I would like to have output from Emacsclient without quotes, but

$ emacsclient -s my-server -e '(princ "hello")'

gives output:


Expected output would be:


The effect of the princ function happens in the server Emacs, in this case, hello is echoed in the echo area.

emacsclient in the other hand, prints the return value of the expression, which is the string "hello".

For example:

emacsclient -s my-server -e '(progn (princ "hello") 1)'

Here, hello is still being echoed in the server Emacs, however, emacsclient prints 1, as this is the value of the expression.

| improve this answer | |
  • Thanks.. but I am not sure I understand completely.. Then why is emacsclient -s my-server -e '"hello"' still printing "Hello" and not Hello? – Håkon Hægland Feb 19 '15 at 10:00
  • But emacsclient -s my-server -e "'hello" works.. – Håkon Hægland Feb 19 '15 at 10:01
  • Maybe I could use something like: emacsclient -s my-server -e '(make-symbol (princ "Hello"))' ? – Håkon Hægland Feb 19 '15 at 10:10
  • 4
    emacsclient prints the value of the expression. A symbol would print like hello, but a symbol with a space would print like hello\ world. As far a I know, there is no way to make emacsclient print anything other than a read:able representation of a lisp object. However, you could write a simple wrapper script in your favorite scripting language (like Ruby) that starts emacsclient is such a way that it stores the output in, say, a file, which the wrapper script could pick up and print. – Lindydancer Feb 19 '15 at 10:34
  • @HåkonHægland The printing of the string is a side effect of the function. This side effect happens inside Emacs. The evaluation in emacsclient doesn't return the side effect, it returns the last element of the expression, which in your OP is "hello". In Lindydancer's example, the last element is 1. – nanny Feb 19 '15 at 15:05

As @Lindydancer said, a wrapper would work. Here's a simple example for Linux:

bash -c 'echo ${0:1:-1}' $(emacsclient -e '(caar (make-frame-names-alist))')

I use it to bring my emacs window into focus (I normally only have 1) by feeding its output to wmctrl:

wmctrl -a $(bash -c 'echo ${0:1:-1}' $(emacsclient -e '(caar (make-frame-names-alist))'))
| improve this answer | |

As you know the name of your server, I suspect the server-eval-at function, called from a secondary Emacs instance running in batch mode, may be a workable solution (perhaps depending on how frequently you're planning on calling this).


emacs -Q --batch -l server --eval "(princ (server-eval-at \"my-server\" '\"Hello, world\"))"

emacs -Q --batch -l server --eval "(princ (server-eval-at \"my-server\" '(emacs-version)))"

emacs -Q --batch -l server --eval "(prin1 (server-eval-at \"my-server\" 'load-path))"
| 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.