Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeating actions #244

Closed
minad opened this issue Jun 14, 2021 · 10 comments
Closed

Repeating actions #244

minad opened this issue Jun 14, 2021 · 10 comments

Comments

@minad
Copy link
Contributor

minad commented Jun 14, 2021

This is a good idea from cmap - it allows repeating actions by pressing the action key multiple times. This is similar to Emacs 28 repeat-mode.

For example cmap has commands cmap-symbol-next/previous. Furthermore it is potentially useful for org commands at point which can be repeated, e.g., org-timestamp-up.

(defun embark-symbol-next (sym)
  (interactive "s")
  (forward-char)
  (re-search-forward (format "\\_<%s\\_>" (regexp-quote sym))))

(defun embark-symbol-previous (sym)
  (interactive "s")
  (backward-char)
  (re-search-backward (format "\\_<%s\\_>" (regexp-quote sym))))

(define-key embark-symbol-map "p" #'embark-symbol-previous)
(define-key embark-symbol-map "n" #'embark-symbol-next)

These commands could be repeated by pressing C-. n n n.

I assume that support for this will be easy to implement when Embark uses transient keymaps, since then one could just keep the action keymap alive.

@oantolin
Copy link
Owner

Aren't there very few actions one would want to repeat? But yes, going back to transient maps would probably make this easy.

@minad
Copy link
Contributor Author

minad commented Jun 14, 2021

Yes, I am not entirely sure about this. There are probably not many actions, you can take a look at cmap for other examples. Nevertheless I wanted to put it up for discussion.

@hmelman
Copy link

hmelman commented Jun 14, 2021

I'm a big fan of the package symbol-overlay. It's basic feature is that it lets you highlight all occurrences of symbol-at-point in a unique color which makes scanning code for a variable easier. But it's bonus feature is that it installs a transient map on the symbol giving some basic commands easy key bindings: next, previous, first , last, copy (kill-new) and even replace and query-replace (which are quite nice).

If embark could generalize these for any target it would be great. I think you'd want different maps for different target types. symbols or variables you'd want to treat individually like symbol-overlay (go to the next occurrence of this symbol) but for URLs or bug-references (or I guess file names in a buffer) I think you'd want to just go to the next URL. I'm not much of an org user but I'd think various org targets would behave as URLs (eg go to the next timestamp). URLs wouldn't want a replace command but browse-url or open in eww would be nice. So: C-. n n n n b would open the 4th URL from point in the browser.

@oantolin
Copy link
Owner

I would have said that the main feature of symbol-overlay is actually the keymap, since highlighting stuff in different colors is something that the built-in highlight-symbol-at-point does. But yes, that keymap is a great idea. There is also a region-bindings-mode package that gives you a keymap for when you are on an active region. That package makes region commands even more comfortable to use than embark-region-map.

As for these "move to next thing" commands, they sound like a pretty good idea, specially if they are repeatable, but maybe even without that.

@minad
Copy link
Contributor Author

minad commented Jul 31, 2021

Implemented in #245

@minad minad closed this as completed Jul 31, 2021
@oantolin
Copy link
Owner

So, are there any other actions in Embark's default configuration we should mark as repeatable?

@minad
Copy link
Contributor Author

minad commented Jul 31, 2021

Some of the region commands could be repeatable, e.g., rot13 ;)

@minad
Copy link
Contributor Author

minad commented Jul 31, 2021

Seriously when acting on regions or symbols I often like cycling variants, e.g. cycle filling, cycle capitalization, cycle identifier styles (string-inflection package). Then spelling mistakes, the flyspell correct command also cycles at point. One can probably reuse the ispell command to get the same behavior.

@oantolin
Copy link
Owner

Ooh, the string-inflection example sounds like a good one for the wiki. It probably involves just binding one command and adding it to the repeatable list, right?

@minad
Copy link
Contributor Author

minad commented Jul 31, 2021

Yes, this is how I am going to use string-inflection now. Doesn't require an individual toplevel keybinding anymore. Needs some testing though, the target finder may not find the full identifier at point when you cycle through the styles. But I don't think this matters since the command does not read a string but uses the identifier at point. Only the highlighting may be messed up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants