jwiegley/use-package

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

skyler544 opened this issue · 2 comments

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?

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

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