1

I have a global prefix command key define like following:

(unless (boundp 'help-document-map)
  (define-prefix-command 'help-document-map))
;; (define-key my-programming-prefix-k (kbd "h") 'help-document-map)
(global-set-key (kbd "C-h d") 'help-document-map)

And then I want to use it in following mode-map defining keys.

(eval-after-load "helm-cscope"
  '(progn
     (define-key helm-cscope-mode-map (kbd "M-t") 'helm-cscope-find-symbol)
     (define-key helm-cscope-mode-map (kbd "M-r") 'helm-cscope-find-global-definition)
     (define-key helm-cscope-mode-map (kbd "M-g M-c") 'helm-cscope-find-called-function)
     (define-key helm-cscope-mode-map (kbd "M-g M-p") 'helm-cscope-find-calling-this-funtcion)
     (define-key helm-cscope-mode-map (kbd "M-s") 'helm-cscope-select)))

So how do I define this keybinding?

  • 2
    It's really hard to know what's being asked here. Would you mind rewording? – shosti Oct 6 '14 at 5:36
1

It sounds like what you want is for C-h d to act as a prefix to a map dependent on the current mode.

There are a couple of solutions to this. One solution I have seen used in a couple of modes is to prefix each of the kbd calls with say help-document-prefix.

(defvar helm-document-prefix "C-h d")
(eval-after-load "helm-cscope"
  '(progn
     (define-key helm-cscope-mode-map 
                 (kbd (concat help-document-prefix " M-t")) 
                 'helm-cscope-find-symbol)))

This approach will enable C-h d M-t when helm-cscope-mode-map is active.

Another approach would be to set these bindings using local-set-key but inside of the mode hook. That would do a better job of respecting the help-document-prefix variable changing, as the binding would update every time the mode was enabled.

I don't know if there is a way to use a prefix map to dispatch to a function, which in turn dispatches to a keymap. It is possible to inherit from another keymap, but I don't know as that would help here.

  • I add a hook like this: (add-hook 'helm-cscope-mode-hook (lambda () (local-set-key (kbd (concat my-prog-help-document-map " M-t")) 'helm-cscope-find-symbol))) . But it report error: wrong type argument: characterp, keymap. – stardiviner Oct 7 '14 at 3:18
  • As you said, I did a search in GitHub code, and try to find some examples with (kbd (concat ...)). Found an example github.com/schnecki/dot-emacs.d/blob/… – stardiviner Oct 7 '14 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.