Skip to content

Instantly share code, notes, and snippets.

@alexispurslane
Created February 6, 2025 20:53
Show Gist options
  • Save alexispurslane/56e3085bffd511facfbb708c58a23334 to your computer and use it in GitHub Desktop.
Save alexispurslane/56e3085bffd511facfbb708c58a23334 to your computer and use it in GitHub Desktop.
sort org mode headings by tags
(defun org-sort-by-tags ()
(interactive)
(org-sort-entries nil ?f
(lambda () (org-get-tags (point)))
(lambda (a b)
(let ((a (if (listp (cdr a))
a
(buffer-substring (car a) (cdr a))))
(b (if (listp (cdr b))
b
(buffer-substring (car b) (cdr b)))))
(last (cl-loop for tag-a in a
for tag-b in b
while (not (or (string> tag-a tag-b)
(string< tag-a tag-b)))
collect (string< tag-a tag-b)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment