Add new option to 'register-use-preview'

When set to 'insist', exit minibuffer with same key as
register name, instead of pressing RET.  E.g., pressing
"a" selects register "a", then pressing "a" again exits
the minibuffer.

* lisp/register.el (register-use-preview): New option 'insist'.
(register-read-with-preview-fancy): Handle new option.
* doc/emacs/regs.texi: Document it.
* etc/NEWS: Mention 'insist'.  (Bug#68654)
This commit is contained in:
Thierry Volpiatto 2024-01-08 15:08:01 +01:00 committed by Eli Zaretskii
parent fc70eced27
commit 6b93e16e43
3 changed files with 22 additions and 3 deletions

View file

@ -71,6 +71,11 @@ by @code{insert-register} will only show registers whose values can be
inserted into the buffer, omitting registers which hold window
configurations, positions, and other un-insertable values.
@item insist
This value is like @code{t}, but in addition of pressing @key{RET} to
exit with the choosen value, you can press the same key as the name of
register.
@item nil
This value requests behavior similar to @code{traditional}, but the
preview is shown without delay, and is filtered according to the

View file

@ -639,7 +639,7 @@ This allows to customize different switches for different remote machines.
+++
*** New mode of prompting for register names and showing preview.
The new user option 'register-use-preview' can be customized to the
value t to request a different user interface of prompting for
value t or insist to request a different user interface of prompting for
register names and previewing the registers: Emacs will require
confirmation for overwriting the value of a register, and will show
the preview of registers without delay. You can also customize this

View file

@ -131,7 +131,11 @@ to the value of `register--read-with-preview-function'.")
(defcustom register-use-preview 'traditional
"Whether to show register preview when modifying registers.
When set to `t', show a preview buffer with navigation and highlighting.
When set to `t', show a preview buffer with navigation and
highlighting.
When set to \\='insist behave as with `t' but allow exiting minibuffer
by pressing a second time the selected register, e.g pressing \"a\"
select register \"a\" and pressing again \"a\" exit minibuffer.
When nil, show a preview buffer without navigation and highlighting, and
exit the minibuffer immediately after inserting response in minibuffer.
When set to \\='never, behave as with nil, but with no preview buffer at
@ -141,6 +145,7 @@ according to `register-preview-delay'; this preserves the traditional
behavior of Emacs 29 and before."
:type '(choice
(const :tag "Use preview" t)
(const :tag "Use preview and exit on second hit" insist)
(const :tag "Use quick preview" nil)
(const :tag "Never use preview" never)
(const :tag "Basic preview like Emacs-29" traditional))
@ -541,7 +546,12 @@ or \\='never."
(member new strs))
new old))
(delete-minibuffer-contents)
(insert input)))
(insert input)
;; Exit minibuffer on second hit
;; when *-use-preview == insist.
(when (and (string= new old)
(eq register-use-preview 'insist))
(setq noconfirm t))))
(when (and smatch (not (string= input ""))
(not (member input strs)))
(setq input "")
@ -551,6 +561,10 @@ or \\='never."
(setq pat input))))
(if (setq win (get-buffer-window buffer))
(with-selected-window win
(when noconfirm
;; Happen only when
;; *-use-preview == insist.
(exit-minibuffer))
(let ((ov (make-overlay
(point-min) (point-min)))
;; Allow upper-case and lower-case letters