【问题标题】:Completely hide the :PROPERTIES: drawer in org-mode在 org-mode 中完全隐藏 :PROPERTIES: 抽屉
【发布时间】:2013-07-02 22:18:54
【问题描述】:

有人可以帮我完全隐藏:PROPERTIES: 抽屉,包括:PROPERTIES: 的行。

* TASKS (with deadines)

    ** Next Action [#A] Ask the geniuses how to do this.  :lawlist:
       DEADLINE: <2013-07-04 Thu >
         :PROPERTIES:
         :ToodledoID: 330686790
         :ToodledoFolder: TASKS
         :Hash:     afa88f17317bbe2ce0ce661333cdcfb4
         :END:
       This line is for notes, which appears underneath the properties drawer.

* UNDATED (without deadlines)

    ** Someday [#A] Close but no cigar -- keep trying.  :lawlist:
          :PROPERTIES:
          :ToodledoID: 330686680
          :ToodledoFolder: TASKS
          :Hash:     eb0b8d360b5b1453dd66ed0c5698e135
          :END:
       This line is for notes, which appears underneath the properties drawer.

我没有通过谷歌搜索看到此功能,因此我猜测需要一些特殊的代码行才能使此功能请求成为现实。 [换句话说,我不认为这是一个超级用户的问题,因为这需要用一些特殊的代码来发明。]

【问题讨论】:

    标签: emacs org-mode


    【解决方案1】:

    以下答案完全隐藏了从:PROPERTIES::END: 的所有内容。可以通过评估(org-cycle-hide-drawers 'children)(org-cycle-hide-drawers 'all) 或结合与循环大纲视图相关的其他功能进行测试。 org-mode 系列中包含的标准展开功能都可以工作——例如,show-allorg-show-subtree;等等

    (require 'org)
    
    (defun org-cycle-hide-drawers (state)
      "Re-hide all drawers after a visibility state change."
      (when (and (derived-mode-p 'org-mode)
                 (not (memq state '(overview folded contents))))
        (save-excursion
          (let* ((globalp (memq state '(contents all)))
                 (beg (if globalp
                        (point-min)
                        (point)))
                 (end (if globalp
                        (point-max)
                        (if (eq state 'children)
                          (save-excursion
                            (outline-next-heading)
                            (point))
                          (org-end-of-subtree t)))))
            (goto-char beg)
            (while (re-search-forward org-drawer-regexp end t)
              (save-excursion
                (beginning-of-line 1)
                (when (looking-at org-drawer-regexp)
                  (let* ((start (1- (match-beginning 0)))
                         (limit
                           (save-excursion
                             (outline-next-heading)
                               (point)))
                         (msg (format
                                (concat
                                  "org-cycle-hide-drawers:  "
                                  "`:END:`"
                                  " line missing at position %s")
                                (1+ start))))
                    (if (re-search-forward "^[ \t]*:END:" limit t)
                      (outline-flag-region start (point-at-eol) t)
                      (user-error msg))))))))))
    

    对于任何对在所有不同视图之间循环选项卡感兴趣的人(包括揭示:PROPERTIES: 抽屉内的内容,可以通过添加附加条件之前轻松修改org-cycle-internal-local (t ;; Default action: hide the subtree. . . .

    ((eq org-cycle-subtree-status 'subtree)
      (org-show-subtree)
      (org-unlogged-message "ALL")
      (setq org-cycle-subtree-status 'all))
    

    屏幕截图——隐藏的抽屉:

    https://www.lawlist.com/images/org_mode_properties_a.png


    屏幕截图 -- 抽屉可见:

    https://www.lawlist.com/images/org_mode_properties_b.png

    【讨论】:

    • 为什么不顺便把它送到上游呢?
    • @Michaël -- 仅供参考:提议的功能已被org-mode 包的维护者拒绝,我不想尝试说服他添加此功能,因为上面的答案是足以满足我现在的需要。 [“谢谢你的建议。但是,我认为对用户完全隐藏东西并不是很好。你将如何编辑它,甚至知道那里有属性?你可以写“:properties:”而不是“:PROPERTIES: “,用一张合适的脸把它们变暗……”] 我依稀记得几年前有一个类似的回复,但找不到旧电子邮件。
    • 快速提问,以防有人仍在关注此问题。在org-mode 中已经有一个名为org-cycle-hide-drawers 的函数。但据我所知,它与上面定义的函数不同。更新答案以使用新的函数名称是否有意义?还是有意替换内置函数?
    • @apc -- 答案认为用户将 替换 old 内置函数为 new在上面的答案中起作用。通过使用 same 作为内置函数的名称,new 函数有效地取代了 old 内置函数。以防万一 old 内置函数尚未加载/读取,上面这个答案的第一行会强制加载整个库,以便 new 函数可以代替 old 内置函数。
    【解决方案2】:

    现在这根本不可能,至少在没有(很多?)额外编码的情况下是不可能的......

    问题是:你将如何取消隐藏它?你会单独看到“...”吗?

    【讨论】:

    • 必须有一个简单的解决方案,例如重新搜索转发,并为从 :PROPERTIES: 开始到并包括单词 :END: 的每一行从缓冲区的顶部到底部进行保存偏移点击code fold 按钮,使其在上一行下方折叠起来。然后unfold everything button 显示所有内容,然后从那里返回到骑自行车。
    • 锦上添花的是第一行末尾的倒三角形,表示代码折叠。 :)
    • 现在有一个成熟的解决方案 -- :)
    • @american-ninja-warrior -- 抱歉延迟回复。我看到至少有另一个人和你有同样的询问(基于对你问题的支持)。据我所知,此线程中接受的答案包含一个成熟的解决方案——我从 2013 年到现在一直在使用该解决方案。
    【解决方案3】:

    这允许您切换当前所在标题的属性。

    (defun org-toggle-properties ()
      ;; toggle visibility of properties in current header if it exists
      (save-excursion
        (when (not (org-at-heading-p))
          (org-previous-visible-heading 1))
        (when (org-header-property-p)
          (let* ((a (re-search-forward "\n\\:" nil t)))
            (if (outline-invisible-p (point))
                (outline-show-entry)
              (org-cycle-hide-drawers 'all))))))
    

    【讨论】:

    • 问题的调用寻求一种完全隐藏:PROPERTIES:抽屉的方法——包括表示:PROPERTIES:的行。此外,截至 2018 年 9 月 23 日,可通过克隆获得的最新版 org-mode 中不存在函数 org-header-property-pgit clone https://code.orgmode.org/bzg/org-mode.git。在我也 grep 的 org-mode 的一些先前版本中不存在该功能。由于缺少组件,我无法测试该功能,我不知道是否还有其他问题。另外,谷歌找不到org-header-property-p
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2021-06-06
    相关资源
    最近更新 更多