Elisp: Run Elisp Script in Terminal
Run Emacs Lisp Script in Shell
to run emacs lisp script in shell (terminal), use the --script
option.
emacs --script myfile.el
;; -*- coding: utf-8; lexical-binding: t; -*- ;; save this file as myfile.el ;; run it in terminal, like this ;; emacs --script myfile.el (message "Hi. Today is %s" (format-time-string "%Y-%m-%d"))
Prepare Emacs Lisp Script to Run in Batch Mode
make sure your elisp file is:
- Self-contained. Independ from anything in 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.