我使用组织模式来处理多个文件中的任务和项目。
在每周议程中,可以使用
<TAB>
或 <RET>
跳转到每个 TODO 条目的位置。如果目标文件之前未打开,则会加载该文件,并将光标设置到正确的标题,并且整个文档展开,包括抽屉。
我非常希望只看到一棵稀疏的树,其中包含所有内容,但折叠了正确的标题(子树可见性并不重要)。
可以通过使用
C-u <TAB
循环全局可见性来折叠整个树,但随后我必须再次找到标题。
我知道我可以通过缩小缓冲区来隐藏其余部分,如下所述: Emacs,如何在组织模式下仅显示当前任务并隐藏其他任务? 但随后我失去了上下文(父标题,轻松访问兄弟姐妹)并且抽屉仍然打开。
理想情况下,我希望有一个显示以下内容的命令:
编辑:
发布的函数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)))
这是基于实际问题编辑中的答案。
如果对任何人有帮助: 当我尝试将上面的内容绑定到热键时,我不断收到错误,命令错误的参数某事......事实证明必须添加(交互式)标志才能使其工作。 下面是与 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)
@Patrick.B 感谢您的编辑!
在当前的 Emacs 和 org-mode 版本(Emacs 27.1,截至 2022 年 8 月)中,您可以按顶级标题
- 当前的头条新闻,以及所有家长的高层
- 当前头条的孩子们
Shift-Tab Tab 关闭所有标题,然后打开当前标题。至关重要的是,光标保留在当前折叠的标题上,因此 Tab 可以重新打开它。
默认安装中唯一显着的变化是 Evil,这可能会也可能不会影响光标保留在折叠标题上的事实。
org-mode hacks 中找到这两个函数。我稍微修改了它们以满足我的目的。
两个功能支持:
(setq recenter-positions '(top bottom))
,可能有一些更好的解决方案,但我没有深入研究。
(defun ded/org-show-next-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-next-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)
(recenter-top-bottom)
(show-children)
(recenter-top-bottom)))
(defun ded/org-show-previous-heading-tidily ()
"Show previous entry, keeping other entries closed."
(let ((pos (point)))
(outline-previous-heading)
(unless (and (< (point) pos) (bolp) (org-on-heading-p))
(goto-char pos)
(hide-subtree)
(error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(recenter-top-bottom)
(show-children)
(recenter-top-bottom)))
并且您可以使用 org-mode 快捷键与
j
和
l
绑定它们,然后当光标位于标题开头时,您可以使用
j
和
l
来控制标题的折叠。
(setq org-speed-commands-user
'(("j" . ded/org-show-next-heading-tidily)
("l" . ded/org-show-previous-heading-tidily))))
它非常适合读取组织模式文件,干杯!
(save-excursion (outline-hide-other) (org-reveal))
应该足够了,但是 org-reveal 不显示上部打开的标题的文本正文。(org-reveal) 中有奇怪的参数,需要传递 '(4),不知道为什么。
对于组织模式:
(defun my/org-fold-hide-other ()
"Hide other headers and reveal current and don't hide headers and text in opened ones."
(interactive)
(save-excursion
(org-overview) ;; hide others
(org-reveal '(4))) ;; reveal current place appropriate)
(add-hook 'org-mode-hook (lambda ()
(local-set-key (kbd "C-c e") 'my/org-fold-hide-other))
对于轮廓模式:
(defun my/outline-hide-other ()
"Hide other headers and don't hide headers and text in opened ones.
like (outline-hide-other)"
(interactive)
(save-excursion
(outline-hide-sublevels 1) ;; hide all, set level to required!
(outline-show-children) ;; show headers, not shure how and wehere,
(outline-back-to-heading t) ;; to header in depths
(outline-show-entry) ;; show local text
(outline-up-heading 1 t) ;; go upper
(while ( > (funcall outline-level) 1) ;; while not at first header
(outline-show-entry)
(outline-show-children) ;; show subheaders
(outline-up-heading 1 t) ;; go upper
)))
(add-hook 'outline-mode-hook (lambda ()
(local-set-key (kbd "C-c e") 'my/outline-hide-other))