Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update handling of minibuffer message overlays #165

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 5 additions & 38 deletions selectrum.el
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,6 @@ PRED defaults to `minibuffer-completion-predicate'."
(overlay-put selectrum--candidates-overlay 'after-string text)))
(setq selectrum--end-of-input-marker (set-marker (make-marker) bound))
(set-marker-insertion-type selectrum--end-of-input-marker t)
(selectrum--fix-set-minibuffer-message)
(when keep-mark-active
(setq deactivate-mark nil))
(setq-local selectrum--init-p nil)))
Expand Down Expand Up @@ -1755,29 +1754,6 @@ shadows correctly."
(setq current-prefix-arg selectrum--last-prefix-arg)
(call-interactively selectrum--last-command)))

;;;###autoload
(defun selectrum--fix-set-minibuffer-message (&rest _)
"Move the minibuffer message overlay to the right place.
This advice fixes the overlay placed by `set-minibuffer-message',
which is different from the one placed by `minibuffer-message'.

By default the overlay is placed at the end, but in the case of
Selectrum this means after all the candidates. We want to move it
instead to just after the user input.

To test that this advice is working correctly, type \\[find-file]
and enter \"/sudo::\", then authenticate. The overlay indicating
that authentication was successful should appear right after the
user input area, not at the end of the candidate list.

This is an `:after' advice for `set-minibuffer-message'."
(selectrum--when-compile (boundp 'minibuffer-message-overlay)
(when (and (bound-and-true-p selectrum-active-p)
(overlayp minibuffer-message-overlay))
(move-overlay minibuffer-message-overlay
selectrum--end-of-input-marker
selectrum--end-of-input-marker))))

;;;###autoload
(defun selectrum--fix-minibuffer-message (func &rest args)
"Move the minibuffer message overlay to the right place.
Expand All @@ -1797,12 +1773,11 @@ not at the end of the candidate list.
This is an `:around' advice for `minibuffer-message'. FUNC and
ARGS are standard as in all `:around' advice."
(if (bound-and-true-p selectrum-active-p)
(cl-letf* ((orig-make-overlay (symbol-function #'make-overlay))
((symbol-function #'make-overlay)
(lambda (_beg _end &rest args)
(apply orig-make-overlay
selectrum--end-of-input-marker
selectrum--end-of-input-marker
(cl-letf* ((orig-put-text-property (symbol-function #'put-text-property))
((symbol-function #'put-text-property)
(lambda (beg end key val &rest args)
(apply orig-put-text-property
beg end key (if (eq key 'cursor) 1 val)
args))))
(apply func args))
(apply func args)))
Expand Down Expand Up @@ -1851,10 +1826,6 @@ ARGS are standard as in all `:around' advice."
#'selectrum-read-library-name)
(advice-add #'minibuffer-message :around
#'selectrum--fix-minibuffer-message)
;; No sharp quote because `set-minibuffer-message' is not
;; defined in older Emacs versions.
(advice-add 'set-minibuffer-message :after
#'selectrum--fix-set-minibuffer-message)
(define-key minibuffer-local-map
[remap previous-matching-history-element]
'selectrum-select-from-history))
Expand Down Expand Up @@ -1883,10 +1854,6 @@ ARGS are standard as in all `:around' advice."
;; older Emacs versions.
(advice-remove 'read-library-name #'selectrum-read-library-name)
(advice-remove #'minibuffer-message #'selectrum--fix-minibuffer-message)
;; No sharp quote because `set-minibuffer-message' is not
;; defined in older Emacs versions.
(advice-remove 'set-minibuffer-message
#'selectrum--fix-set-minibuffer-message)
(when (eq (lookup-key minibuffer-local-map
[remap previous-matching-history-element])
#'selectrum-select-from-history)
Expand Down