(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))
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"))