* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
@ 2021-04-10 8:23 Ramesh Nedunchezian
2021-04-10 10:34 ` Dmitry Gutov
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Ramesh Nedunchezian @ 2021-04-10 8:23 UTC (permalink / raw)
To: 47688
Could you please add rectangle commands to the repeatable set? This
is what I have in my .emacs. It works reasonably well, except for the
`x' (- `rectangle-exchange-point-and-mark') key below:
Issue 1:
--------
In Non-repeat mode,
1. Press C-x SPC and make a rectangel.
2. Press C-x C-x 4 or more times. You will see the cursor jumping
between the corners.
With below snippet installed, in repeat-mode, repeat the above
operations with single key strokes. I am seeing that the 3rd press of
x gets me out of the repeat loop and inserts the char "x" in the
buffer.
Issue 2: A repeat map can provide a custom `:help'-er
-----------------------------------------------------
This is the message I see in the minibuffer.
Repeat with c, ESC, w, r, d, k, o, b, C-b, x, C-x, f, C-f, <left>,
SPC, <down>, C-n, N, <up>, C-p, <right>, t, y
1. `ESC' above correpsonds to `M-w' in the repeat map. The single
character `ESC' confused me for some time. I wonder if the help
text could be improved in this case.
2. The help text is really really big, and it clutters the echo area.
It seems that .... Repeatable keys are essentially a poor-man's
hydra,
So, a repeat-map, like the rectangle one below, which has lots of
keybindings can set a `:help' attribute on itself.
`repeat-post-hook' can then rely on this `:help'-er to provide a
help much similar to what the hydra package provides.
Issue 3: A repeat map can take `:keep-pred' (or a `:exit-key') and other properties.
----------------------------------------------------------------------------
When looked askance, `repeat-post-hook' is essentially a wrapper
around `transient-map'.
So, a `repeat-map' can take a `:keep-pred' and `:on-exit' attributes,
in addition to a `:help' attribute.
This will obviate the need for the global `repeat-exit-key' i.e., the
choice of how the map exits should itself be delegated to the repeat
map. `
Suggestion 1: Provide a macro(?) for creating repeatable commands.
------------------------------------------------------------------
Provide a defmacro for creating repeatable keymaps. The snippet below
is actually created by my own `defmacro'. The macro takes an list of
(KEY . CMD) and a name of repeat map and generates what you see below.
(Bonus points, if the API invocation looks much similar to `bind-key'
section in a in a `use-package' directive)
The rectangle commands itself come from two different maps
`ctl-x-r-map' and `rectangle-mark-mode-map'. The first one has
/non-rectangle/ commands like register commands.
If the repeatable commands all come from a single map (and if there
are no other commands in that map), then there is NO need for this
API. One could do something what diff-hl already does
(map-keymap
(lambda (_key cmd)
(put cmd 'repeat-map 'diff-hl-command-map))
diff-hl-command-map)
The need for this APIs arise only because one is collecting the keys
from disparate maps.
Suggestion 2:
------------
Provide a defmacro for chained commands. I am making the suggestion
here. I will provide details in a separate bug report.
----------------------------------------------------------------
Snippet for making rectangle commands repeatable.
-------------------------------------------------
(progn
(defvar rectangle-repeat-map
(let ((map (make-sparse-keymap)))
map))
(cl-loop for (cmd . key-sequence) in
`(
(clear-rectangle . "c")
(copy-rectangle-as-kill . ,(kbd "M-w"))
(copy-rectangle-as-kill . "w")
(copy-rectangle-to-register . "r")
(delete-rectangle . "d")
(kill-rectangle . "k")
(open-rectangle . "o")
(rectangle-backward-char . "b")
(rectangle-backward-char . ,(kbd "C-b"))
(rectangle-exchange-point-and-mark . "x")
(rectangle-exchange-point-and-mark . ,(kbd "C-x C-x"))
(rectangle-forward-char . "f")
(rectangle-forward-char . ,(kbd "C-f"))
(rectangle-left-char . ,(kbd "<left>"))
(rectangle-mark-mode . " ")
(rectangle-mark-mode . ,(kbd "C-x SPC"))
(rectangle-next-line . ,(kbd "<down>"))
(rectangle-next-line . ,(kbd "C-n"))
(rectangle-number-lines . "N")
(rectangle-previous-line . ,(kbd "<up>"))
(rectangle-previous-line . ,(kbd "C-p"))
(rectangle-right-char . ,(kbd "<right>"))
(string-rectangle . "t")
(yank-rectangle . "y")
)
do
(define-key rectangle-repeat-map key-sequence cmd)
(put cmd 'repeat-map 'rectangle-repeat-map)))
----------------------------------------------------------------
In GNU Emacs 28.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
of 2021-04-07 built on debian
Repository revision: c1173f231d46f14f71886fa343dbc7501f064919
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: Debian GNU/Linux bullseye/sid
Configured using:
'configure -with-imagemagick --with-json --with-xwidgets'
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
2021-04-10 8:23 bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments Ramesh Nedunchezian
@ 2021-04-10 10:34 ` Dmitry Gutov
2021-04-10 13:04 ` Ramesh Nedunchezian
2021-04-10 12:32 ` Ramesh Nedunchezian
` (3 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Dmitry Gutov @ 2021-04-10 10:34 UTC (permalink / raw)
To: Ramesh Nedunchezian, 47688
On 10.04.2021 11:23, Ramesh Nedunchezian wrote:
> So, a repeat-map, like the rectangle one below, which has lots of
> keybindings can set a `:help' attribute on itself.
> `repeat-post-hook' can then rely on this `:help'-er to provide a
> help much similar to what the hydra package provides.
:help attribute sounds like a neat alternative, but what would you set
it to?
Aside from nil, perhaps.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
2021-04-10 8:23 bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments Ramesh Nedunchezian
2021-04-10 10:34 ` Dmitry Gutov
@ 2021-04-10 12:32 ` Ramesh Nedunchezian
2021-04-12 16:16 ` Juri Linkov
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Ramesh Nedunchezian @ 2021-04-10 12:32 UTC (permalink / raw)
To: 47688
On 10/04/21 1:53 pm, Ramesh Nedunchezian wrote:
> Provide a defmacro for chained commands. I am making the suggestion
> here. I will provide details in a separate bug report.
I have documented my use case, and a recipe here:
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=47690
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
2021-04-10 10:34 ` Dmitry Gutov
@ 2021-04-10 13:04 ` Ramesh Nedunchezian
2021-04-10 14:54 ` Dmitry Gutov
0 siblings, 1 reply; 9+ messages in thread
From: Ramesh Nedunchezian @ 2021-04-10 13:04 UTC (permalink / raw)
To: Dmitry Gutov, 47688
[-- Attachment #1: Type: text/plain, Size: 1785 bytes --]
On 10/04/21 4:04 pm, Dmitry Gutov wrote:
> On 10.04.2021 11:23, Ramesh Nedunchezian wrote:
>> So, a repeat-map, like the rectangle one below, which has lots of
>> keybindings can set a `:help' attribute on itself.
>> `repeat-post-hook' can then rely on this `:help'-er to provide a
>> help much similar to what the hydra package provides.
>
> :help attribute sounds like a neat alternative, but what would you set it to?
>
> Aside from nil, perhaps.
Hydra -- this is part of GNU Emacs / GNU ELPA -- uses one of the 3
types
(defcustom hydra-hint-display-type 'lv
"The utility to show hydra hint"
:type '(choice
(const message)
(const lv)
(const posframe))
:group 'hydra)
(https://github.com/abo-abo/hydra/blob/2d553787aca1aceb3e6927e426200e9bb9f056f1/hydra.el#L249)
Hydra's hints are very pleasant to look at, and hydra is one of the
frequently mentioned package in reddit.com/r/emacs.
I am attaching screenshots of how the 'lv' and 'posframe' hints looks
like for one of the "fancier" hydras in the project's README
(https://github.com/abo-abo/hydra)
The core idea behind my suggestion is that /the/ repeat map itself is
the best judge on what sort of hint is the best.
I understand that repeat-mode's "Repeat with ..." and "Exit with ..."
messages are more of informational / diagonsic messages. The messages
need stop at being diagnostic assurances. They can go a step further
and be hints.
'nil'--do nothing--as a ':help'-er is what an experienced user may
want. A verbose hint is what a beginner will appreciate.
Rectangle, register and highlight commands are very useful ... and
when I was new to Emacs they were bothersome to type and remember.
/Younger/ me would have /loved/ a hydra-like hints.
[-- Attachment #2: hydra-hint--lv.png --]
[-- Type: image/png, Size: 117124 bytes --]
[-- Attachment #3: hydra-hint--posframe.png --]
[-- Type: image/png, Size: 107483 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
2021-04-10 13:04 ` Ramesh Nedunchezian
@ 2021-04-10 14:54 ` Dmitry Gutov
0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Gutov @ 2021-04-10 14:54 UTC (permalink / raw)
To: Ramesh Nedunchezian, 47688
On 10.04.2021 16:04, Ramesh Nedunchezian wrote:
> Hydra -- this is part of GNU Emacs / GNU ELPA -- uses one of the 3
> types
>
> (defcustom hydra-hint-display-type 'lv
> "The utility to show hydra hint"
> :type '(choice
> (const message)
> (const lv)
> (const posframe))
> :group 'hydra)
>
> (https://github.com/abo-abo/hydra/blob/2d553787aca1aceb3e6927e426200e9bb9f056f1/hydra.el#L249)
>
> Hydra's hints are very pleasant to look at, and hydra is one of the
> frequently mentioned package in reddit.com/r/emacs.
Nothing against Hydra, but its hints are even noisier than what have now
with repeat-mode.
> I am attaching screenshots of how the 'lv' and 'posframe' hints looks
> like for one of the "fancier" hydras in the project's README
> (https://github.com/abo-abo/hydra)
>
> The core idea behind my suggestion is that /the/ repeat map itself is
> the best judge on what sort of hint is the best.
Right.
But some recommendations for less obtrusive notifications could be helpul.
> I understand that repeat-mode's "Repeat with ..." and "Exit with ..."
> messages are more of informational / diagonsic messages. The messages
> need stop at being diagnostic assurances. They can go a step further
> and be hints.
>
> 'nil'--do nothing--as a ':help'-er is what an experienced user may
> want. A verbose hint is what a beginner will appreciate.
So it might use a user option as well.
But when hints are enabled, I'm looking for some version that's less
in-your-face than Hydra.
> Rectangle, register and highlight commands are very useful ... and
> when I was new to Emacs they were bothersome to type and remember.
> /Younger/ me would have /loved/ a hydra-like hints.
No doubt.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
2021-04-10 8:23 bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments Ramesh Nedunchezian
2021-04-10 10:34 ` Dmitry Gutov
2021-04-10 12:32 ` Ramesh Nedunchezian
@ 2021-04-12 16:16 ` Juri Linkov
2021-04-13 16:09 ` Juri Linkov
2021-04-14 18:12 ` Juri Linkov
[not found] ` <handler.47688.D47688.161842410719411.notifdone@debbugs.gnu.org>
4 siblings, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2021-04-12 16:16 UTC (permalink / raw)
To: Ramesh Nedunchezian; +Cc: 47688
> Could you please add rectangle commands to the repeatable set?
Could you please demonstrate an example of the real key sequences
where repeat-mode could help to greatly reduce the length of
such key sequences.
> This is what I have in my .emacs. It works reasonably well, except
> for the `x' (- `rectangle-exchange-point-and-mark') key below:
>
> Issue 1:
> --------
>
> In Non-repeat mode,
>
> 1. Press C-x SPC and make a rectangel.
>
> 2. Press C-x C-x 4 or more times. You will see the cursor jumping
> between the corners.
>
> With below snippet installed, in repeat-mode, repeat the above
> operations with single key strokes. I am seeing that the 3rd press of
> x gets me out of the repeat loop and inserts the char "x" in the
> buffer.
Thanks for reporting the issue, this is fixed now.
> Issue 2: A repeat map can provide a custom `:help'-er
> -----------------------------------------------------
>
> This is the message I see in the minibuffer.
>
> Repeat with c, ESC, w, r, d, k, o, b, C-b, x, C-x, f, C-f, <left>,
> SPC, <down>, C-n, N, <up>, C-p, <right>, t, y
>
> 1. `ESC' above correpsonds to `M-w' in the repeat map. The single
> character `ESC' confused me for some time. I wonder if the help
> text could be improved in this case.
I don't know if there is a function that extracts all key sequences
from the keymap.
There is describe-map-tree that prints the keybindings to the output buffer,
but what is needed is a function that just returns a list of key sequences
from the keymap.
> 2. The help text is really really big, and it clutters the echo area.
>
> It seems that .... Repeatable keys are essentially a poor-man's
> hydra,
>
> So, a repeat-map, like the rectangle one below, which has lots of
> keybindings can set a `:help' attribute on itself.
> `repeat-post-hook' can then rely on this `:help'-er to provide a
> help much similar to what the hydra package provides.
A new option is implemented now.
> Issue 3: A repeat map can take `:keep-pred' (or a `:exit-key') and other properties.
> ----------------------------------------------------------------------------
>
> When looked askance, `repeat-post-hook' is essentially a wrapper
> around `transient-map'.
>
> So, a `repeat-map' can take a `:keep-pred' and `:on-exit' attributes,
> in addition to a `:help' attribute.
We already tried to change the values of set-transient-map arguments,
but such arguments break repeat-map.
> This will obviate the need for the global `repeat-exit-key' i.e., the
> choice of how the map exits should itself be delegated to the repeat
> map. `
The purpose of repeat-exit-key is to avoid the need to add an exit key
to every keymap.
> Suggestion 1: Provide a macro(?) for creating repeatable commands.
> ------------------------------------------------------------------
>
> Suggestion 2:
> ------------
>
> Provide a defmacro for chained commands. I am making the suggestion
> here. I will provide details in a separate bug report.
Such convenience macros are better suitable for a separate package like hydra.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
2021-04-12 16:16 ` Juri Linkov
@ 2021-04-13 16:09 ` Juri Linkov
0 siblings, 0 replies; 9+ messages in thread
From: Juri Linkov @ 2021-04-13 16:09 UTC (permalink / raw)
To: Ramesh Nedunchezian; +Cc: 47688
[-- Attachment #1: Type: text/plain, Size: 477 bytes --]
> Could you please demonstrate an example of the real key sequences
> where repeat-mode could help to greatly reduce the length of
> such key sequences.
An example where such repeating map is sorely missing is gdb.
Until now, stepping through the program was a hassle that required
typing such overly long key sequences:
'C-x C-a C-n C-x C-a C-n C-x C-a C-n C-x C-a C-n C-x C-a C-n ...'
Now with the following patch, stepping is much easier:
'C-x C-a C-n n n n n ...'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gud-step-repeat-map.patch --]
[-- Type: text/x-diff, Size: 1324 bytes --]
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index b105cbaa0e..45ba9fff07 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -293,6 +293,12 @@ gud-tool-bar-map
(tool-bar-local-item-from-menu
(car x) (cdr x) map gud-minor-mode-map))))
+(defvar gud-step-repeat-map
+ (let ((map (make-sparse-keymap)))
+ map)
+ "Keymap to repeat gud stepping instructions `C-x C-a C-n n n'.
+Used in `repeat-mode'.")
+
(defun gud-file-name (f)
"Transform a relative file name to an absolute file name.
Uses `gud-<MINOR-MODE>-directories' to find the source files."
@@ -784,6 +790,17 @@ gud-gdb
(gud-def gud-until "until %l" "\C-u" "Continue to current line.")
(gud-def gud-run "run" nil "Run the program.")
+ (dolist (cmd '(("n" . gud-next)
+ ("s" . gud-step)
+ ("i" . gud-stepi)
+ ("c" . gud-cont)
+ ("l" . gud-refresh)
+ ("f" . gud-finish)
+ ("<" . gud-up)
+ (">" . gud-down)))
+ (define-key gud-step-repeat-map (car cmd) (cdr cmd))
+ (put (cdr cmd) 'repeat-map 'gud-step-repeat-map))
+
(add-hook 'completion-at-point-functions #'gud-gdb-completion-at-point
nil 'local)
(setq-local gud-gdb-completion-function 'gud-gdb-completions)
[-- Attachment #3: Type: text/plain, Size: 114 bytes --]
Also you can see that adding a convenience macro wouldn't much of help here,
dolist is quite convenient as well.
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments
2021-04-10 8:23 bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments Ramesh Nedunchezian
` (2 preceding siblings ...)
2021-04-12 16:16 ` Juri Linkov
@ 2021-04-14 18:12 ` Juri Linkov
[not found] ` <handler.47688.D47688.161842410719411.notifdone@debbugs.gnu.org>
4 siblings, 0 replies; 9+ messages in thread
From: Juri Linkov @ 2021-04-14 18:12 UTC (permalink / raw)
To: Ramesh Nedunchezian; +Cc: 47688-done
> Could you please add rectangle commands to the repeatable set? This
> is what I have in my .emacs.
> ...
> (rectangle-backward-char . "b")
> (rectangle-backward-char . ,(kbd "C-b"))
> (rectangle-exchange-point-and-mark . "x")
> (rectangle-exchange-point-and-mark . ,(kbd "C-x C-x"))
> (rectangle-forward-char . "f")
> (rectangle-forward-char . ,(kbd "C-f"))
> (rectangle-left-char . ,(kbd "<left>"))
> (rectangle-mark-mode . " ")
> (rectangle-mark-mode . ,(kbd "C-x SPC"))
> (rectangle-next-line . ,(kbd "<down>"))
> (rectangle-next-line . ,(kbd "C-n"))
> (rectangle-number-lines . "N")
> (rectangle-previous-line . ,(kbd "<up>"))
> (rectangle-previous-line . ,(kbd "C-p"))
> (rectangle-right-char . ,(kbd "<right>"))
Thanks for the suggestions. 'C-x SPC' activates 'rectangle-mark-mode'
that already supports short key sequences similar to 'repeat-mode':
(defvar rectangle-mark-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [?\C-o] 'open-rectangle)
(define-key map [?\C-t] 'string-rectangle)
(define-key map [remap exchange-point-and-mark]
'rectangle-exchange-point-and-mark)
(dolist (cmd '(right-char left-char forward-char backward-char
next-line previous-line))
(define-key map (vector 'remap cmd)
(intern (format "rectangle-%s" cmd))))
There are already single keys to edit the rectangle.
If you want, you can request more short keys to be
added to rectangle-mark-mode-map in a separate report.
So it seems this request can be closed now.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#47688: closed (Re: bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments)
[not found] ` <handler.47688.D47688.161842410719411.notifdone@debbugs.gnu.org>
@ 2021-05-04 4:19 ` Ramesh Nedunchezian
0 siblings, 0 replies; 9+ messages in thread
From: Ramesh Nedunchezian @ 2021-05-04 4:19 UTC (permalink / raw)
To: 47688
On 14/04/21 11:46 pm, GNU bug Tracking System wrote:
> Thanks for the suggestions. 'C-x SPC' activates 'rectangle-mark-mode'
> that already supports short key sequences similar to 'repeat-mode':
>
> (defvar rectangle-mark-mode-map
> (let ((map (make-sparse-keymap)))
> (define-key map [?\C-o] 'open-rectangle)
> (define-key map [?\C-t] 'string-rectangle)
> (define-key map [remap exchange-point-and-mark]
> 'rectangle-exchange-point-and-mark)
> (dolist (cmd '(right-char left-char forward-char backward-char
> next-line previous-line))
> (define-key map (vector 'remap cmd)
> (intern (format "rectangle-%s" cmd))))
>
> There are already single keys to edit the rectangle.
C-o, C-t are not single keys. There is a difference between: (a) There
exists single keys (b) All keys are single keys.
I will not chase down this request further. I can achieve what I want
in my `.emacs'. Thanks for addressing the C-x C-x part which I
wouldn't have been able to take care of in my .emacs.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-05-04 4:19 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-10 8:23 bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments Ramesh Nedunchezian
2021-04-10 10:34 ` Dmitry Gutov
2021-04-10 13:04 ` Ramesh Nedunchezian
2021-04-10 14:54 ` Dmitry Gutov
2021-04-10 12:32 ` Ramesh Nedunchezian
2021-04-12 16:16 ` Juri Linkov
2021-04-13 16:09 ` Juri Linkov
2021-04-14 18:12 ` Juri Linkov
[not found] ` <handler.47688.D47688.161842410719411.notifdone@debbugs.gnu.org>
2021-05-04 4:19 ` bug#47688: closed (Re: bug#47688: 28.0.50; repeat-mode: Make rectangle commands repeatable. Also some misc. queries, comments) Ramesh Nedunchezian
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).