The following command works to open a file in an existing emacs instance:

emacsclient --eval \
"(progn (find-file \\"/a/b.txt\\") (goto-line 1) (forward-char 2) (recenter))" \
--no-wait \

However when there is no emacs instance running it creates a buffer called b.txt").

Is there a way this can be made to work in both cases?

1 Answer 1


In emacs 26 this will be supported by using --alternate-editor="emacs --eval"

For now you can write a script that wraps emacs, eg:


exec emacs --eval "$@"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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