Function: help--analyze-key
help--analyze-key is a byte-compiled function defined in help.el.gz.
Signature
(help--analyze-key KEY UNTRANSLATED &optional BUFFER)
Documentation
Get information about KEY its corresponding UNTRANSLATED events.
Returns a list of the form (BRIEF-DESC DEFN EVENT MOUSE-MSG). When BUFFER is nil, it defaults to the buffer displayed in the selected window.
Source Code
;; Defined in /usr/src/emacs/lisp/help.el.gz
(defun help--analyze-key (key untranslated &optional buffer)
"Get information about KEY its corresponding UNTRANSLATED events.
Returns a list of the form (BRIEF-DESC DEFN EVENT MOUSE-MSG).
When BUFFER is nil, it defaults to the buffer displayed
in the selected window."
(if (numberp untranslated)
(error "Missing `untranslated'!"))
(let* ((event (when (> (length key) 0)
(aref key (if (and (symbolp (aref key 0))
(> (length key) 1)
(consp (aref key 1)))
;; Look at the second event when the first
;; is a pseudo-event like `mode-line' or
;; `left-fringe'.
1
0))))
(modifiers (event-modifiers event))
(mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
(memq 'drag modifiers))
" at that spot" ""))
(click-pos (event-end event))
;; Use `posn-set-point' to handle the case when a menu item
;; is selected from the context menu that should describe KEY
;; at the position of mouse click that opened the context menu.
;; When no mouse was involved, or the event doesn't provide a
;; valid position, don't use `posn-set-point'.
(defn (if (or buffer (not (consp click-pos)))
(key-binding key t)
(save-excursion (posn-set-point (event-end event))
(key-binding key t)))))
;; Handle the case where we faked an entry in "Select and Paste" menu.
(when (and (eq defn nil)
(stringp (aref key (1- (length key))))
(eq (key-binding (substring key 0 -1)) 'yank-menu))
(setq defn 'menu-bar-select-yank))
;; Don't bother user with strings from (e.g.) the select-paste menu.
(when (stringp (aref key (1- (length key))))
(aset key (1- (length key)) "(any string)"))
(when (and untranslated
(stringp (aref untranslated (1- (length untranslated)))))
(aset untranslated (1- (length untranslated)) "(any string)"))
(list
;; Now describe the key, perhaps as changed.
(let ((key-desc (help-key-description key untranslated)))
(if (help--binding-undefined-p defn)
(format "%s%s is undefined" key-desc mouse-msg)
(format "%s%s runs the command %s" key-desc mouse-msg
(if (symbolp defn) (prin1-to-string defn)
(help-fns-function-name defn)))))
defn event mouse-msg)))