From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thierry Volpiatto <thievol@posteo.net> Newsgroups: gmane.emacs.bugs Subject: bug#66394: 29.1; Make register-read-with-preview more useful Date: Mon, 11 Dec 2023 09:30:50 +0000 Message-ID: <87a5qhxf05.fsf@posteo.net> References: <87il7ib6cu.fsf@posteo.net> <87ttqgpjiz.fsf@posteo.net> <87wmvbibpr.fsf@web.de> <877cnb2n63.fsf@posteo.net> <8734xyc8z0.fsf@web.de> <87zg05rewi.fsf@posteo.net> <87ttqcg8gw.fsf@web.de> <87h6mcr8ol.fsf@posteo.net> <87r0l73029.fsf@web.de> <877cmdx8ud.fsf@posteo.net> <jwvjzqcxrnq.fsf-monnier+emacs@gnu.org> <87sf50s1gh.fsf@posteo.net> <83o7ficesp.fsf@gnu.org> <878r6leh9d.fsf@posteo.net> <83il5pbnmh.fsf@gnu.org> <87zfz1cz7s.fsf@posteo.net> <83bkbc7j1o.fsf@gnu.org> <8734wov2wv.fsf@posteo.net> <83v89j6arv.fsf@gnu.org> <87cyvpf8y6.fsf@posteo.net> <83plzp82mb.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26199"; mail-complaints-to="usenet@ciao.gmane.io" Cc: michael_heerdegen@web.de, 66394@debbugs.gnu.org, monnier@iro.umontreal.ca, stefankangas@gmail.com To: Eli Zaretskii <eliz@gnu.org> Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 11 10:32:18 2023 Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org> Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>) id 1rCce8-0006Zg-8R for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Dec 2023 10:32:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <bug-gnu-emacs-bounces@gnu.org>) id 1rCcdj-0004ZM-A3; Mon, 11 Dec 2023 04:31:51 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rCcdh-0004Z9-Cj for bug-gnu-emacs@gnu.org; Mon, 11 Dec 2023 04:31:49 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rCcdg-0007zw-2J for bug-gnu-emacs@gnu.org; Mon, 11 Dec 2023 04:31:48 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rCcdu-0001Z4-GI for bug-gnu-emacs@gnu.org; Mon, 11 Dec 2023 04:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Thierry Volpiatto <thievol@posteo.net> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Dec 2023 09:32:02 +0000 Resent-Message-ID: <handler.66394.B66394.17022870875970@debbugs.gnu.org> Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66394 X-GNU-PR-Package: emacs Original-Received: via spool by 66394-submit@debbugs.gnu.org id=B66394.17022870875970 (code B ref 66394); Mon, 11 Dec 2023 09:32:02 +0000 Original-Received: (at 66394) by debbugs.gnu.org; 11 Dec 2023 09:31:27 +0000 Original-Received: from localhost ([127.0.0.1]:52580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1rCcdK-0001YE-7k for submit@debbugs.gnu.org; Mon, 11 Dec 2023 04:31:27 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:53503) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <thievol@posteo.net>) id 1rCcdC-0001Xm-2J for 66394@debbugs.gnu.org; Mon, 11 Dec 2023 04:31:24 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 51EC4240027 for <66394@debbugs.gnu.org>; Mon, 11 Dec 2023 10:30:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1702287057; bh=wZ2aIFhCSZ7LZVpVpMkxnDOLyHIhQ6cS/PKVQDmFhic=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Autocrypt:OpenPGP: From; b=iO7UZemGCtzrLbLYEW3L6c1JaiUO1SfTVaVKHZI903nLhyqiIck5FdTZysp7guPux p1HJlVeP8fZ2XWz/K+i2I0tzMxWUFAFDmdvTy9O3THRnnsbvS7VfEHeIaAJtOrLv2C TgOOPsVBmSohrTS18jADdMeK/eoKNb5K3kve/n3CIj1n5s0WrUcrOf0oqj+arOIy2x IfhHIV5DVog6cWnVp5vM5FNg5vYSG7FmEh/wTqnNUTe1DPWzJELYfRnRkPuWXST0hg VVOQ+XWvgbjUWqGO9RY4SKcG19UBpHmNI2q1AwdP77BA7jFpZSVopcAKO202p3otdZ oY6cmIwaTYmiQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Spc1V2cfNz6tvr; Mon, 11 Dec 2023 10:30:53 +0100 (CET) In-Reply-To: <83plzp82mb.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 02 Dec 2023 09:50:20 +0200 (1 week, 2 days, 1 hour ago)") Autocrypt: addr=thievol@posteo.net; prefer-encrypt=mutual; keydata=xsDNBF8ylcIBDADG+hy+zR6L4/vbdDDZuSaMmSrU3A5QZJpeBCvxTr7MpzzruZbhLPW1K3R6N2MA edi8Y+C8o27FVRIjpdbaKMGu9je7JV/TbUQYo3SOwCK1vM4LUn4V6ZLzSYkuiEt4eyMoiDdyvN0p kcK6P9x9DCetcEVszXzQg+yzCVrQ2hXWDXWT4M18EC3wtO7RHPouMqGiwBFhBAYErCqFWFxQHkfb tG/4yGyJ58rglb65O3qijjMWvYwcWZun9/7qm8Z4/4mHopmo2zgU+OrptnLSZfkZGz3Y7Uf452xQ GVq0Fv75NPvQru7y+DYVhuVXXyAmGxt+vf4rIiixMBbhKEPjcxEPAa2LTzex2IsTZR+QVG9uDnqC WcgaOEQ58fzXNvNhtwwF/Rgio2XWAJVdmFWS59/k9W58CIUSNKBMZh2XeGdEmtHvDtCxW3z6FJha 36RzOM3fMNNiAGdFZJA84gcdloJR+sHCDTTPT3784fjr+V8An7sI581NGFzkRQqPvEQCZbUAEQEA Ac0SdGhpZXZvbEBwb3N0ZW8ubmV0wsEOBBMBCgA4AhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA FiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmL3HCoACgkQDsVtFB0W75OVEAv/f6XxmtIFz08fUb8h Bp/zJP6IC4/rhhh+0GMRIRzLN8DK0jV8JCzYdFHiRJOy2lNIOpmrrCmjRRxferc2G42+ePFIsslx hU46VSz1Z83NwIG3mpdYNV5WUTUdgzxExHTNTFCd7NKv0nlHKQaA OpenPGP: url=https://posteo.de/keys/thievol@posteo.net.asc; preference=encrypt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe> List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs> List-Post: <mailto:bug-gnu-emacs@gnu.org> List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe> Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275972 Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/275972> --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hello Eli,=20 here the last patch that provide Emacs-29 previous behavior as asked on ema= cs-dev, I made it the default for now. The only customization one have to do to make a change is through register-use-preview which have now three options: =2D basic (default - same as Emacs-29- ) =2D nil (simple preview with filtering, default and no confirm) =2D never (same as nil but without any preview) =2D t (the improved version with navigation etc...) I don't know if you want to restore previous behavior (emacs-29), if so thi= s patch will apply against the previous one. (0001-Don-t-confirm-with-RET-even-when-overwriting-in-regi.patch). Thanks. =2D-=20 Thierry --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Provide-emacs-29-behavior-for-register-preview.patch Content-Transfer-Encoding: quoted-printable From=201b85a30f0150b0427b8efb3dee9ea4d740f3254b Mon Sep 17 00:00:00 2001 From: Thierry Volpiatto <thievol@posteo.net> Date: Mon, 11 Dec 2023 09:02:58 +0100 Subject: [PATCH] Provide emacs-29 behavior for register-preview It is now the default with a value of register-use-preview eq to basic. To change this one have now to customize register-use-preview to another value. * lisp/register.el (register-preview-delay): Remove obsolescence. (register--read-with-preview-function): New. (register-use-preview): New option basic, it is now the default. (register-preview-default-1): New the register-preview-default used by `register-read-with-preview-fancy`. (register-preview-default): Restored (same as Emacs-29). (register--preview-function): Generic fn that return the right function for register--preview-function. (register-preview): Restored (same behavior as Emacs-29). (register-preview-1): Used by `register-read-with-preview-fancy'. (register-read-with-preview-basic): The old register-read-with-preview. (register-read-with-preview-fancy): The new register-read-with-preview. =2D-- lisp/register.el | 133 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 121 insertions(+), 12 deletions(-) diff --git a/lisp/register.el b/lisp/register.el index 2f2f5682e34..5818e818787 100644 =2D-- a/lisp/register.el +++ b/lisp/register.el @@ -100,24 +100,49 @@ If nil, do not show register previews, unless `help-c= har' (or a member of :version "24.4" :type '(choice number (const :tag "No preview unless requested" nil)) :group 'register) =2D(make-obsolete-variable 'register-preview-delay "No longer used." "30.1") =20 (defcustom register-preview-default-keys (mapcar #'string (number-sequence= ?a ?z)) "Default keys for setting a new register." =2D :type '(repeat string)) =2D =2D(defcustom register-use-preview t + :type '(repeat string) + :version 30.1) + +(defvar register--read-with-preview-function nil + "The register read preview function to use. +Two functions are provided, one that provide navigation and +highlighting of the register selected, filtering of register +according to command in use, defaults register to use when +setting a new register, confirmation and notification when you +are about to overwrite a register and generic functions to +configure how each existing commands behave. The other function +provided is the same as what was used in Emacs-29, no filtering, +no navigation, no defaults.") + +(defcustom register-use-preview 'basic "Maybe show register preview. =20 +This have no effect when `register--read-with-preview-function' value +is `register-read-with-preview-basic'. + When set to `t' show a preview buffer with navigation and highlighting. When nil show a basic preview buffer and exit minibuffer immediately after insertion in minibuffer. When set to \\=3D'never behave as above but with no preview buffer at =2Dall." +all. +When set to \\=3D'basic provide a much more basic preview according to +`register-preview-delay', it have the exact same behavior as in Emacs-29." :type '(choice (const :tag "Use preview" t) (const :tag "Use quick preview" nil) =2D (const :tag "Never use preview" never))) + (const :tag "Never use preview" never) + (const :tag "Basic preview like Emacs-29" basic)) + :version 30.1 + :set (lambda (var val) + (set var val) + (setq register--read-with-preview-function + (if (eq val 'basic) + #'register-read-with-preview-basic + #'register-read-with-preview-fancy)) + (setq register-preview-function nil))) =20 (defun get-register (register) "Return contents of Emacs register named REGISTER, or nil if none." @@ -137,17 +162,34 @@ See the documentation of the variable `register-alist= ' for possible VALUEs." (substring d (match-end 0)) d))) =20 =2D(defun register-preview-default (r) +(defun register-preview-default-1 (r) "Function that is the default value of the variable `register-preview-fu= nction'." (format "%s: %s\n" (propertize (string (car r)) 'display (single-key-description (car r))) (register-describe-oneline (car r)))) =20 =2D(defvar register-preview-function #'register-preview-default +(defun register-preview-default (r) + "Function that is the default value of the variable `register-preview-fu= nction'." + (format "%s: %s\n" + (single-key-description (car r)) + (register-describe-oneline (car r)))) + +(defvar register-preview-function nil "Function to format a register for previewing. Called with one argument, a cons (NAME . CONTENTS) as found in `register-a= list'. =2DThe function should return a string, the description of the argument.") +The function should return a string, the description of the argument. +It is set according to the value of `register--read-with-preview-function'= .") + +(cl-defgeneric register--preview-function (read-preview-function) + "Returns a function to format a register for previewing. +This accorfing to the value of read-preview-function.") +(cl-defmethod register--preview-function ((read-preview-function + (eql 'register-read-with-previe= w-basic))) + #'register-preview-default) +(cl-defmethod register--preview-function ((read-preview-function + (eql 'register-read-with-previe= w-fancy))) + #'register-preview-default-1) =20 (cl-defstruct register-preview-info "Store data for a specific register command. @@ -326,12 +368,39 @@ satisfy `cl-typep' otherwise the new type should be d= efined with when (memq (register-type register) types) collect register))) =20 =2D(defun register-preview (buffer &optional show-empty types) +(defun register-preview (buffer &optional show-empty) + "Pop up a window showing the registers preview in BUFFER. +If SHOW-EMPTY is non-nil, show the window even if no registers. +Format of each entry is controlled by the variable `register-preview-funct= ion'." + (unless register-preview-function + (setq register-preview-function (register--preview-function + register--read-with-preview-function)= )) + (when (or show-empty (consp register-alist)) + (with-current-buffer-window + buffer + (cons 'display-buffer-below-selected + '((window-height . fit-window-to-buffer) + (preserve-size . (nil . t)))) + nil + (with-current-buffer standard-output + (setq cursor-in-non-selected-windows nil) + (mapc (lambda (elem) + (when (get-register (car elem)) + (insert (funcall register-preview-function elem)))) + register-alist))))) + +(defun register-preview-1 (buffer &optional show-empty types) "Pop up a window showing the registers preview in BUFFER. + +This is the preview function use with +`register-read-with-preview-fancy' function. If SHOW-EMPTY is non-nil, show the window even if no registers. Argument TYPES (a list) specify the types of register to show, when nil sh= ow all registers, see `register-type' for suitable types. Format of each entry is controlled by the variable `register-preview-funct= ion'." + (unless register-preview-function + (setq register-preview-function (register--preview-function + register--read-with-preview-function)= )) (let ((registers (register-of-type-alist (or types '(all))))) (when (or show-empty (consp registers)) (with-current-buffer-window @@ -359,6 +428,46 @@ Format of each entry is controlled by the variable `re= gister-preview-function'." "Read and return a register name, possibly showing existing registers. Prompt with the string PROMPT. If `help-char' (or a member of `help-event-list') is pressed, +display such a window regardless." + (funcall register--read-with-preview-function prompt)) + +(defun register-read-with-preview-basic (prompt) + "Read and return a register name, possibly showing existing registers. +Prompt with the string PROMPT. If `register-alist' and +`register-preview-delay' are both non-nil, display a window +listing existing registers after `register-preview-delay' seconds. +If `help-char' (or a member of `help-event-list') is pressed, +display such a window regardless." + (let* ((buffer "*Register Preview*") + (timer (when (numberp register-preview-delay) + (run-with-timer register-preview-delay nil + (lambda () + (unless (get-buffer-window buffer) + (register-preview buffer)))))) + (help-chars (cl-loop for c in (cons help-char help-event-list) + when (not (get-register c)) + collect c))) + (unwind-protect + (progn + (while (memq (read-key (propertize prompt 'face 'minibuffer-prompt)) + help-chars) + (unless (get-buffer-window buffer) + (register-preview buffer 'show-empty))) + (when (or (eq ?\C-g last-input-event) + (eq 'escape last-input-event) + (eq ?\C-\[ last-input-event)) + (keyboard-quit)) + (if (characterp last-input-event) last-input-event + (error "Non-character input-event"))) + (and (timerp timer) (cancel-timer timer)) + (let ((w (get-buffer-window buffer))) + (and (window-live-p w) (delete-window w))) + (and (get-buffer buffer) (kill-buffer buffer))))) + +(defun register-read-with-preview-fancy (prompt) + "Read and return a register name, possibly showing existing registers. +Prompt with the string PROMPT. +If `help-char' (or a member of `help-event-list') is pressed, display such a window regardless." (let* ((buffer "*Register Preview*") (buffer1 "*Register quick preview*") @@ -391,13 +500,13 @@ display such a window regardless." ;; Do nothing when buffer1 is in use. (unless (get-buffer-window buf) (with-selected-window (minibuffer-selected-window) =2D (register-preview buffer 'show-empty types)))= ))) + (register-preview-1 buffer 'show-empty types)))= ))) (define-key map (kbd "<down>") 'register-preview-next) (define-key map (kbd "<up>") 'register-preview-previous) (define-key map (kbd "C-n") 'register-preview-next) (define-key map (kbd "C-p") 'register-preview-previous) (unless (or executing-kbd-macro (eq register-use-preview 'never)) =2D (register-preview buf nil types)) + (register-preview-1 buf nil types)) (unwind-protect (progn (minibuffer-with-setup-hook =2D-=20 2.34.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQHHBAEBCgAxFiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmV21ssTHHRoaWV2b2xA cG9zdGVvLm5ldAAKCRAOxW0UHRbvk+aUC/9ddvEU9W0yel0O4sywj4aDjI0c6ZQ2 Y4OzSpdr9o09RkjGigDiaEIScW6cvD6N5+G1f4xO3rcg5F8qoHLGjwXai+QVyQMR TjoGVm5MnGZ1509s8eBfyqQ5IpIaxw2rGAP8xcRz97stONYegfPuYTaw7tY+Zh/Z LoZFCi1Bp8CH37N3zx4uKtpKliqvEtzY4c7jokpy4+Wc0/jtrQIchFAX8H3HT0yu /bB+dcKEEFaHyP/id6PvWXSo4+/Q9MiecGCLwPQtqpTludDfcZnPVJguNt1ELvHW xaO0sGuNSfDmEtwR3lq3NV4vWG1vZdiZjYxfXpk7KSkOLCzunJ6nFOmJBf85UNY5 CAHYDvsKEkuASSbtmnXc/80G1m83V4YeqZCy2A3OLJVzR0I2u+i55qwllKy3D1+I eBibH9wYFPiDhIA79/UNOvpGbYgUUDv8s9KDp6pE/wKiNiLeDgnCEErrHYqPmRle 6nKzFEIEBHV88jm6OQBg49VLMJfFVHbB0oE= =cSFh -----END PGP SIGNATURE----- --==-=-=--