I am running emacsclient with the command:

emacsclient -t -a "" --eval "some-exp"

The emacsclient -t -a "" is a must.

The problem is, for example, if I run:

emacsclient -t -a "" --eval "nil"

when quitting emacsclient, the command line will have "nil" printed.

My question is, how to totally stop the printing of the returned value ? (in here, it's nil).

  • Would answer that prints output to STDERR Instead be acceptable? – Melioratus Nov 29 '16 at 5:50
  • @Melioratus yes, how to achieve that? – FunkyBaby Nov 29 '16 at 6:55

I don't really understand your concern. emacsclient's --eval/-e always eval one expression and print the result to stdout, if you don't care about the result, simply ignore it or redirect it to /dev/null. Anyway, it's easy to stop printing, you can use

(define-advice server-eval-and-print (:filter-args (args) no-print)
  (list (car args) nil))

to advice server-eval-and-print to just eval and bypass print. It should be easy to know how it works by taking a look at the function server-eval-and-print in source code.

If you don't have define-advice, which was added in Emacs 25.1, use this instead:

(defun server-eval-and-print@no-print (args)
  (list (car args) nil))

(advice-add 'server-eval-and-print :filter-args
  • How did you trace down to 'server-eval-and-print' from the mere fact --eval "sexp" evaluates an sexp? – FunkyBaby Nov 30 '16 at 4:52
  • btw, redirecting stdout to /dev/null will make emacsclient -t -a "" fail to launch. – FunkyBaby Nov 30 '16 at 4:53
  • @FunkyBaby Here is how server-eval-and-print do the evaluation: (eval (car (read-from-string expr))), so if you pass multiple sexp, it always the first one and ignore the rest. – xuchunyang Nov 30 '16 at 5:16
  • @FunkyBaby I assumed you only want to redirect the output of --eval/-e. I don't understand why you need use -t and --eval/-e together. the -t makes no sense when --eval/-e exists, though It's should be OK. Of course, you can't do something like emacsclient -t foo.txt > /dev/null or vi foo.txt > /dev/null. – xuchunyang Nov 30 '16 at 5:31
  • What if I just want to omit the "nil" to stdout, not anything else? – CodyChan Apr 16 '19 at 5:57

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.