all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Eli Barzilay <eli@barzilay.org>, Eli Zaretskii <eliz@gnu.org>,
	21634@debbugs.gnu.org
Subject: bug#21634: text-scale-adjust suggestion
Date: Sun, 03 Jul 2022 19:36:04 +0300	[thread overview]
Message-ID: <86wncu6t6b.fsf@mail.linkov.net> (raw)
In-Reply-To: <87r1333etw.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 02 Jul 2022 13:59:39 +0200")

[-- Attachment #1: Type: text/plain, Size: 934 bytes --]

> Juri Linkov <juri@linkov.net> 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 <keys...>".
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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: set-transient-map.patch --]
[-- Type: text/x-diff, Size: 6135 bytes --]

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"))))))
 
 \f
 ;; ----------------------------------------------------------------
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-map>\\[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-map>\\[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.

  reply	other threads:[~2022-07-03 16:36 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-06 12:04 bug#21634: 24.5; Suggested improvement Eli Barzilay
2015-10-06 14:58 ` Eli Zaretskii
2015-10-22  6:06   ` Eli Barzilay
2015-10-23  8:24     ` Eli Zaretskii
2021-09-03 11:02     ` bug#21634: text-scale-adjust suggestion Lars Ingebrigtsen
2021-09-03 16:13       ` Juri Linkov
2021-09-04  6:54         ` Lars Ingebrigtsen
2021-09-05 16:40           ` Juri Linkov
2021-09-06  8:28             ` Lars Ingebrigtsen
2021-09-06 15:34               ` Juri Linkov
2021-09-06 22:15                 ` bug#21634: [External] : " Drew Adams
2021-09-06 22:31                   ` Eli Barzilay
2021-09-06 22:35                     ` Drew Adams
2021-09-07  8:16                     ` martin rudalics
2022-06-30 16:12           ` Juri Linkov
2022-07-01  9:17             ` Lars Ingebrigtsen
2022-07-01 15:40               ` Juri Linkov
2022-07-02 11:59                 ` Lars Ingebrigtsen
2022-07-03 16:36                   ` Juri Linkov [this message]
2022-07-04 10:51                     ` Lars Ingebrigtsen
2022-07-04 17:45                       ` Juri Linkov
2022-07-05 11:15                         ` Lars Ingebrigtsen
2022-07-05 13:21                           ` Robert Pluim
2022-07-05 16:38                             ` Lars Ingebrigtsen
2022-07-05 16:39                               ` Lars Ingebrigtsen
2022-07-06 17:42                             ` Juri Linkov
2022-07-07  8:01                               ` Lars Ingebrigtsen
2022-07-07 16:49                                 ` Juri Linkov
2022-07-07 18:04                                   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86wncu6t6b.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=21634@debbugs.gnu.org \
    --cc=eli@barzilay.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.