Emacs wizardry for the non-programmer.
December 30, 2008 9:37 AM   Subscribe

How can I automate emacs to open a file, execute a bunch of macros, then save the file in a new format?

I need to extract bookmarks from large PDFs into text files importable into MS Access. I have been using emacs to open the file, then used 5-6 macros to extract the bookmarks and format it properly to be imported into Access. This gets extremely tedious, I have about 100 files to convert.

Is there a more elegant or convenient way to do this? I would love to be able to automate it in emacs. I am not a programmer, and although I have tried to figure out how to do this with elisp, it just doesn't make sense to me. I'm running emacs 22.2.1 on Windows and Acrobat 6 and 7 standard.
posted by Barry B. Palindromer to Technology (5 answers total) 1 user marked this as a favorite
Best answer:
(setq list-of-file-names '("test-file" "test-file-two"....))

(defun do-something-to-file (file-name)
    (find-file file-name)
    (goto-char (point-min))

(mapc 'do-something-to-file list-of-file-names)

posted by rdr at 9:52 AM on December 30, 2008

Best answer: Or if you don't want to touch e-lisp, then you can automate this with a keyboard macro. Make a buffer that contains the names of the files that you wish to operate on with each file name on a different line. Start recording the keyboard macro with C-X (, move to the beginning of the current line, kill it, yank it, C-X C-F, yank, do whatever, write the result, return to list of files buffer, move to the next line. Once you've got the macro you run it 100 times by doing Meta - 1 0 0 C-X e. Backup up work before you start debugging.
posted by rdr at 10:18 AM on December 30, 2008

Best answer: See the Emacs Wiki for how to convert a macro to an elisp function and how to run it in batch mode.

This, in combination with rdr's hints should get you there.
posted by Zed at 1:25 PM on December 30, 2008

Best answer: As much as Emacs is my Operating System text editor of choice, you are kind of using the wrong tool for the job. I think PDFtk can do what you want, windows binary here.
posted by ghost of a past number at 10:14 PM on December 30, 2008

Response by poster: Cool. Looks like PDFtk will work with the bookmark extraction, then I can clean up the text files with some batched macros. Still have to figure the specifics on that, but thanks for pointing out the way.
posted by Barry B. Palindromer at 9:32 AM on December 31, 2008

« Older What are we dealing with here?   |   The 1000 Photos of Dr. M Newer »
This thread is closed to new comments.