0

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)

flonk
  • 3,726
  • 3
  • 24
  • 37

2 Answers2

6

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.

jmbr
  • 3,298
  • 23
  • 23
  • Thank you. Unfortunately, it does not what I want, for example `emacs --eval '(progn (goto-line 10))' my_file.py` will not do what's expected. What I look for is a way to evaluate lisp code in the file's own buffer, *after* loading it. – flonk Aug 04 '13 at 18:40
  • I have just edited the command line ordering in my post to do exactly what you are asking for. I just tested it and it works on Emacs 24.3.50.7 – jmbr Aug 04 '13 at 18:54
2

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.

Community
  • 1
  • 1
jpkotta
  • 9,237
  • 3
  • 29
  • 34