简体   繁体   中英

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 Mx 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:

在此处输入图片说明

Any ideas, comments? Thanks!

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 ): 在此处输入图片说明

What you ask for could be solved if:

  • there was a face org-tag-separator (for example) just for the ":" symbol,
  • you customized that face to have its foreground equal to your background.

To ask on the Org ML?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM