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: Mon, 04 Jul 2022 20:45:47 +0300 [thread overview]
Message-ID: <86h73weppw.fsf@mail.linkov.net> (raw)
In-Reply-To: <87h73x882a.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 04 Jul 2022 12:51:25 +0200")
[-- Attachment #1: Type: text/plain, Size: 996 bytes --]
>> 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 <left>, <right>, S-<left>, or S-<right>.
NEW: Indent region with TAB, <left>, <right>, S-<left>, S-<right>
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-+].
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: set-transient-map.patch --]
[-- Type: text/x-diff, Size: 6685 bytes --]
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-map>\\[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")))))
\f
;; ----------------------------------------------------------------
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-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
+ "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.
next prev parent reply other threads:[~2022-07-04 17:45 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
2022-07-04 10:51 ` Lars Ingebrigtsen
2022-07-04 17:45 ` Juri Linkov [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86h73weppw.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).