1

Can anyone think of a way to hide org-mode tags, perhaps something along the lines of this solution to completely hide the properties drawer?

I would love to hide tags but still have them searchable and be able to make them visible through cycling.

Ideas?

  • I can think of two options off the top of my head: (1) attach a function to the org-agenda-finalize-hook that goes through the near final product and redacts it using a regexp \\(:[[:alnum:]_@#%:]+:\\); or, (2), modify org-agenda-format-item to structure the data before it gets inserted into the buffer. No one, except me, likes to modify the source . . . so option two only applies to the very brave or stubborn souls. I don't know of any adverse consequences to either approach off the top of my head, but it may behoove you to wait for someone like .. [insert name if I can think of it]. – lawlist Apr 9 '17 at 6:47
  • Thanks. Was hoping to find a solution that works in the plain org-mode buffer (the outline view, not the agenda view)... maybe I'm not referring to this correctly? – Adam Apr 9 '17 at 6:50
  • Ah, that makes a big difference then . . . thank you for the clarification. – lawlist Apr 9 '17 at 6:51
  • One idea would be to modify the whopper of org-set-font-lock-defaults, somewhere after all the faces are applied, to create a semi-permanent hiding of tags. Absent additional details regarding how a potential toggle would work in the context of this question, I am unable to comment on that approach (even though I wrote up the solution in the linked thread). Please give some thought as to what circumstances would trigger toggling on and off, including, but not limited to, how far and wide spread the toggle is -- e.g., just the subtree or the whole buffer in one-fell swoop. – lawlist Apr 9 '17 at 6:59
  • Thanks, I'll check into org-set-font-lock-defaults. I was thinking about adding the setting to org-mode's visibility cycling to toggle tag hiding on/off... – Adam Apr 9 '17 at 7:10
4

Here is one approach to hide tags in folded view, and show them in any expanded view.

(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)
  • Hey John - thanks! It looks like this only works on the current line (where the cursor is). Is there a way to apply this to the buffer globally? So if you have a buffer with say 20 level 1 headers and you shift-tab to fold all of them, then all the tags hide at once? – Adam Apr 10 '17 at 14:54
  • Sure. I edited the answer to do that. – John Kitchin Apr 10 '17 at 17:41
  • Thanks John. I'm still just able to hide tags one heading at a time... (e.g., global cycling via shift-tab does not hide all tags...?) – Adam Apr 10 '17 at 18:24
  • That isn't what I see. When I shift tab and everything collapses, the tags disappear. Subsequent shift-tabs make them reappear. – John Kitchin Apr 10 '17 at 18:37
  • Ah okay! So it works great if all headings are top-level (eg * Heading one, * Heading two, etc.). But if you have say a main heading, eg (* Notes) and then sub-headings (** Note one, ** Note two,..., ** Note N) this breaks the script. – Adam Apr 10 '17 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.