Emacs组织模式:我如何折叠除当前标题之外的所有内容?

时间:2014-08-06 13:33:28

标签: emacs org-mode

我使用org-mode来处理多个文件中的任务和项目。

在每周议程中,可以使用<TAB><RET>跳转到每个TODO条目的位置。如果目标文件先前未打开,则会加载一个光标,并将光标设置为正确的标题,展开整个文档,包括抽屉

我非常希望只看到稀疏的树,除了正确的标题折叠(子树可见性无关紧要)。

可以使用C-u <TAB循环全局可见性来折叠整个树,但我必须再次找到标题。

我知道我可以通过缩小缓冲区来隐藏其余部分,如下所述: Emacs, How can I display only current task and hide others in 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)))

3 个答案:

答案 0 :(得分:5)

这是基于实际问题编辑中的答案。

如果对任何人有帮助: 当我试图将上面的内容绑定到一个热键时,我不断收到错误,命令错误的参数有些东西......结果发现必须添加(交互式)标志才能使其正常工作。 以下是与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感谢编辑!

答案 1 :(得分:3)

我不确定这是否是你的要求(我只是认为它适合你的问题标题),但是我通过在org-mode的速度命令中绑定它们来使用这两个函数带来很多乐趣。您可以在org-mode hacks中找到这两个功能。我略微修改它们以达到我的目的。

这两个功能支持:

  1. 展开除当前标题外的所有其他标题
  2. 将当前标题移至屏幕顶部以获得更宽的阅读区域。
  3. 为了完成(2),你需要(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)))
    

    您可以使用jl将org-mode速度键与它们绑定,然后您可以使用jl来控制标题的折叠光标位于标题的开头。

    (setq org-speed-commands-user
          '(("j" . ded/org-show-next-heading-tidily)
            ("l" . ded/org-show-previous-heading-tidily))))
    

    非常适合阅读org-mode文件,欢呼!

答案 2 :(得分:0)

检查您的组织启动选项(customize-group&gt; org-startup),例如org-startup-foldedorg-agenda-inhibit-startup(其他人已经提到过这些选项)并设置选项以仅显示折叠视图。我们讨论了#+STARTUP等组织模式变量{。{3}}。

当您现在跳到议程时,您可能会注意到所有内容都已折叠,即使活动项目的父项可能也不可见。然后,您可以使用org-reveal C-c C-r根据here显示上下文(父母,子女,下一个兄弟)

相关问题