(let* ((function (and (stringp command-name) (intern-soft command-name)))
(binding (and suggest-key-bindings
(not executing-kbd-macro)
- (where-is-internal function overriding-local-map t))))
+ (where-is-internal function overriding-local-map t)))
+ (delay-before-suggest 0))
(unless (commandp function)
(error "`%s' is not a valid command name" command-name))
;; Some features, such as novice.el, rely on this-command-keys
(let ((prefix-arg prefixarg))
(command-execute function 'record))
;; If enabled, show which key runs this command.
- ;; But first wait, and skip the message if there is input.
- (let* ((waited
- ;; If this command displayed something in the echo area;
- ;; wait a few seconds, then display our suggestion message.
- ;; FIXME: Wait *after* running post-command-hook!
- ;; FIXME: If execute-extended-command--shorter were
- ;; faster, we could compute the result here first too.
- (when (and suggest-key-bindings
- (or binding
- (and extended-command-suggest-shorter typed)))
- (sit-for (cond
- ((zerop (length (current-message))) 0)
- ((numberp suggest-key-bindings) suggest-key-bindings)
- (t 2))))))
- (when (and waited (not (consp unread-command-events)))
- (unless (or (not extended-command-suggest-shorter)
- binding executing-kbd-macro (not (symbolp function))
- (<= (length (symbol-name function)) 2))
- ;; There's no binding for CMD. Let's try and find the shortest
- ;; string to use in M-x.
- ;; FIXME: Can be slow. Cache it maybe?
- (while-no-input
- (setq binding (execute-extended-command--shorter
- (symbol-name function) typed))))
- (when binding
- ;; This is normally not necessary -- the timer should run
- ;; immediately, but be defensive and ensure that we never
- ;; have two of these timers in flight.
- (when execute-extended-command--binding-timer
- (cancel-timer execute-extended-command--binding-timer))
- (setq execute-extended-command--binding-timer
- (run-at-time
- 0 nil
- (lambda ()
- (with-temp-message
- (format-message "You can run the command `%s' with %s"
- function
- (if (stringp binding)
- (concat "M-x " binding " RET")
- (key-description binding)))
- (sit-for (if (numberp suggest-key-bindings)
- suggest-key-bindings
- 2)))))))))))
+
+ ;; If this command displayed something in the echo area;
+ ;; then postpone display our suggestion message a bit.
+ ;; FIXME: If execute-extended-command--shorter were
+ ;; faster, we could compute the result here first too.
+ (when (and suggest-key-bindings
+ (or binding
+ (and extended-command-suggest-shorter typed)))
+ (setq delay-before-suggest
+ (cond
+ ((zerop (length (current-message))) 0)
+ ((numberp suggest-key-bindings) suggest-key-bindings)
+ (t 2))))
+ (unless (or (not extended-command-suggest-shorter)
+ binding executing-kbd-macro (not (symbolp function))
+ (<= (length (symbol-name function)) 2))
+ ;; There's no binding for CMD. Let's try and find the shortest
+ ;; string to use in M-x.
+ ;; FIXME: Can be slow. Cache it maybe?
+ (while-no-input
+ (setq binding (execute-extended-command--shorter
+ (symbol-name function) typed))))
+ ;; Ensure that we never have two of these timers in flight.
+ (when execute-extended-command--binding-timer
+ (cancel-timer execute-extended-command--binding-timer))
+ (when binding
+ (setq execute-extended-command--binding-timer
+ (run-at-time
+ delay-before-suggest nil
+ (lambda ()
+ ;; If the user has typed any other commands in the
+ ;; meantime, then don't display anything.
+ (when (eq function real-last-command)
+ (with-temp-message
+ (format-message "You can run the command `%s' with %s"
+ function
+ (if (stringp binding)
+ (concat "M-x " binding " RET")
+ (key-description binding)))
+ (sit-for (if (numberp suggest-key-bindings)
+ suggest-key-bindings
+ 2))))))))))
(defun execute-extended-command-for-buffer (prefixarg &optional
command-name typed)