I have two overlays that are initially in the same position.
(defvar-local minibuffer-overlay nil)
(defvar-local minibuffer-overlay2 nil)
(defun minibuffer-advice (fn &rest args)
(minibuffer-with-setup-hook #'minibuffer-setup (apply fn args)))
(defun minibuffer-setup ()
(setq minibuffer-overlay (make-overlay (point-min) (point-min) nil t nil))
(setq minibuffer-overlay2 (make-overlay (point-min) (point-min) nil t t))
(add-hook 'post-command-hook #'minibuffer-exhibit nil 'local))
(defun minibuffer-exhibit ()
(move-overlay minibuffer-overlay (minibuffer-prompt-end) (minibuffer-prompt-end))
(overlay-put minibuffer-overlay 'before-string "!")
(move-overlay minibuffer-overlay2 (point-max) (point-max))
(overlay-put minibuffer-overlay2 'after-string "?"))
(advice-add #'completing-read-default :around #'minibuffer-advice)
M-x looks like M-x ?!|
where |
is the cursor.
If I type foo
then it becomes M-x !foo?|
.
How do I make M-x initially look like M-x !?|
instead?
EDIT:
Example for a *scratch* buffer since it may be confusing having it in the minibuffer:
(let ((overlay1 (make-overlay (point-min) (point-min)))
(overlay2 (make-overlay (point-min) (point-min))))
(move-overlay overlay1 (point-min) (point-min))
(overlay-put overlay1 'before-string "!")
(move-overlay overlay2 (point-min) (point-min))
(overlay-put overlay2 'after-string "?"))
The beginning of the buffer will look like ?!
. Why does the second overlay come first and how can I change that?