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" ""))
         ;; 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, don't use `posn-set-point'.
         (defn (if buffer
                   (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 defn)))
     defn event mouse-msg)))