3

I have lots and lots of headings in Org-mode. If I want to cut-and-paste several of them, or assign tags to multiple headings, I can only select a bunch of them with the contiguous region and do edits or apply org-map-entries. However, a situation arises sometimes when I want to do that to discontiguous headings, and then I have to repeat the manipulation multiple times. I'd prefer to mark each heading I need, and invoke the command only once (like it's typically done in GUI lists with ctrl/cmd-clicks).

Is there anything out there that implements this workflow, preferably tailored to Evil and/or Org-mode? Since I need to do various stuff like tagging, I'd like to just get the list of selected headings/lines with elisp, instead of having some limited end-user functionality.

I've looked at the various 'multiple cursor' packages, but those seem to be quite different to what I want. Seeing as I don't need to edit multiple regions simultaneously letter-by-letter, but need to apply the same cut-and-paste or Org commands to them. Even if I could only mark up the lines and then invoke some API from my code, that would be quite enough.

I could code my own thing, of course, but would like to know if anyone did the same previously.

3
  • Why couldn't you "apply the same cut-and-paste Org commands to them" using the multiple-cursors package? Applying the same command at multiple places is what that package is all about. Commented Dec 19, 2024 at 4:00
  • Or just use a keyboard macro. Commented Dec 19, 2024 at 4:00
  • 1
    Please modify your question to state exactly what you want. The discussion in the comments after my answer shows that the question needs more details to be answerable. Commented Dec 22, 2024 at 18:30

1 Answer 1

2

It's possible to do what you want with the agenda. If the file you are interested in is not already added to the agenda, you can add it temporarily with C-c [ (and eventually remove it from the agenda with C-c ]). Then you do an agenda search to limit the headlines you are going to consider, mark the ones that you really want to work on and apply a bulk command to all of the marked headlines. See the section Commands in the Agenda Buffer in the Org mode manual; in particular, see the Bulk remote editing selected entries subsection.

In more detail, list all the nodes of interest with an agenda search: C-c a or M-x org-agenda will get you to the agenda dispatcher. You can write your own agenda search if you want, but if you want to do it interactively, try m to do a tags/properties search and use +CATEGORY="foo" where foo.org is the name of the file you added above. That will list all the headlines in that file (assuming you have no other entries with category equal to foo - if you do, you can rename the file beforehand to something that will not clash with any category in your agenda)[1]. You can use a slightly more elaborate search to limit the number of entries, e.g. you can use +CATEGORY="foo"+LEVEL=1 for just the top-level headlines - see Matching Tags and Properties in the manual for the search syntax and some additional ideas.

Once you have the list, you can mark individual entries with m and then apply a bulk action with B. There are bulk action commands for simple things already: e.g. for adding or removing a tag, you say + or -, enter the tag you want and you are done. There are built-in functions to archive, add/remove tags, change TODO state, add/modify SCHEDULED/DEADLINE timestamps, refile and scatter[2].

The marks are cleared after the bulk command is done, unless you persist them: after the B, press p before whatever bulk command you want to run.

You can also implement your own bulk actions and add them to org-agenda-bulk-custom-functions but that's a matter for another question.


Footnotes

[1] You can also write your own custom agenda search command(s) and add it (them) to org-agenda-custom-commands for easy reuse - see Custom Agenda Views

[2] ... about which I know nothing: I think it allows you to scatter a set of tasks among a number of days, perhaps to equalize the load, but I've never used it.

6
  • That sounds good — except afaik the agenda displays headings in a flat list. This, and filtering for wanted headings, alas doesn't fit my particular case, because I have very branchy and sprawling outlines with thousands of entries. The headings I want are defined by their place in the tree, rather than searchable attributes. Plus, I may need to work on headings from different branches of the outline. As a result, even if it's possible to automate jumping from the outline to the agenda with chosen headings, I'm back to marking those headings first. Thanks for the info, though. Commented Dec 21, 2024 at 14:25
  • If you could be more precise about the criteria for the headings of interest, I could be more precise with a search; e.g. the place in the tree can be a searchable attribute. Commented Dec 21, 2024 at 19:15
  • BTW, in the question you say: I'd prefer to mark each heading I need, and invoke the command only once (like it's typically done in GUI lists with ctrl/cmd-clicks)., so that's what I described above (plus hints on limiting the number of entries shown). The better you describe your problem, the better the solution will be. Commented Dec 21, 2024 at 19:22
  • Well, generally I'm just looking for whether anyone has implemented the 'mark multiple lines/headings and get them programmatically' thing, since I may want to do various stuff with them that's not envisioned by the author. But, about "the place in the tree can be a searchable attribute" — how does that work? Commented Dec 22, 2024 at 16:58
  • You need to be clearer: mark multiple lines/heading is a manual process - you have to decide which ones to mark. Once you've marked them, then getting them programmatically is easy: that's what the B command does in the agenda. But previously you objected to marking those headings. So which is it? Commented Dec 22, 2024 at 18:25

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.