Emacs Lisp: Run Emacs Lisp Code in Shell
You can run emacs lisp script in shell (terminal), using the
--script option. For example:
emacs --script abc.el
abc.el is file of emacs lisp code.
Here's a table of most useful options for running emacs lisp as a script.
- Do not load Emacs Init File,
- Do not load the site-wide init file
site-start.el. (info "(elisp) Init File")
- Run the elisp file at path.
- Do not launch emacs as a editor. Use it together with
--loadto specify a lisp file. This implies
- Run emacs like
--loadset to path.
For a complete list, see:
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
- Has necessary load path set in the script (For example,
(add-to-list 'load-path lib_path)) if it needs libs that's not part of standard GNU emacs install, just like you would with a Python or Ruby script.
How to start emacs on a Mac from command line?
If you are on a Mac, call it from the command line like this: