1

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 \
--alternate-editor=emacs

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

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

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

emacs-eval-wrapper

#!/bin/bash
exec emacs --eval "$@"
| improve this answer | |

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.