From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#21634: text-scale-adjust suggestion Date: Sun, 03 Jul 2022 19:36:04 +0300 Organization: LINKOV.NET Message-ID: <86wncu6t6b.fsf@mail.linkov.net> References: <22035.47283.76000.848103@gargle.gargle.HOWL> <83d1wsxcuz.fsf@gnu.org> <87zgstyl9e.fsf_-_@gnus.org> <871r65ab7q.fsf@mail.linkov.net> <87czpou8z7.fsf@gnus.org> <86letewfpa.fsf@mail.linkov.net> <878rpdyyxo.fsf@gnus.org> <86k08wzx5e.fsf@mail.linkov.net> <87r1333etw.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10600"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Eli Barzilay , Eli Zaretskii , 21634@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 03 18:54:30 2022 Return-path: 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 ) id 1o82re-0002YF-Cm for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Jul 2022 18:54:30 +0200 Original-Received: from localhost ([::1]:38848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o82rc-0000q8-TE for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Jul 2022 12:54:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o82rC-0000nG-8h for bug-gnu-emacs@gnu.org; Sun, 03 Jul 2022 12:54:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o82rB-0001h2-Uk for bug-gnu-emacs@gnu.org; Sun, 03 Jul 2022 12:54:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o82rB-0007If-UA for bug-gnu-emacs@gnu.org; Sun, 03 Jul 2022 12:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Jul 2022 16:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21634 X-GNU-PR-Package: emacs Original-Received: via spool by 21634-submit@debbugs.gnu.org id=B21634.165686721328025 (code B ref 21634); Sun, 03 Jul 2022 16:54:01 +0000 Original-Received: (at 21634) by debbugs.gnu.org; 3 Jul 2022 16:53:33 +0000 Original-Received: from localhost ([127.0.0.1]:45449 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o82qi-0007Hw-Qz for submit@debbugs.gnu.org; Sun, 03 Jul 2022 12:53:33 -0400 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:47295) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o82qf-0007Hj-VR for 21634@debbugs.gnu.org; Sun, 03 Jul 2022 12:53:32 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id CC91020004; Sun, 3 Jul 2022 16:53:22 +0000 (UTC) In-Reply-To: <87r1333etw.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 02 Jul 2022 13:59:39 +0200") 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" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:236012 Archived-At: --=-=-= Content-Type: text/plain > Juri Linkov writes: > >> Actually, I can imagine when someone might want to keep a transient map >> active with KEEP-PRED, but still deactivate it after a timeout. So >> a separate TIMEOUT looks cleaner. > > Yup, makes sense. > >> Anyway, repeat-mode has separate options for repeat-exit-timeout >> and constructs a message, so I could copy the same code from repeat-mode >> to set-transient-map. > > Sounds good. Maybe something like this. I'm still unsure about providing a prefix message without keys, because when the message arg is a string then better to display it as is. Otherwise when it is `t', then the message will be constructed to "Repeat with ". I.e. the remaining question is that you already raised whether typically all keys should be mentioned in the message. OTOH, there are messages like "Use \\`+',\\`-',\\`0' for further adjustment" have not only a prefix, but also a suffix. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=set-transient-map.patch diff --git a/lisp/face-remap.el b/lisp/face-remap.el index 7037bc58cb..951285fbf2 100644 --- a/lisp/face-remap.el +++ b/lisp/face-remap.el @@ -408,9 +408,6 @@ text-scale-adjust (?0 0) (_ inc)))) (text-scale-increase step) - ;; (unless (zerop step) - (message (substitute-command-keys - "Use \\`+',\\`-',\\`0' for further adjustment")) (set-transient-map (let ((map (make-sparse-keymap))) (dolist (mods '(() (control))) @@ -418,10 +415,9 @@ text-scale-adjust (define-key map (vector (append mods (list key))) (lambda () (interactive) (text-scale-adjust (abs inc)))))) map) - nil - ;; Clear the prompt after exiting. - (lambda () - (message "")))))) + nil nil + (substitute-command-keys + "Use \\`+',\\`-',\\`0' for further adjustment"))))) (defvar-local text-scale--pinch-start-scale 0 "The text scale at the start of a pinch sequence.") @@ -515,15 +511,16 @@ global-text-scale-adjust (not global-text-scale-adjust-resizes-frames))) (set-face-attribute 'default nil :height new))) (when (characterp key) - (message (substitute-command-keys - "Use \\`+',\\`-',\\`0' for further adjustment")) (set-transient-map (let ((map (make-sparse-keymap))) (dolist (mod '(() (control meta))) (dolist (key '(?+ ?= ?- ?0)) (define-key map (vector (append mod (list key))) 'global-text-scale-adjust))) - map)))))) + map) + nil nil + (substitute-command-keys + "Use \\`+',\\`-',\\`0' for further adjustment")))))) ;; ---------------------------------------------------------------- diff --git a/lisp/indent.el b/lisp/indent.el index d6dee94016..6eaf9f04ae 100644 --- a/lisp/indent.el +++ b/lisp/indent.el @@ -270,11 +270,10 @@ indent-rigidly indentation by specifying a large negative ARG." (interactive "r\nP\np") (if (and (not arg) interactive) - (progn - (message - (substitute-command-keys - "Indent region with \\\\[indent-rigidly-left], \\[indent-rigidly-right], \\[indent-rigidly-left-to-tab-stop], or \\[indent-rigidly-right-to-tab-stop].")) - (set-transient-map indent-rigidly-map t #'deactivate-mark)) + (set-transient-map + indent-rigidly-map t #'deactivate-mark + (substitute-command-keys + "Indent region with \\\\[indent-rigidly-left], \\[indent-rigidly-right], \\[indent-rigidly-left-to-tab-stop], or \\[indent-rigidly-right-to-tab-stop].")) (save-excursion (goto-char end) (setq end (point-marker)) diff --git a/lisp/subr.el b/lisp/subr.el index 4e4eac32d9..338248bbae 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -6013,7 +6013,15 @@ internal-pop-keymap (define-obsolete-function-alias 'set-temporary-overlay-map #'set-transient-map "24.4") -(defun set-transient-map (map &optional keep-pred on-exit) +(defvar set-transient-map-timeout 3 + "Break the repetition chain of keys after specified timeout. +When a number, exit the previous `set-transient-map' after idle time +of the specified number of seconds.") + +(defvar set-transient-map-timer nil + "Timer to exit `set-transient-map' after `set-transient-map-timeout'.") + +(defun set-transient-map (map &optional keep-pred on-exit message timeout) "Set MAP as a temporary keymap taking precedence over other keymaps. Normally, MAP is used only once, to look up the very next key. However, if the optional argument KEEP-PRED is t, MAP stays @@ -6030,18 +6038,33 @@ set-transient-map This returns an \"exit function\", which can be called with no argument to deactivate this transient map, regardless of KEEP-PRED." - (let* ((clearfun (make-symbol "clear-transient-map")) + (let* ((timeout (or set-transient-map-timeout timeout)) + (message + (when message + (if (stringp message) message + (let (keys) + (map-keymap (lambda (key cmd) (and cmd (push key keys))) map) + (format-message "Repeat with %s" + (mapconcat (lambda (key) + (substitute-command-keys + (format "\\`%s'" + (key-description (vector key))))) + keys ", ")))))) + (clearfun (make-symbol "clear-transient-map")) (exitfun (lambda () (internal-pop-keymap map 'overriding-terminal-local-map) (remove-hook 'pre-command-hook clearfun) + ;; Clear the prompt after exiting. + (when message (message "")) + (when set-transient-map-timer (cancel-timer set-transient-map-timer)) (when on-exit (funcall on-exit))))) ;; Don't use letrec, because equal (in add/remove-hook) could get trapped ;; in a cycle. (bug#46326) (fset clearfun (lambda () (with-demoted-errors "set-transient-map PCH: %S" - (unless (cond + (if (cond ((null keep-pred) nil) ((and (not (eq map (cadr overriding-terminal-local-map))) (memq map (cddr overriding-terminal-local-map))) @@ -6066,9 +6089,14 @@ set-transient-map ;; nil and so is `mc`. (and mc (eq this-command mc)))) (t (funcall keep-pred))) + (when message (message "%s" message)) (funcall exitfun))))) (add-hook 'pre-command-hook clearfun) (internal-push-keymap map 'overriding-terminal-local-map) + (when timeout + (when set-transient-map-timer (cancel-timer set-transient-map-timer)) + (setq set-transient-map-timer (run-with-idle-timer timeout nil exitfun))) + (when message (message "%s" message)) exitfun)) ;;;; Progress reporters. --=-=-=--