Created
February 23, 2021 05:18
-
-
Save lijigang/cbb9d052266eb6f050c4011f87fc232c to your computer and use it in GitHub Desktop.
hide orgmode headline's tags for a better look
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Hide tags | |
(defun org-toggle-tag-visibility (state) | |
"Run in `org-cycle-hook'." | |
(message "%s" state) | |
(cond | |
;; global cycling | |
((memq state '(overview contents showall)) | |
(org-map-entries | |
(lambda () | |
(let ((tagstring (nth 5 (org-heading-components))) | |
start end) | |
(when tagstring | |
(save-excursion | |
(beginning-of-line) | |
(re-search-forward tagstring) | |
(setq start (match-beginning 0) | |
end (match-end 0))) | |
(cond | |
((memq state '(overview contents)) | |
(outline-flag-region start end t)) | |
(t | |
(outline-flag-region start end nil)))))))) | |
;; local cycling | |
((memq state '(folded children subtree)) | |
(save-restriction | |
(org-narrow-to-subtree) | |
(org-map-entries | |
(lambda () | |
(let ((tagstring (nth 5 (org-heading-components))) | |
start end) | |
(when tagstring | |
(save-excursion | |
(beginning-of-line) | |
(re-search-forward tagstring) | |
(setq start (match-beginning 0) | |
end (match-end 0))) | |
(cond | |
((memq state '(folded children)) | |
(outline-flag-region start end t)) | |
(t | |
(outline-flag-region start end nil))))))))))) | |
(add-hook 'org-cycle-hook 'org-toggle-tag-visibility) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment