-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
selecting sentence & paragraph; marking target as region for certain commands #347
Comments
Are there some good actions for sentences and paragraphs? I guess beyond saving on the kill-ring, which is always useful, we could have killing and transposing. For paragraphs, filling, indent-rigidly. By the way, I just noticed that the defun target in markdown mode and org mode is a little wonky. It seems to want to select an entire section including it's heading, but not always. And it's odd, because Maybe the defun target finder should only be active in modes that derive from |
I think we had it like this originally? Probably it makes sense to have special text mode target finders (sentence, paragraph) and the defun finder should only be active in prog-modes or code blocks (org, markdown, etc). |
Fill, count words, cleanup blanks, all the region stuff seems interesting. If it's a short sentence you may want to consult grep for it. BTW I'm often wishing some commands would treat the target as a (temporarily) active region, since it is/will be so easy to "select" something interesting with embark. For example, there is no "mark sentence" that I know of. Maybe pushing it too far? |
FWIW, the meaning of a defun in markdown-mode is deliberate. My first thought was that if marking a defun is broken in some mode, that's the fault of the mode and embark shouldn't be altering it's functionality because of that. Then I thought that having two different configs for prog and text modes was pretty reasonable since they'd break along symbol/expression/block/defun and word/sentence/paragraph/page lines. But FWIW,
I was going to ask if something like this was possible. I know that some target maps bind SPC to the relevant mark command. If there was a presumed region or perhaps a generic |
For any commands you would like to treat the target as region you can add a pre-action hook that marks the target: (cl-defun embark--mark-target (&key bounds &allow-other-keys)
(when bounds
(set-mark (car bounds))
(goto-char (cdr bounds))))
(push #'embark--mark-target (alist-get 'kill-region embark-pre-action-hooks)) I'm thinking of adding |
Generally re-using key commands that you already know seems better than learning a new embark one for use only when embarking. For example, I usually use my binding for |
Yeah, I started out doing that too with
Oh, by the way, @jdtsmith, there is a built-in |
So, which region commands is one likely to want to use on an embark target that isn't already a region? I don't want to preconfigure every possible region command to run I was thinking:
Is there any other region command you are likely to want to run on a non-region target? |
I decided to add all of those (except the prose ones, which I'll add later). 0de5038 |
Thanks! Consult-line gets a lot of use for me so I also bind to ("M-s l" . consult-line)
("s-l" . consult-line)
("s-L" . (lambda () (interactive) ; same mode buffers line
(consult-line-multi `(:mode ,major-mode))))
("M-s-L" . consult-line-multi) ; all buffers line We've talked about a transient frontend package that lets you consult-line(-multi) with various configured parameters. |
Will it work for other commands which eventually call the specified embark-able region commands? I have |
No, you'd directly need to Which hooks get run are looked up by action name, so the command needs to directly appear as a key in the alist |
Understood. Perhaps |
Also perhaps case conversion:
|
I'm hoping to see more transient UIs pop up now that it is in core Emacs. I suspect people will abuse transient for my taste, and use it for things you don't really need it, but for some cases it is really great. The |
I thought of those, but do you really want to put an entire string or defun in all caps that often? Although maybe that's the wrong question, maybe I should be thinking instead: "if an embark user uses a case command as an action, what do they expect to happen?" And I should configure these so they just work if someone decides to try them. OK, I think I talked myself into it. :D |
Oh, and those just delete without saving on the kill-ring right? That's good to have. |
The mark and kill generalization for targets with bounds is a great idea. Didn't think of this when we added highlighting. Are some specific mark/kill commands made obsolete by the generic commands? |
Exactly, for all those buffer-selecting optional arguments. A good interface I think is "map any prefix argument into a transient", which has good mnemonics. I do hope the transient docs get improved and some rich examples start appearing; the current docs are detailed but hard to put into actual practice. |
@jdtsmith I would love to see a consult-transient.el package in the consult repository, which adds transient interfaces to consult-x-multi and the consult-grep family of async commands. See also the consult wishlist and minad/consult#170 as a starting point. |
Is this a good argument for just temporarily marking the region for all commands (past present and future) which conclude an embark invocation? Or is that asking for trouble? |
@jdtsmith Yes, I think marking always is asking for trouble. I would prefer if Embark does not modify anything on its own without an explicit request. |
I wonder where the distinction between region and target should be now.
|
@minad said:
I'd say the
Basically: we should now use As for marking commands, we currently have two: Or, we could remove all marking commands on the grounds that instead of marking a target and then using some command that uses the region, people should just skip the marking and use that command directly as an action. |
Oh, we were writing at the same time, @minad. Putting the region commands under a prefix is an interesting idea. |
The idea is basically to unify regions and targets. Marking could still be available as an action, but it will be mostly unnecessary. You can always act directly. In order to avoid too much shadowing I would use the R prefix. Only for the region target itself the region map is directly the top-level map. |
If we want a general mark action, I'd reuse the (push #'embark--mark-target (alist-get 'mark embark-pre-action-hooks))
(define-key embark-general-map " " #'mark) |
It might be useful to have |
Yes and just to have a bridge to the outside of Embark. |
I thought about the exact same question and I am undecided 🤷 |
Let's try just the repeating |
Yes SPC is much better. I only proposed R for the region prefix map. |
OK, done: b20de98 This binds |
I guess this issue got a highjacked by using targets as regions. That part seems mostly finished, and I will add sentence and paragraphs targets tonight (I have to go out right now). I do have one further question: what actions differ from sentences to paragraphs? I think they should share almost all of them, except transpose-{sentences,paragraphs}. |
Did it really get hijacked given the title "marking target as region for certain commands"? It is probably a good idea to create separate issues for separate ideas 😬 |
The title was changed after the high-jacking! 😆 |
RE mixing issues: apologies, this thought sort of came out of nowhere. I'm definitely in favor of "just act directly" for the most useful region-based commands. Similar to how I can "just act directly" and drop right into consult-line, etc. With all of this mark and repeat business, I'm actually a bit worried about an inconsistent experience: if you get used to |
On the other hand, if you worry about embark "stealing the mark" without having been asked to do so, SPC makes more sense (esp. if the highlight face changes to indicate it). I guess a short user configurable list of commands which can "act directly on targets as if they were regions" might be a good compromise. |
Now we have a mix of both approaches. Some commands are available directly and some require you to mark first with spc. This makes sense since we would get too much keybinding shadowing if every region command is directly available with a top-level keybinding. Note that some users also expressed their preference to "hide" many of the general bindings. What we've got is a compromise. Either you act on the target or you press space first to switch to the region target. But region target and other targets are not automatically the same. |
This exists already (in an indirect form). It is the set of commands with embark--mark-target in their pre action hooks. |
One thing I should add - it probably makes sense to add embark--mark-target for every command acting on regions which is available as global binding. On top of that Embark can make more commands accessible via its region keymap. |
In particular I could see using |
Just to mention this, there is the obscure but sometimes useful command, |
We could have the highlight indicator not highlight region targets, so they get their normal face. |
While I see the appeal I also think it is misleading since then it is not obvious that you are embarking. |
I doubt anyone is using just the highlighting indicator, maybe the other indicators are enough. |
Off-topic, but I'm really enjoying putting point on the blank line after a defun and using |
So, @hmelman, you'd prefer we keep the defun target for text modes? Or at least for markdown-mode? (I was considering restricting it to modes derived from prog-mode.) |
I added the sentence and paragraph targets and actions (25ec9c3). Please let me know if any other actions would be good to bind. I made the motion and transpose actions repeatable (dragging stuff forward is super fun; dragging them backwards is, appropriately, a bit of a drag: I can't believe how quickly the default configuration is improving. This new indexed-by-actions format for the {pre,setup-post}-action hooks really encourages one to use them! |
I think I agree with @jdtsmith that we might as well configure lots and lots of region commands to mark the target, so that if someone uses them they aren't disappointed (the politely named "principle of least surprise"). So I added the ones easily accesible by keybinding:
|
I'm not sure, I can't say I personally use defuns in |
A target finder returns either nil if not applicable or the target it found. So it can check for the mode (or any other condition) before even looking for the target. For targets that are just |
Oh, each finder is responsible for checking if it works in the mode and all are in one global list. That wasn't the first arrangement that came to mind, but it does localize a prog-mode check for something like a defun finder. It's not as easy if you wanted to reorder finders for different modes, but maybe that's not important. Probably makes sense to just wait and see if any issue develop. expand-region has a lot of programming mode specific finders, e.g., for python it can mark statements as well as inside and outside strings (referring to including or excluding the delimiters). |
Since by default embark acts on any marked region, there's no reason not to use both expand-region and embark together. That said, it might be nice to have (optional) access to expand region capabilities after an embark is underway. In particular for reducing region and reset (so |
In text modes, it would be wonderful if repeated embark-act application toggled word/sentence/paragraph selection (and/or if
u
increased the scope in that manner).The text was updated successfully, but these errors were encountered: