jxq
1
作为org-roam重度用户,创建标题节点之后,标题后面就会跟着一个property drawer。这样org文件中就会增加很多的drawer,看起来非常的杂乱。因此开发了org-tidy这个包,通过overlay来隐藏这些drawer。让org-mode回归原本的清爽。
对比图如下:
已经放到melpa,欢迎大家体验。
(use-package org-tidy
:ensure t
:config
(add-hook 'org-mode-hook #'org-tidy-mode))
15 个赞
赞,我也分享一下我的轻量方案:
平时在 org-cycle
的时候用内置的机制完全折叠起来,需要编辑或查看的时候按 C-<TAB>
就能展开当前 entry 的 drawers.
代码:
;; src: https://stackoverflow.com/questions/17478260/completely-hide-the-properties-drawer-in-org-mode
(defun elemacs/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 (line-end-position) t)
(user-error msg))))))))))
;;;###autoload
(defun eli/org-expand-all ()
(interactive)
(org-fold-show-subtree)
(org-unlogged-message "ALL")
(setq org-cycle-subtree-status 'all))
(add-hook 'org-cycle-hook #'org-cycle-hide-drawers)
(advice-add 'org-cycle-hide-drawers :override #'elemacs/org-cycle-hide-drawers)
(advice-add 'org-insert-heading-respect-content :after #'eli/org-expand-all)
(define-key org-mode-map [C-tab] #'eli/org-expand-all)
效果:
3 个赞
在从org-agenda第一次跳转到我的org文件时有肉眼可见的卡顿,感觉性能还有待优化
jxq
5
org文件大概有多少行?如果是直接打开会有卡顿吗?
也就456行,16个各类drawer,可能因为有的drawer内部行数比较多吧。
平常在agenda里面按tab秒跳转,开启org-tidy的hook后第一次明显会卡一下
编辑:Windows的Emacs,30.0.50 preview版