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: Mon, 04 Jul 2022 20:45:47 +0300 Organization: LINKOV.NET Message-ID: <86h73weppw.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> <86wncu6t6b.fsf@mail.linkov.net> <87h73x882a.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="30060"; 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 Mon Jul 04 19:50:24 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 1o8QDH-0007gu-KW for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Jul 2022 19:50:23 +0200 Original-Received: from localhost ([::1]:60876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o8QDG-00013O-CY for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Jul 2022 13:50:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o8QCx-00011F-PS for bug-gnu-emacs@gnu.org; Mon, 04 Jul 2022 13:50:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o8QCv-00080a-Op for bug-gnu-emacs@gnu.org; Mon, 04 Jul 2022 13:50:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o8QCv-0004mJ-MW for bug-gnu-emacs@gnu.org; Mon, 04 Jul 2022 13:50: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: Mon, 04 Jul 2022 17:50: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.165695700018356 (code B ref 21634); Mon, 04 Jul 2022 17:50:01 +0000 Original-Received: (at 21634) by debbugs.gnu.org; 4 Jul 2022 17:50:00 +0000 Original-Received: from localhost ([127.0.0.1]:48612 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8QCt-0004lz-Mi for submit@debbugs.gnu.org; Mon, 04 Jul 2022 13:50:00 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:55389) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o8QCq-0004lc-3l for 21634@debbugs.gnu.org; Mon, 04 Jul 2022 13:49:58 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 57AA11C0009; Mon, 4 Jul 2022 17:49:47 +0000 (UTC) In-Reply-To: <87h73x882a.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 04 Jul 2022 12:51:25 +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:236066 Archived-At: --=-=-= Content-Type: text/plain >> OTOH, there are messages like "Use \\`+',\\`-',\\`0' for further adjustment" >> have not only a prefix, but also a suffix. > > Perhaps the MESSAGE should be a format-spec string? So the caller could > say "Use %k for further adjustment" and have the keymap description > inserted at the %k. That should be plenty flexible. format-spec is a nice helper. Here are the changes after the value of %k is automatically generated from the keys: emoji-zoom-increase: OLD: Zoom with + and - NEW: Zoom with +, - indent-rigidly: OLD: Indent region with , , S-, or S-. NEW: Indent region with TAB, , , S-, S- text-scale-adjust: OLD: Use +,-,0 for further adjustment NEW: Use +, =, -, 0, C-+, C-=, C--, C-0 for further adjustment global-text-scale-adjust: OLD: Use +,-,0 for further adjustment NEW: Use +, =, -, 0, ESC for further adjustment ESC is because map-keymap handles only top-level keys but C-M-+ is [ESC C-+]. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=set-transient-map.patch diff --git a/lisp/international/emoji.el b/lisp/international/emoji.el index 27b725b0aa..a129656d2b 100644 --- a/lisp/international/emoji.el +++ b/lisp/international/emoji.el @@ -709,10 +709,7 @@ emoji-zoom-increase "Increase the size of the character under point. FACTOR is the multiplication factor for the size." (interactive) - (message - (substitute-command-keys - "Zoom with \\\\[emoji-zoom-increase] and \\[emoji-zoom-decrease]")) - (set-transient-map emoji-zoom-map t) + (set-transient-map emoji-zoom-map t nil "Zoom with %k") (let* ((factor (or factor 1.1)) (old (get-text-property (point) 'face)) (height (or (and (consp old) diff --git a/lisp/face-remap.el b/lisp/face-remap.el index 467ccbc299..fd49c81ab3 100644 --- a/lisp/face-remap.el +++ b/lisp/face-remap.el @@ -408,20 +408,15 @@ 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))) - (dolist (key '(?- ?+ ?= ?0)) ;; = is often unshifted +. + (dolist (key '(?+ ?= ?- ?0)) ;; = is often unshifted +. (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 + "Use %k for further adjustment")))) (defvar-local text-scale--pinch-start-scale 0 "The text scale at the start of a pinch sequence.") @@ -515,15 +510,15 @@ 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 + "Use %k for further adjustment"))))) ;; ---------------------------------------------------------------- diff --git a/lisp/indent.el b/lisp/indent.el index d6dee94016..f52b729051 100644 --- a/lisp/indent.el +++ b/lisp/indent.el @@ -270,11 +270,8 @@ 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 + "Indent region with %k") (save-excursion (goto-char end) (setq end (point-marker)) diff --git a/lisp/subr.el b/lisp/subr.el index 2f9d37ffd6..efb920ec5a 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,34 @@ 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 + (let (keys) + (map-keymap (lambda (key cmd) (and cmd (push key keys))) map) + (format-spec (if (stringp message) message + "Repeat with %k") + `((?k . ,(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 +6090,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. --=-=-=--