"Insert the character you type in the minibuffer and exit.
Discard all previous input before inserting and exiting the minibuffer."
(interactive)
- (delete-minibuffer-contents)
- (insert last-command-event)
- (exit-minibuffer))
+ (when (minibufferp)
+ (delete-minibuffer-contents)
+ (insert last-command-event)
+ (exit-minibuffer)))
(defun read-char-from-minibuffer-insert-other ()
"Handle inserting of a character other than allowed.
Display an error on trying to insert a disallowed character.
Also discard all previous input in the minibuffer."
(interactive)
- (delete-minibuffer-contents)
- (ding)
- (discard-input)
- (minibuffer-message "Wrong answer")
- (sit-for 2))
+ (when (minibufferp)
+ (delete-minibuffer-contents)
+ (ding)
+ (discard-input)
+ (minibuffer-message "Wrong answer")
+ (sit-for 2)))
(defvar empty-history)
map)
read-char-from-minibuffer-map-hash))
read-char-from-minibuffer-map))
+ ;; Protect this-command when called from pre-command-hook (bug#45029)
+ (this-command this-command)
(result
(read-from-minibuffer prompt nil map nil
(or history 'empty-history)))
"Insert the answer \"y\" and exit the minibuffer of `y-or-n-p'.
Discard all previous input before inserting and exiting the minibuffer."
(interactive)
- (delete-minibuffer-contents)
- (insert "y")
- (exit-minibuffer))
+ (when (minibufferp)
+ (delete-minibuffer-contents)
+ (insert "y")
+ (exit-minibuffer)))
(defun y-or-n-p-insert-n ()
"Insert the answer \"n\" and exit the minibuffer of `y-or-n-p'.
Discard all previous input before inserting and exiting the minibuffer."
(interactive)
- (delete-minibuffer-contents)
- (insert "n")
- (exit-minibuffer))
+ (when (minibufferp)
+ (delete-minibuffer-contents)
+ (insert "n")
+ (exit-minibuffer)))
(defun y-or-n-p-insert-other ()
"Handle inserting of other answers in the minibuffer of `y-or-n-p'.
Display an error on trying to insert a disallowed character.
Also discard all previous input in the minibuffer."
(interactive)
- (delete-minibuffer-contents)
- (ding)
- (discard-input)
- (minibuffer-message "Please answer y or n")
- (sit-for 2))
+ (when (minibufferp)
+ (delete-minibuffer-contents)
+ (ding)
+ (discard-input)
+ (minibuffer-message "Please answer y or n")
+ (sit-for 2)))
(defvar empty-history)
(setq prompt (funcall padded prompt))
(let* ((empty-history '())
(enable-recursive-minibuffers t)
+ ;; Protect this-command when called from pre-command-hook (bug#45029)
+ (this-command this-command)
(str (read-from-minibuffer
prompt nil
(make-composed-keymap y-or-n-p-map query-replace-map)