From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Lundin Subject: Re: Generate list of all tags in use? Date: Fri, 26 Nov 2010 00:01:57 -0500 Message-ID: <87r5e8u18a.fsf@fastmail.fm> References: <22895.1989477084$1290649103@news.gmane.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=48139 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLqRk-0007Ky-OA for emacs-orgmode@gnu.org; Fri, 26 Nov 2010 00:02:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLqRd-0003nF-KV for emacs-orgmode@gnu.org; Fri, 26 Nov 2010 00:02:08 -0500 Received: from out3.smtp.messagingengine.com ([66.111.4.27]:50203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PLqRd-0003ms-If for emacs-orgmode@gnu.org; Fri, 26 Nov 2010 00:02:01 -0500 In-Reply-To: <22895.1989477084$1290649103@news.gmane.org> (Uriel Avalos's message of "Wed, 24 Nov 2010 20:38:13 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Uriel Avalos Cc: emacs-orgmode@gnu.org Uriel Avalos 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