Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerate all tags in org-mode

Tags:

org-mode

How do I generate an enumerated list of all tags (e.g., :tag:) in an org-mode file? Say I have a list of the form:

* Head1        :foo:bar:
** Subhead1    :foo:
* Head2
** Subhead2    :foo:bar:

I want to generate a list of all tags in this file as well as how many times each tag was used. Say something like,

:foo:    3
:bar:    2  
like image 311
Chernoff Avatar asked Jun 20 '14 15:06

Chernoff


People also ask

How do you use tags in Org mode?

Org mode has extensive support for tags. Every headline can contain a list of tags; they occur at the end of the headline. Tags are normal words containing letters, numbers, ' _ ', and ' @ '. Tags must be preceded and followed by a single colon, e.g., ' :work: '.

How do you write org mode?

To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores. MY PROJECT is the title of the document, this can be anything. This will enable Org mode for this document, no matter what the file-ending is.

What can Org mode do?

Org Mode offers the ability to insert source code in the document being edited, which is automatically exported and/or executed when exporting the document; the result(s) produced by this code can be automatically fetched back in the resulting output.

How do I use tags in Emacs?

' ( 'find-tag' ) – find a tag, that is, use the Tags file to look up a definition. If there are multiple tags in the project with the same name, use ` C-u M-. ' to go to the next match. 'M-x find-tag-other-window' – selects the buffer containing the tag's definition in another window, and move point there.


1 Answers

Here is a shorter version.

(defun get-tag-counts ()
  (let ((all-tags '()))
    (org-map-entries
     (lambda ()
       (let ((tag-string (car (last (org-heading-components)))))
     (when tag-string   
       (setq all-tags
         (append all-tags (split-string tag-string ":" t)))))))


    ;; now get counts
    (loop for tag in (-uniq all-tags) 
      collect (cons tag (cl-count tag all-tags :test 'string=)))))
like image 180
John Kitchin Avatar answered Oct 01 '22 20:10

John Kitchin