From: Thierry Volpiatto Date: Mon, 8 Jan 2024 14:08:01 +0000 (+0100) Subject: Add new option to 'register-use-preview' X-Git-Tag: archive/raspbian/1%30.1+1-3+rpi1^2~2^2~20^2~2797 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6b93e16e436735003d49a5a2ab451394937ee76c;p=emacs.git 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) --- diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi index fdcddbbc739..c30bcc37999 100644 --- a/doc/emacs/regs.texi +++ b/doc/emacs/regs.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index 7e30cda7226..e854873b8d0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 diff --git a/lisp/register.el b/lisp/register.el index f5b0365dec2..73d1b24b231 100644 --- a/lisp/register.el +++ b/lisp/register.el @@ -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