【问题标题】:Emacs org-mode: How can i fold everything but the current headline?Emacs org-mode:我如何折叠除当前标题之外的所有内容?
【发布时间】:2014-08-06 13:33:27
【问题描述】:

我使用 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)))

【问题讨论】:

  • 不是一个完整的答案,但请查看以下变量,看看它们是否适合您的需求:org-startup-foldedorg-startup-optionsorg-agenda-inhibit-startup
  • 使用org-agenda-inhibit-startup 切换它几乎可以满足我的要求,谢谢!奇怪的是,标题的兄弟节点被隐藏了,只显示了第一个子节点,但这绝对是一个改进!
  • 在不修改源代码的情况下,折叠的选项数量有限——手册只有少数交互式命令:gnu.org/software/emacs/manual/html_node/org/… 缩小可见范围的另一个选项是执行标签或关键字搜索:orgmode.org/worg/org-tutorials/advanced-searching.html 成功修改源代码以创建自定义视图的乐趣是持久的,但如果您真正感兴趣的话,请准备好花费大量时间。
  • 这非常有用,但它隐藏了上下文。我想显示当前任务的所有祖先,它们的属性(折叠,但显示),以及兄弟姐妹。这可能吗?

标签: emacs org-mode


【解决方案1】:

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

如果对任何人有帮助: 当我尝试将上述内容绑定到热键时,我不断收到错误,commandp wrong argument something something ... 结果证明必须添加(交互式)标志才能使其工作。 下面是绑定到 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 感谢编辑!

【讨论】:

  • 这几乎对我有用 - 我发现上一级的兄弟姐妹不可见,必须通过C-u C-c C-r 显示所有内容。我确认M-: (org-reveal t) 什么都不做,所以它显然与C-u C-c C-r 不一样。使用this 的想法,我替换为(let ((current-prefix-arg '(4))) (call-interactively 'org-reveal)),这样就可以了。
  • 由于该函数在 org 缓冲区之外没有意义,我将 global-set-key 替换为本地键绑定:(add-hook 'org-mode-hook (lambda () (local-set-key "\M-=" 'org-show-current-heading-tidily)))。请注意,您需要重新加载 org 文件才能使其生效。
【解决方案2】:

我不太确定这是否是您的需求(我只是认为它适合您的问题标题),但是通过将它们绑定在 org-mode 的速度命令中,我非常高兴地使用这两个功能。您可以在org-mode hacks 中找到这两个函数。我稍微修改了它们以满足我的目的。

两个功能支持:

  1. 展开除当前标题之外的所有其他标题
  2. 将当前标题移至屏幕顶部以扩大阅读区域。

为了完成(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 speed 键将它们绑定,然后您可以使用jl 来控制光标在标题开头时的折叠。

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

非常适合阅读 org-mode 文件,干杯!

【讨论】:

  • 通过简单地将 (outline-next-heading) 替换为 (outline-back-to-heading),我设法让第一个函数做我想做的事。速度键和 org-hacks 也很有趣,谢谢!
【解决方案3】:

检查您的组织启动选项 (customize-group > org-startup),例如 org-startup-foldedorg-agenda-inhibit-startup(其他人已经提到过这些)并将选项设置为仅显示折叠视图。像#+STARTUP 这样的组织模式变量在here 中讨论。

当您现在跳转到议程时,您可能会注意到所有内容都已折叠,甚至可能看不到活动项目的父项。然后,您可以使用org-revealC-c C-r 根据manual)使 上下文(父母、孩子、下一个兄弟姐妹)可见

【讨论】:

  • 万岁!我和 OP 有同样的问题,与被接受的答案相比,你的答案非常简单。在我看来,这应该是公认的答案@patrick-b
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-12
  • 2013-07-11
  • 2011-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多