Emacs Lisp: Get Command Line Arguments
when you run emacs lisp script from terminal
emacs --script do.el arg1 arg2
[see Emacs Lisp: Run Emacs Lisp Code in Shell]
You can get the arguments in elisp from the variable argv
- argv
- A built-in variable. Its value is a list. Each element is a item from the command line.
(message "argv 0: %s" (elt argv 0)) ; %s is for string (message "argv 1: %s" (elt argv 1)) (message "argv 2: %s" (elt argv 2)) (message "argv 3: %s" (elt argv 3))
Save and name the above script as test.el
and run it like this:
emacs --script test.el uni 2 -tri
Here's the output:
$ emacs --script test.el uni 2 -tri argv 0: "uni" argv 1: "2" argv 2: "-tri" argv 3: nil
(info "(elisp) Command-Line Arguments")
Thanks to Piotr Chamera [piotr_cham…@poczta.onet.pl], Swami Tota Ram Shankar [tota_…@india.com].