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 key binding?

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

1 Answer 1

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.

2
  • 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. Oct 7, 2014 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/… Oct 7, 2014 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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