From: Eshel Yaron Date: Sat, 29 Mar 2025 20:42:15 +0000 (+0100) Subject: * lisp/help.el (where-is): Remove prefix arg, clean up. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7cd4a0eec7d373a0e15c771084615d8338980437;p=emacs.git * lisp/help.el (where-is): Remove prefix arg, clean up. --- diff --git a/lisp/help.el b/lisp/help.el index 13f0bda0fb8..34c77c6a237 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -954,33 +954,30 @@ or a buffer name." (put-text-property (1+ (match-beginning 0)) (1- (match-end 0)) 'invisible t))))))))) -(defun where-is (definition &optional insert) - "Print message listing key sequences that invoke the command DEFINITION. -Argument is a command definition, usually a symbol with a function definition. -If INSERT (the prefix arg) is non-nil, insert the message in the buffer." +(defun where-is (command &optional _) + "Report about key sequences that invoke COMMAND. + +(fn COMMAND)" (interactive - (let ((fn (function-called-at-point)) - val) - (setq val (completing-read (format-prompt "Where is command" fn) - obarray #'commandp t nil nil - (and fn (symbol-name fn)))) - (list (unless (equal val "") (intern val)) - current-prefix-arg))) - (unless definition (error "No command")) - (let ((func (indirect-function definition)) - (defs nil) - (standard-output (if insert (current-buffer) standard-output))) + (let* ((fn (symbol-at-point)) + (def (when (commandp fn) (symbol-name fn))) + (val (completing-read (format-prompt "Where is command" def) + obarray #'commandp t nil + 'extended-command-history def))) + (when (string-empty-p val) (user-error "You didn't specify a command")) + (list (intern val) current-prefix-arg))) + (let ((func (indirect-function command)) defs) ;; In DEFS, find all symbols that are aliases for DEFINITION. (mapatoms (lambda (symbol) (and (fboundp symbol) - (not (eq symbol definition)) + (not (eq symbol command)) (eq func (condition-case () (indirect-function symbol) (error symbol))) (push symbol defs)))) ;; Look at all the symbols--first DEFINITION, ;; then its aliases. - (dolist (symbol (cons definition defs)) + (dolist (symbol (cons command defs)) (let* ((remapped (command-remapping symbol)) (keys (where-is-internal symbol overriding-local-map nil nil remapped)) @@ -988,37 +985,29 @@ If INSERT (the prefix arg) is non-nil, insert the message in the buffer." keys ", ")) string) (setq string - (if insert - (if (> (length keys) 0) - (if remapped - (format "%s, remapped to %s (%s)" - symbol remapped keys) - (format "%s (%s)" symbol keys)) - (format "M-x %s RET" symbol)) - (if (> (length keys) 0) - (if remapped - (if (eq symbol (symbol-function definition)) - (format - "%s, which is remapped to %s, which is on %s" - symbol remapped keys) - (format "%s is remapped to %s, which is on %s" - symbol remapped keys)) - (if (eq symbol (symbol-function definition)) - (format "%s, which is on %s" symbol keys) - (format "%s is on %s" symbol keys))) - ;; If this is the command the user asked about, - ;; and it is not on any key, say so. - ;; For other symbols, its aliases, say nothing - ;; about them unless they are on keys. - (if (eq symbol definition) - (format "%s is not on any key" symbol))))) + (if (> (length keys) 0) + (if remapped + (if (eq symbol (symbol-function command)) + (format + "%s, which is remapped to %s, which is on %s" + symbol remapped keys) + (format "%s is remapped to %s, which is on %s" + symbol remapped keys)) + (if (eq symbol (symbol-function command)) + (format "%s, which is on %s" symbol keys) + (format "%s is on %s" symbol keys))) + ;; If this is the command the user asked about, + ;; and it is not on any key, say so. + ;; For other symbols, its aliases, say nothing + ;; about them unless they are on keys. + (if (eq symbol command) + (format "%s is not on any key" symbol)))) (when string - (unless (eq symbol definition) - (if (eq definition (symbol-function symbol)) + (unless (eq symbol command) + (if (eq command (symbol-function symbol)) (princ ";\n its alias ") (princ ";\n it's an alias for "))) - (princ string))))) - nil) + (princ string)))))) (put 'where-is 'minibuffer-action (cons (compf where-is intern) "show keys"))