簡體   English   中英

Emacs org-mode:除了當前標題,我如何折疊所有內容?

[英]Emacs org-mode: How can i fold everything but the current headline?

我使用 org-mode 在多個文件中處理我的任務和項目。

在每周議程中,可以使用<TAB><RET>跳轉到每個 TODO 條目的位置。 如果目標文件之前未打開,則會加載它並將 cursor 設置為正確的標題,並展開整個文檔,包括抽屜

我非常希望只看到一個稀疏樹,除了正確的標題折疊(子樹可見性無關緊要)之外的所有內容。

可以通過使用Cu <TAB循環全局可見性來折疊整個樹,但是我必須再次找到標題。

我知道我可以通過縮小緩沖區來隱藏 rest,如下所述: Emacs,如何僅顯示當前任務並在 org 模式下隱藏其他任務? 但后來我失去了上下文(父標題,輕松訪問兄弟姐妹)並且抽屜仍然打開。

理想情況下,我想要一個顯示以下內容的命令:

  • 頂級標題
  • 當前的標題,以及最高級別的所有父項
  • 當前頭條的孩子們

編輯:

發布的函數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感謝您的編輯!

我不太確定這是否是你的要求(我只是認為它適合你的問題標題),但我通過在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 ,那么你可以使用jl來控制標題的折疊當你的光標在標題的開始。

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

它非常適合閱讀組織模式文件,歡呼!

檢查您的組織啟動選項( customize-group > org-startup ),如org-startup-foldedorg-agenda-inhibit-startup (其他人已經提到過這些)並設置選項以僅顯示折疊視圖。 這里討論像#+STARTUP這樣的組織模式變量。

當您現在跳到議程時,您可能會注意到所有內容都已折疊,即使活動項目的父項可能也不可見。 然后,您可以使用org-revealCc Cr根據手冊org-reveal 上下文 (父母,孩子,下一個兄弟)

當前 (2022) emacs 不再需要精心設置來實現問題中所述的目標:

  • 頂級標題
  • 當前的標題,以及最高級別的所有父項
  • 當前頭條的孩子們

在當前的 Emacs 和 org-mode 版本(Emacs 27.1,截至 2022 年 8 月)中,您可以按Shift-Tab Tab關閉所有標題,然后打開當前標題。 至關重要的是,cursor 仍保留在當前折疊的標題上,因此Tab重新打開它。

我從默認安裝中獲得的唯一顯着變化是 Evil,它可能會或可能不會影響 cursor 保持在折疊標題上的事實。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM