flonk
flonk

Reputation: 3876

Start emacs from shell with predefined lisp code

It is possible to start emacs from the shell and tell it to execute a lisp function, e.g.

emacs -f some-lisp-function my_file.py

However, I would like to pass also lisp functions with arguments, like

emacs -f "(goto-line 10)" my_file.py
# --> not working

and in the best of all worlds, pass also more complex lisp code consisting of multiple function calls, like

emacs -f "(goto-line 10) (some-other-func some-arg)" my_file.py
# --> not working

Does somebody know how?

Edit: To clarify this point, I need a way to evaluate the lisp code in the file's own buffer, after opening it.

(Btw. I know that the goto-line problem could be solved differently without using -f but thats just one example for my general problem)

Upvotes: 0

Views: 359

Answers (2)

jmbr
jmbr

Reputation: 3348

Try emacs my_file.py --eval '(progn (goto-line 10) (some-other-func some-arg))'. Also note that invoking Emacs as emacs +10 my_file.py will open the file at the tenth line.

Upvotes: 7

jpkotta
jpkotta

Reputation: 9417

You have access to the command line that Emacs was invoked with. You can add code to handle your own command line switches. Depending on what you want, this may be cleaner than --eval. See http://www.gnu.org/software/emacs/manual/html_node/elisp/Command_002dLine-Arguments.html and Emacs custom command line argument.

Upvotes: 2

Related Questions