- (save-excursion
- (let ((modifiers (event-modifiers (aref key 0)))
- window position)
- ;; For a mouse button event, go to the button it applies to
- ;; to get the right key bindings. And go to the right place
- ;; in case the keymap depends on where you clicked.
- (if (or (memq 'click modifiers) (memq 'down modifiers)
- (memq 'drag modifiers))
- (setq window (posn-window (event-start (aref key 0)))
- position (posn-point (event-start (aref key 0)))))
- (when (windowp window)
- (set-buffer (window-buffer window))
- (goto-char position))
- (let ((defn (or (string-key-binding key) (key-binding key t))))
- ;; Handle the case where we faked an entry in "Select and Paste" menu.
- (if (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))
- (if (or (null defn) (integerp defn) (equal defn 'undefined))
- (message "%s is undefined" (help-key-description key untranslated))
- (help-setup-xref (list #'describe-function defn) (interactive-p))
- ;; Don't bother user with strings from (e.g.) the select-paste menu.
- (if (stringp (aref key (1- (length key))))
- (aset key (1- (length key)) "(any string)"))
- (if (and untranslated
- (stringp (aref untranslated (1- (length untranslated)))))
- (aset untranslated (1- (length untranslated))
- "(any string)"))
- (with-output-to-temp-buffer (help-buffer)
- (princ (help-key-description key untranslated))
- (if (windowp window)
- (princ " at that spot"))
- (princ " runs the command ")
- (prin1 defn)
- (princ "\n which is ")
- (describe-function-1 defn)
- (setq foo up-event)
- (when up-event
- (let ((type (event-basic-type up-event))
- (hdr "\n\n-------------- up event ---------------\n\n")
- defn sequence
- mouse-1-tricky mouse-1-remapped)
- (setq sequence (vector up-event))
- (when (and (eq type 'mouse-1)
- (windowp window)
+ (let* ((event (aref key (if (and (symbolp (aref key 0))
+ (> (length key) 1)
+ (consp (aref key 1)))
+ 1
+ 0)))
+ (modifiers (event-modifiers event))
+ (mouse-msg (if (or (memq 'click modifiers) (memq 'down modifiers)
+ (memq 'drag modifiers)) " at that spot" ""))
+ (defn (key-binding key t))
+ defn-up defn-up-tricky ev-type
+ mouse-1-remapped mouse-1-tricky)
+
+ ;; 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))
+ (if (or (null defn) (integerp defn) (equal defn 'undefined))
+ (message "%s%s is undefined"
+ (help-key-description key untranslated) mouse-msg)
+ (help-setup-xref (list #'describe-function defn) (interactive-p))
+ ;; 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)"))
+ ;; Need to do this before erasing *Help* buffer in case event
+ ;; is a mouse click in an existing *Help* buffer.
+ (when up-event
+ (setq ev-type (event-basic-type up-event))
+ (let ((sequence (vector up-event)))
+ (when (and (eq ev-type 'mouse-1)
+ mouse-1-click-follows-link
+ (not (eq mouse-1-click-follows-link 'double))
+ (setq mouse-1-remapped
+ (mouse-on-link-p (event-start up-event))))
+ (setq mouse-1-tricky (and (integerp mouse-1-click-follows-link)
+ (> mouse-1-click-follows-link 0)))
+ (cond ((stringp mouse-1-remapped)
+ (setq sequence mouse-1-remapped))
+ ((vectorp mouse-1-remapped)
+ (setcar up-event (elt mouse-1-remapped 0)))
+ (t (setcar up-event 'mouse-2))))
+ (setq defn-up (key-binding sequence nil nil (event-start up-event)))
+ (when mouse-1-tricky
+ (setq sequence (vector up-event))
+ (aset sequence 0 'mouse-1)
+ (setq defn-up-tricky (key-binding sequence nil nil (event-start up-event))))))
+ (with-output-to-temp-buffer (help-buffer)
+ (princ (help-key-description key untranslated))
+ (princ (format "\
+%s runs the command %S
+ which is "
+ mouse-msg defn))
+ (describe-function-1 defn)
+ (when up-event
+ (unless (or (null defn-up)
+ (integerp defn-up)
+ (equal defn-up 'undefined))
+ (princ (format "
+
+----------------- up-event %s----------------
+
+<%S>%s%s runs the command %S
+ which is "
+ (if mouse-1-tricky "(short click) " "")
+ ev-type mouse-msg
+ (if mouse-1-remapped
+ " is remapped to <mouse-2>\nwhich" "")
+ defn-up))
+ (describe-function-1 defn-up))
+ (unless (or (null defn-up-tricky)
+ (integerp defn-up-tricky)
+ (eq defn-up-tricky 'undefined))
+ (princ (format "
+
+----------------- up-event (long click) ----------------
+
+Pressing <%S>%s for longer than %d milli-seconds
+runs the command %S
+ which is "
+ ev-type mouse-msg