I would like to have output from Emacsclient without quotes, but
$ emacsclient -s my-server -e '(princ "hello")'
gives output:
"hello"
Expected output would be:
hello
I would like to have output from Emacsclient without quotes, but
$ emacsclient -s my-server -e '(princ "hello")'
gives output:
"hello"
Expected output would be:
hello
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)'
1
Here, hello
is still being echoed in the server Emacs, however, emacsclient
prints 1
, as this is the value of the expression.
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))'))
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).
Examples:
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))"
emacsclient -s my-server -e '"hello"'
still printing"Hello"
and notHello
? – Håkon Hægland Feb 19 '15 at 10:00emacsclient -s my-server -e "'hello"
works.. – Håkon Hægland Feb 19 '15 at 10:01emacsclient -s my-server -e '(make-symbol (princ "Hello"))'
? – Håkon Hægland Feb 19 '15 at 10:10emacsclient
prints the value of the expression. A symbol would print likehello
, but a symbol with a space would print likehello\ world
. As far a I know, there is no way to makeemacsclient
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 startsemacsclient
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:34emacsclient
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 is1
. – nanny Feb 19 '15 at 15:05emacsclient -e '(progn (princ "This is printed inside Emacs") (princ "Its not printed in the shell.") (princ "Its just a coincidence that the last element of this expression is the string you want to print"))'
. – nanny Feb 19 '15 at 15:11