Properly keep cursor out of minibuffer prompt

The prompt in the minibuffer is read-only. You are able to move the
cursor into it before this fix.

This also more effectively silences echo-area output when deleting text
in the minibuffer. No more "Text is read-only" blocking what you're
typing.
This commit is contained in:
Henrik Lissner 2019-03-01 15:37:42 -05:00
parent fb57f367e7
commit 21e01189b9
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 14 additions and 14 deletions

View file

@ -526,18 +526,20 @@ it to fix all that visual noise."
frame)))
(add-hook 'after-make-frame-functions #'doom|disable-whitespace-mode-in-childframes)
(defun doom*silence-motion-errors (orig-fn &rest args)
"Prevent disruptive motion errors taking over the minibuffer while we're in
it."
(if (not (minibufferp))
(apply orig-fn args)
(ignore-errors (apply orig-fn args))
(when (<= (point) (minibuffer-prompt-end))
(goto-char (minibuffer-prompt-end)))))
(advice-add #'left-char :around #'doom*silence-motion-errors)
(advice-add #'right-char :around #'doom*silence-motion-errors)
(advice-add #'delete-backward-char :around #'doom*silence-motion-errors)
(advice-add #'backward-kill-sentence :around #'doom*silence-motion-errors)
;; Don't allow cursor to enter the prompt
(setq minibuffer-prompt-properties '(read-only t intangible t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
;; Don't display messages in the minibuffer when using the minibuffer
(defmacro doom-silence-motion-key (command key)
(let ((key-command (intern (format "doom/silent-%s" command))))
`(progn
(defun ,key-command ()
(interactive)
(ignore-errors (call-interactively ',command)))
(define-key minibuffer-local-map (kbd ,key) #',key-command))))
(doom-silence-motion-key backward-delete-char "<backspace>")
(doom-silence-motion-key delete-char "<delete>")
;; Switch to `doom-fallback-buffer' if on last real buffer
(advice-add #'kill-this-buffer :around #'doom*switch-to-fallback-buffer-maybe)

View file

@ -230,8 +230,6 @@ and `doom-exit-window-hook'."
inhibit-default-init t
initial-major-mode 'fundamental-mode
initial-scratch-message nil
;; keep the point out of the minibuffer
minibuffer-prompt-properties '(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt)
;; History & backup settings (save nothing, that's what git is for)
auto-save-default nil
create-lockfiles nil