Here's a new version:

(defun find-wiki-by-tags (tags)
  (interactive "sEnter tags: ")
(shell-command (format "cd ~/org;  ack \"\\* tags.*(%s).*\" --all" tags) "mybuf")
(set-buffer "mybuf")
(beginning-of-buffer)
(ignore-errors
  (while (search-forward-regexp "\\(.*?\\):")
    (replace-match "[[~/org/\\1]]" )
    ))
(org-mode)
)

Problems:

1) It's slow, not sure where the bottleneck is (ack in itself is fast, I suppose the problem lies in elisp's side)
2) The regexp is not optmized, and I'm getting some trash, although it lists the files for me so it works well enough now.

- Marcelo.




On Mon, Dec 5, 2011 at 12:08 AM, Marcelo de Moraes Serpa <celoserpa@gmail.com> wrote:
Hi list!

I decided to finally get my hands dirty and build a small function to improve my org-based productivity system.

Let me explain:

I have a subdirectory under ~/org which has a bunch of files named after different subjects. Originally it was supposed to model a wiki, but in practice, I create a file there whenever I start studying a new (often complex) subject and that I know I will come back often and edit / improve. It's indeed like a wiki.

However, I don't keep those files in the agenda. It would slow it down a lot. To keep the organization as organic as possible, I simply use tags to bring them together semantically. So, I have other files with items that are tagged, say, business, and I have a "wiki file" with a headline like this:

* tags :business:

<contents>

I use the tags headline to tag those files.

Now, what I wanted was to get a list of files related to say, the business tag. It's quite useful to find myself in the (good) chaos of tagged "wiki files", I came up with a small elisp function that does just that!

(progn 
(shell-command "cd ~/org;  ack \"\\* tags.*(business).*\" --all" "mybuf")
(set-buffer "mybuf")
(beginning-of-buffer)
(ignore-errors
  (while (search-forward-regexp "\\(.*?\\):")
    (replace-match "[[~/org/\\1]]" )
    ))
(org-mode)
)

Bear in mind this is my first elisp program ever. It's not even a function yet, actually. But it works pretty well for what I want :)

Took me around 1 hour to bring it up.

The joy of breaking your head on something!

Cheers!

(Suggestions on how to improve it welcome!)

Marcelo.