macro help - running org-id-copy successively in a doc

Discussion of programming Lisps using Emacs, including SLIME and other tools

macro help - running org-id-copy successively in a doc

Postby KI6VSM » Mon Jun 27, 2011 9:55 am

Hi folks. Brand new member here. I'm hoping someone can point me in the right direction. I'm a tech writer working on a large org-mode doc with 100's of headings that have :PROPERTY: tags requiring IDs. With shorter docs like this I've just manually run M-x, org-id-copy for each heading property. To save a huge amount of time, what I'd like to use here is use a macro that steps through the doc, finds each instance of :PROPERTIES: and runs org-id-copy.

Just to give you and idea of what I am thinking of, here is a somewhat lame pseudo-code of the procedure, from someone a bit rusty at programming:

search fwd for string ":PROPERTIES:"
Do-while-not-at-EOF {
run org-id-copy
search fwd for string ":PROPERTIES:"
}


Any help would be appreciated.

Patrick
KI6VSM
 
Posts: 2
Joined: Mon Jun 27, 2011 9:30 am

Re: macro help - running org-id-copy successively in a doc

Postby Ramarren » Tue Jun 28, 2011 12:33 am

Something like this should work:

Code: Select all
(defun org-create-all-ids ()
  (interactive)
  (goto-char (point-min))
  (while (search-forward ":PROPERTIES:" (point-max) t)
    (org-id-get-create)))


You can use this function by either adding it to your .emacs file after the org-mode setup, or for a single session by putting it in any buffer any doing eval-last-sexp (by default bound to C-x C-e) with point after the definition.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: macro help - running org-id-copy successively in a doc

Postby KI6VSM » Tue Jun 28, 2011 1:13 pm

Thank you! I'll give it a try. A colleague here at my company did a little digging and came up with a temporary solution: Using F3 to record my little find ':PROPERTIES:' and then run org-id-copy procedure as a macro. I then named the macro "id-add" and used C-u to tell org-mode to run the macro x number of times. As in, entering:

C-u 200 M-x id-add

It got the job done, for now. But it's only a temporary solution since the macro seems to get blown away when I either close the buffer or org-mode... not sure which it is. I guess user-created macros only live in the current buffer? or do they live as long as org-mode remains open?

In any case, your script is probably a better solution in the long run.
KI6VSM
 
Posts: 2
Joined: Mon Jun 27, 2011 9:30 am


Return to Emacs

Who is online

Users browsing this forum: No registered users and 2 guests

cron