Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight and space out tags in org-mode

I would like to change the way tags are displayed in the org-mode buffer from this:

* Headline                                                         :tag1:tag2:tag3:

to this:

* Headline tag1 tag2 tag3

So basically, the changes I'm looking for are:

  1. Start tags immediately after the headline.

  2. Hide the : characters

  3. Add a space in-between each tag, so that long lists of tags will wrap properly in visual line mode

  4. Remove default bold formatting of tags and add a highlight

So far, I've been able to change the font face and add a highlight by customizing the Org Tag property. As a temp/hack, I made the : characters invisible by turning on hi-lock-mode and then M-x highlight-phrase [RET] : [RET] org-hide [RET]. But this only hides the colon—it doesn't actually create a real space. So tags still won't wrap properly in visual line mode. Also, this hides all colons, everywhere, not just the ones that separate tags.

Perhaps another option is to add the space but leave the colon?

* Headline :tag1 :tag2 :tag3

I've been auditioning this with the solarized-light theme. Here's a screenshot:

enter image description here

Any ideas, comments? Thanks!

like image 845
Adam Avatar asked Oct 21 '25 00:10

Adam


1 Answers

As mentioned by @lawlist, the (setq org-tags-column 0) puts the tags immediately after headline.

To hide the colons associated with tags, I tried the approach suggested by @Tobias, by setting the display property of :. Putting this snippet in .emacs or init.el seems to work for me.

(font-lock-add-keywords 'org-mode
  '(("^\\*+ "
     ":" nil nil
     (0 (put-text-property (match-beginning 0) (match-end 0) 'display " ")))))

I was referring to the (matcher . anchored-highlighter) format of setting a Search-based Fontification:

  • the "^\\*+ " part first matches an org heading
  • the subsequent ":" searches for :
  • the next line replaces the matched : with a space, according to the doc on display specs that replaces the texts

A screenshot (note I didn't set org-tags-column 0 so it aligns right, and the font coloring are set by customize-face RET org-tag RET): enter image description here

like image 145
Jason Avatar answered Oct 24 '25 14:10

Jason