我使用org-mode来处理多个文件中的任务和项目.
在每周议程中,可以使用<TAB>或跳转到每个TODO条目的位置<RET>.如果目标文件先前未打开,则会加载它,并将光标设置为正确的标题并展开整个文档,包括抽屉.
我非常希望看到只有稀疏的树,除了正确的标题折叠(子树可见性无关紧要).
可以通过使用循环全局可见性来折叠整个树C-u <TAB,但是我必须再次找到标题.
我知道我可以通过缩小缓冲区来隐藏其余部分,如下所述: Emacs,如何只显示当前任务并在org-mode中隐藏其他任务? 但后来我放松了上下文(父母标题,轻松访问兄弟姐妹),抽屉仍然打开.
理想情况下,我希望有一个显示以下内容的命令:
编辑:
user3173715发布的功能略有修改版似乎可以解决问题:
(defun org-show-current-heading-tidily ()
"Show next entry, keeping other entries closed."
(if (save-excursion (end-of-line) (outline-invisible-p))
(progn (org-show-entry) (show-children))
(outline-back-to-heading)
(unless (and (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(show-children)))
Run Code Online (Sandbox Code Playgroud)
- 顶级标题
- 当前的头条新闻,以及所有高层家长
- 当前头条的孩子们
在当前的 Emacs 和 org-mode 版本(Emacs 27.1,截至 2022 年 8 月)中,您可以按Shift-Tab Tab关闭所有标题,然后打开当前标题。至关重要的是,光标保留在当前折叠的标题上,因此Tab可以重新打开它。
我对默认安装的唯一重大更改是 Evil,这可能会也可能不会影响光标保留在折叠标题上的事实。
这是基于实际问题中编辑的答案.
如果对任何人有帮助:当我尝试将上面的内容绑定到一个热键时,我不断收到错误,命令错误的参数有些东西......结果发现必须添加(交互式)标志才能使其正常工作.下面是与M- =相关的函数示例
(defun org-show-current-heading-tidily ()
(interactive) ;Inteactive
"Show next entry, keeping other entries closed."
(if (save-excursion (end-of-line) (outline-invisible-p))
(progn (org-show-entry) (show-children))
(outline-back-to-heading)
(unless (and (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(show-children)))
(global-set-key "\M-=" 'org-show-current-heading-tidily)
Run Code Online (Sandbox Code Playgroud)
@ Patrick.B感谢您的编辑!