Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:bind for derived keymaps? (java-mode-map for example) #1068

Open
skyler544 opened this issue Jan 19, 2024 · 2 comments
Open

:bind for derived keymaps? (java-mode-map for example) #1068

skyler544 opened this issue Jan 19, 2024 · 2 comments

Comments

@skyler544
Copy link

I may just be doing it wrong, but is there no way of using :bind for a keymap like java-mode-map?

(use-package cc-mode
  :bind (:map java-mode-map ;; :package cc-mode
         ("[tab]" . indent-for-tab-command))
  :config
  ;; HACK `:bind' won't work for this for some reason
  ;; (with-eval-after-load 'cc-mode
  ;;   (bind-key [tab] #'indent-for-tab-command java-mode-map))
)

as it stands here, this declaration does not throw any errors, but it also doesn't set the keybinding in the java-mode-map (M-x java-mode C-h k TAB -> c-indent-line-or-region).

I've tried various combinations of use-package emacs and use-package cc-mode with and without the :package cc-mode part enabled and if you use use-package emacs without :package ... it throws an error on startup: Symbol's value as variable is void: java-mode-map

The part marked with HACK does correctly set the keybinding, which seems odd to me because my understanding of the :bind keyword is that it would get expanded to that anyways. Is this an actual issue, or am I just doing it wrong?

@erikLundstedt
Copy link

what do you get if you run it thru macroexpand?
I'm not the best at emacs-lisp by any means, but seing as use-package is a macro, it should help quite a lot

as a sidenote, the main developer should add something like "if possible, include the output/result of running macroexpand on the use-package call in question" to the issues how-to

hope this helps

@erikLundstedt
Copy link

here is what I got, cleaned up slightly(use-package creates a variable for use in error-logging it seems, i deleted the def an replaced it with the generic "use-package--warning")u

;;; without the hack
(progn
  (use-package-ensure-elpa 'cc-mode
						   '(t)
						   'nil)
  (condition-case-unless-debug err
      (progn
		(unless
			(fboundp 'indent-for-tab-command)
		  (autoload #'indent-for-tab-command "cc-mode" nil t))
		(bind-keys :package cc-mode :map java-mode-map
				   ("[tab]" . indent-for-tab-command)))
    (error (funcall use-package--warning :catch err))))

;;; only the hack

(progn
  (use-package-ensure-elpa 'cc-mode
						   '(t)
						   'nil)
  (condition-case-unless-debug err
      (if (not
		   (require 'cc-mode nil t))
		  (display-warning 'use-package
						   (format "Cannot load %s" 'cc-mode)
						   :error)
		(condition-case-unless-debug err
			(progn
			  (with-eval-after-load 'cc-mode
				(bind-key
				 [tab]
				 #'indent-for-tab-command java-mode-map))
			  t)
		  (error (funcall use-package--warning :config err))))
    (error (funcall use-package--warning :catch err))))

however, my setup is most definitely different from yours, so the output you get might be different

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants