Emacs-- batch mode / lisp command files

justin gedge jgedge at amis.com
Wed Apr 5 11:27:39 MDT 2006


I figured out batch/command files in emacs a few months ago- needed it 
again today and thought it was worth sharing on the plug.  For those who 
have wanted/needed to automate edits in emacs [but don't have the 4 
hours to research] this should get you running in 5-10 minutes!!!

Overall- automating emacs with a batch/command file isn't too dificult- 
but a lot of the documentation is written for those who already know 
everything.

To run emacs w/ batch mode- do following:

xemacs -batch -l [emacs_command_file]

====begin/emacs_command_file====

;; first need to open file you want to edit
(find-file "./file you want to open in emacs buffer")

;; once you have file open- need to use commands to
;; travers through file such as following
(search-forward "text-you're searching-for")
(search-backward "text-you're searching-for")
(end-of-line)
(beginning-of-line)
(beginning-of-buffer)
(end-of-buffer)


;; adding to the file is done with commands like
(newline)
(insert-string "text to insert")


;; how to save and exit
(save-buffer)
(kill-emacs)

====end/emacs_command_file====

for further reference-- there is plenty available in the online manual

M-x apropos

from there you can start typing in commands and get some online manuals 
etc... 

I've also found the O'Reilley ``GNU Emacs'' Pocket Reference usefull.  
You /need/ this for the 1st week you're learning emacs-- but years 
later- it can be kind of a nice reference as it provides a lot of the 
emacs/lisp commands along with the hot keys for comman commands.


Justin Gedge






More information about the PLUG mailing list