Completely hide the :PROPERTIES: drawer in org-mode

情到浓时终转凉″ 提交于 2019-11-28 17:57:29
lawlist

The following answer completely hides everything from :PROPERTIES: through :END:. It can be tested by evaluating (org-cycle-hide-drawers 'children), or (org-cycle-hide-drawers 'all), or in conjunction with the other functions relating to cycling the outline views. The standard functions to unfold that are included within the org-mode family all work -- e.g., show-all; org-show-subtree; etc.

(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))))))))))

For anyone who interested in tab cycling between all of the various views (including revealing what is inside the :PROPERTIES: drawer, there is an easy modification to org-cycle-internal-local by adding an additional condition before (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))

Screenshot -- Drawers Hidden:

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


Screenshot -- Drawers Visible:

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

That's simply not possible right now, at least not without (a lot of?) extra coding...

Problem is: how would you unhide it? Would you see "..." alone?

This allows you to toggle the properties of the header you're currently in.

(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))))))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!