I would like to:

  1. run an emacs function from the shell
  2. in a standard emacs session (configured as if it was run in an interactive session)
  3. with a certain file in the active buffer

So I would like to do something like:

emacs --function org-beamer-export-to-pdf --file my-presentation.org

Bonus points if I can run it with the emacsclient, connecting to an already running emacs server.

1 Answer 1


This should do what you want. If you don't have the file open, you may need to replace the switch-to-buffer function to something that opens the file.

emacsclient -e '(progn (switch-to-buffer "my-presentation.org") (org-beamer-export-to-pdf))'
  • 2
    Great, I had to use find-file instead of switch-to-buffer
    – blueFast
    Sep 8, 2016 at 5:33
  • Should I do somethings as follows: emacsclient -e '(progn (switch-to-buffer "foo.py"))'
    – alper
    May 10, 2020 at 11:45
  • @alper Would that be identical to emacsclient foo.py?
    – AstroFloyd
    Dec 28, 2022 at 13:22
  • @AstroFloyd Yes sir it will
    – alper
    Dec 28, 2022 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.