Banish unmatched top-level trees when performing tag search in Emacs Org Mode

守給你的承諾、 提交于 2021-02-07 19:17:10

问题


For the past year and a half, I've maintained a monolithic buffer in Org Mode for my engineering notes with my current employer. Despite containing mostly pointers to other documents, this file has become quite large by human standards (48,290 lines of text), while remaining trivially searchable and editable through programmatic means (read: grep and Org Mode tag search).

One thing bothers me, though. When I perform a tag search using Org Mode 6.33x, Org's sparse tree view retains the folded representation of unmatched trees within the buffer (that is, content preceded by a single asterisk, *). This is generally useful for smaller buffers or those better organized into a single tree with multiple branches. However, this doesn't work especially well for documentation where each new tree is generated chronologically, one for each day, as I've been doing.

.

Before I continue, I'll note that my workaround is inherent in what I've just asked, as are the obvious alterations in my documentation habits with this buffer. However, the following questions remain:

1) Why does Org Mode organize trees in this manner when performing sparse tag searching? The technical details are self-evident, the UX decisions less so.

2) If I wished to correct this issue with a script written in Emacs Lisp, what hooks and commands should I explore in more detail to restructure the document view? Writing overrides for the standard commands (for example, org-match-sparse-tree) is already self-evident.

.

Thank you in advance.


回答1:


As you already noticed the problem only affects the top level headings. The good thing is that in org-mode you can demote easily all headings with simple keystrokes. This way you can avoid the problem. Also cleaning up afterwards are just some simple keystrokes.

Step-by-step instructions:

  • Mark the full buffer
  • Call M-right (for outline-demote)
  • Input * root\n at the beginning of the file
  • Now, build up your subtree and do what you want with it.
  • When done you can remove * root\n at the beginning of the file and promote the headings again with M-left

I have got the impression that you can even leave the overall-heading where it is for your application.



来源:https://stackoverflow.com/questions/7602787/banish-unmatched-top-level-trees-when-performing-tag-search-in-emacs-org-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!