[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Orgmode] Re: Generate list of all tags in use?
From: |
Matt Lundin |
Subject: |
[Orgmode] Re: Generate list of all tags in use? |
Date: |
Fri, 26 Nov 2010 00:01:57 -0500 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
Uriel Avalos <address@hidden> writes:
> Is there a way to generate a list of all tags in use in all agenda files?
Yes. Please see the documentation for the function
org-global-tags-completion-table, as suggested in the other recent
thread on this topic:
http://permalink.gmane.org/gmane.emacs.orgmode/33995
The function above returns a list suitable for use with, say,
completing-read.
> I'm thinking of something like a tag cloud.
Could you please clarify in which context you'd like this list generated
(in a buffer, as a list returned to another function, etc.)?
The following expression will return a list of strings (without text
properties) containing all the tags in your agenda files:
--8<---------------cut here---------------start------------->8---
(mapcar (lambda (tag)
(substring-no-properties (car tag)))
(org-global-tags-completion-table))
--8<---------------cut here---------------end--------------->8---
If you'd like to insert an alphabetical list of tags in an org buffer,
you could evaluate a source block such as the following:
--8<---------------cut here---------------start------------->8---
#+begin_src emacs-lisp
(mapconcat 'identity
(sort (mapcar
(lambda (tag)
(substring-no-properties (car tag)))
(org-global-tags-completion-table))
'string<)
"\n")
#+end_src
--8<---------------cut here---------------end--------------->8---
Finally, you could write a function (or, say, a quick perl script) to
find all tags in your org files, sort them by the number of times they
appear, and spit out the results. I use the following:
--8<---------------cut here---------------start------------->8---
#!/usr/bin/perl
use strict;
use warnings;
my %tags;
while (<>) {
next unless (/^\*+\s/);
if (/\s:([\w:]+):\s/) {
for my $tag (split(/:/, $1)) {
$tags{$tag} += 1;
}
}
}
for my $tag (sort {$tags{$b} <=> $tags{$a}} keys %tags) {
print "$tag ($tags{$tag})\n";
}
--8<---------------cut here---------------end--------------->8---
Save this script and name orgtags.pl or the like. Then simply run
orgtags.pl on the desired org files:
% perl orgtags.pl ~/org/*.org
And you should receive a listing of tags that looks like this:
home (185)
email (93)
read (75)
think (73)
errands (62)
phone (59)
CONTACT (49)
ATTACH (45)
yard (37)
desk (36)
BIB (34)
NEXT (28)
...
[snip]
Obviously, you could do a lot more, but this is an example of a "quick
and dirty" tag cloud.
HTH,
Matt