3

I know that emacs can open a file while evaluating an expression:

emacs file --eval "(toggle-frame-maximized)"

However I failed to replicate this with emacsclient:

1.emacsclient can open a file:

emacsclient file

2.And it can also evaluate an expression:

emacsclient --eval "(toggle-frame-maximized)"

3.But a problem happens when the two are put together:

emacsclient file --eval "(toggle-frame-maximized)"

It starts to report error and does not open the file. So is it possible to use emacsclient to open a file while still do eval?

2

After several attempts I think I found the solution, basically just put everything into eval and concatenate them use progn:

emacsclient --eval "(progn (find-file \"file\") (toggle-frame-maximized))"
  • 4
    According emacsclient's manual, when --eval is given, the arguments are interpreted as a list of expressions to evaluate, so you can also use emacsclient --eval "(find-file \"file\")" "(toggle-frame-maximized)". – xuchunyang Dec 23 '16 at 8:10
  • 1
    This method of just evaluating find-file "file" is great and simple (which is important). However, it has the disadvantage that the buffer is not considered a "server-editing-buffer", so some of the nice in-built emacsclient machinery does not work — for example, when you call emacsclient -c --eval "(find-file \"file\")" "(other-elisp-functions)" , and then close the frame, the buffer you just opened is not killed (irrespective of whether it was open before or not), unlike with emacsclient -c file. – aplaice Feb 12 '17 at 18:05
  • I think that using server-visit-files — e.g. (server-visit-files '(("file" . nil )) proc) — might be a solution, except that we'd need to know the process id of the client, which I have no idea how to get. – aplaice Feb 12 '17 at 19:16

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.