From: Matt Lundin <mdl@imapmail.org>
To: Uriel Avalos <amscopub-mail@yahoo.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Generate list of all tags in use?
Date: Fri, 26 Nov 2010 00:01:57 -0500 [thread overview]
Message-ID: <87r5e8u18a.fsf@fastmail.fm> (raw)
In-Reply-To: <22895.1989477084$1290649103@news.gmane.org> (Uriel Avalos's message of "Wed, 24 Nov 2010 20:38:13 -0500")
Uriel Avalos <amscopub-mail@yahoo.com> 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
prev parent reply other threads:[~2010-11-26 5:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-25 1:38 Generate list of all tags in use? Uriel Avalos
2010-11-25 3:15 ` Richard Lawrence
2010-11-30 18:40 ` Uriel Avalos
2010-12-08 23:32 ` Matt Lundin
2010-12-11 14:04 ` Uriel Avalos
2010-11-26 5:01 ` Matt Lundin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r5e8u18a.fsf@fastmail.fm \
--to=mdl@imapmail.org \
--cc=amscopub-mail@yahoo.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.