Elisp: Run Emacs Lisp Script in Shell
Run Emacs Lisp Script in Shell
You can run emacs lisp script in shell (terminal), using the --script
option. For example:
emacs --script myfile.el
Prepare Your Emacs Lisp Script to Run in Batch Mode
When you write a elisp script to run in batch, make sure your elisp file is:
- Self-contained; Doesn't depend on anything from your emacs init file.
- Explicitly load all libraries it needs (using
require
orload
). see Elisp: provide, require, features • Elisp: load, load-file, autoload - Has necessary load path set in the script (e.g.
(add-to-list 'load-path lib_path)
) if it needs libs that's not part of standard GNU emacs install.
How to start emacs on a Mac from command line?
If you are on a Mac, call it from the command line like this:
/Applications/Emacs.app/Contents/MacOS/Emacs --script=name.el