When we add tags to a headline, they just get appended. For instance,
* Head 1 :A:C:B:
* Head 2 :B:A:C:
Is there a way I can sort these tags so we get:
* Head 1 :A:B:C:
* Head 2 :A:B:C:
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityWhen we add tags to a headline, they just get appended. For instance,
* Head 1 :A:C:B:
* Head 2 :B:A:C:
Is there a way I can sort these tags so we get:
* Head 1 :A:B:C:
* Head 2 :A:B:C:
You can sort tags alphabetically using:
(setq org-tags-sort-function 'org-string-collate-lessp)
Documentation: When set, tags are sorted using this function as a comparator.
I don't think it's already in Org.
What about
(defun my-org-sort-tags ()
"On a heading sort the tags."
(interactive)
(when (org-at-heading-p)
(org-set-tags (sort (org-get-tags) #'string<))))
for a start?
Activate with
M-x my-org-sort-tags