1
(where-is 'zap-to-char) ;; Prints ("zap-to-char is on M-znil")   
(where-is-internal 'zap-to-char) ;; [134217850] ;;; this number seems like junk to me!

I would like a function that returns M-z I imagine it would be something like (keypress-of 'zap-to-char).

2

Convert between readable key description (string, such as "M-z") and key sequence (vector or string, such as [134217850], [?\M-z], "\M-z", these three are the identical as key sequence):

(key-description [134217850])
    ⇒ "M-z"

(kbd "M-z")
    ⇒ [134217850]

If you read the source code of where-is, you should be able to think of something like following

(mapconcat #'key-description (where-is-internal 'zap-to-char) ", ")
    ⇒ "M-z"
0

I want to do this often, so this might be too inefficient a way:

(defun get-keys (function)
  (with-current-buffer (get-buffer-create "temp-buffer")
    (erase-buffer)
    (where-is function t)
    (let* ((regex (pcre-to-elisp/cached "(,\\s|\\s\\()"))
           (results (s-split regex (buffer-string)))
           (take-until (- (length results) 1)))
      (subseq results 0 take-until)))) 

(get-keys 'ido-kill-buffer) ;; ("M-m b k" "C-x k")  
  • Other variants will be accepted. Perhaps one that is a variation on where-is in help.el? – 24HrRevengeTherapist Oct 25 '15 at 18:20

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.