最近刚刚从 require-package 转到 use-package, 有个问题
(use-package helm
:bind
(("M-x" . helm-M-x)
;; :map helm-M-x-map
;; ("M-x" . helm-keyboard-quit)
)
:init
(setq helm-M-x-fuzzy-match t)
:config
(require 'helm-config)
(helm-mode 1)
;; (define-key "M-x" #'helm-keyboard-quit helm-map) ;;same
(bind-key "M-x" #'helm-keyboard-quit helm-M-x-map)
)
想给helm-M-x-map 加快捷键,
上面这段会报没有找到helm-M-x-map,如何先加载helm-M-x-map呢?
用的是最新的use-package
直接放到config 里不就可以了吗。。没必要一定用 bind 。
我确实是直接放到config里面了啊
;; (define-key "M-x" #'helm-keyboard-quit helm-map) ;;same
(bind-key "M-x" #'helm-keyboard-quit helm-M-x-map)
这两句不是在config里面吗,bind那里被注释掉了
helm-M-x-map 前面要加quote。不然就会被立刻求值。
这样应该就可以了
绝不是这个原因
(define-key "M-x" #'helm-keyboard-quit helm-M-x-map)
(bind-key "M-x" #'helm-keyboard-quit helm-M-x-map)
这两句eval之后都能执行正常,而加了quote之后就报错了
事实上我是参考的use-package官网的例子
(use-package helm
:bind (:map helm-command-map
("C-c h" . helm-execute-persistent-action)))
只不过helm-command-map是已经被加载的。和我的情况不一样。
那么,试试用(with-eval-after-load 'helm-command ... )
这个是肯定可以的,我原来就是用的这个,现在不是换use-package了吗。。想试试它的延迟加载。。
如果这样的话,你需要用(use-package helm-command ...)
。因为helm-M-x
在helm-command.el
里,它不见得会在helm.el
加载的时候马上加载。
1 个赞
helm-M-x-map
是在 helm-command.el
里,并不在 helm.el
里,所以你用 (use-package helm ...)
自然找不到。可以试试
(use-package helm-command
:bind (:map helm-M-x-map ("M-x" . helm-keyboard-quit)))
因为 helm-command.el
是肯定会首先加载 helm.el
的,所以直接用 helm-keyboard-quit
是没问题的。
2 个赞