Skip to content

Instantly share code, notes, and snippets.

@lijigang
Created February 23, 2021 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lijigang/cbb9d052266eb6f050c4011f87fc232c to your computer and use it in GitHub Desktop.
Save lijigang/cbb9d052266eb6f050c4011f87fc232c to your computer and use it in GitHub Desktop.
hide orgmode headline's tags for a better look
;; 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