emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [OT] The joy of elisp
@ 2011-12-05  6:08 Marcelo de Moraes Serpa
  2011-12-05 17:34 ` Marcelo de Moraes Serpa
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo de Moraes Serpa @ 2011-12-05  6:08 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1576 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 2153 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [OT] The joy of elisp
  2011-12-05  6:08 [OT] The joy of elisp Marcelo de Moraes Serpa
@ 2011-12-05 17:34 ` Marcelo de Moraes Serpa
  2011-12-06 14:27   ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Marcelo de Moraes Serpa @ 2011-12-05 17:34 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 2351 bytes --]

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.
>

[-- Attachment #2: Type: text/html, Size: 3489 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [OT] The joy of elisp
  2011-12-05 17:34 ` Marcelo de Moraes Serpa
@ 2011-12-06 14:27   ` Eric Schulte
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2011-12-06 14:27 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: Org Mode

Marcelo de Moraes Serpa <celoserpa@gmail.com> writes:

> 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)

A pure elisp implementation would likely be faster, maybe something like
the following would work as an improvement

(defun org-files ()
  "Return a list of the files in the \"~/org/\" directory."
  (directory-files "~/org/" nil ".*.org$"))

(defun collect-links (tag)
  "Collect links in \"~/org/\" including TAG."
  (save-window-excursion           ; save the current buffer and point
    (let ((rx (format "^\\* tags.*%s" tag)) ; build a regexp for the given tag
          links)                            ; hold collected links
      (dolist (file (org-files)) ; for all files returned by `org-files'
        (find-file (expand-file-name file "~/org/"))  ; in this file
        (save-excursion
          (goto-char (point-min))       ; go to the beginning of the file
          (while (re-search-forward rx nil t) ; search for matches
            (push (org-store-link nil) links)))) ; save a link to the match
      links)))                          ; return the collected links

(defun find-wiki-by-tag (tag)
  "Pop to a buffer of links to headlines \"~/org/\" in including TAG."
  (pop-to-buffer (set-buffer (generate-new-buffer "*tag-matches*")))
  (org-mode)
  (dolist (link (collect-links tag))
    (insert link) (insert "\n")))

> 
> 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.
>

Try the `regexp-builder' function in one of your org files to
interactively build up a regexp and see what it matches.

In general the following two functions are very useful for finding
useful functions and documentation.

- describe-function :: used with tab completion to show documentation of
  functions

- elisp-index-search :: to look up documentation on broad elisp topics

Cheers,

>
> - 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.
>>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-06 14:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-05  6:08 [OT] The joy of elisp Marcelo de Moraes Serpa
2011-12-05 17:34 ` Marcelo de Moraes Serpa
2011-12-06 14:27   ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).