Here is my zsh code

function eweb() {
    emacsclient -t --eval "(eww-open-file \"$1\")" "(save-buffer \"$2\")"

There are two parameters, the first is the local webpage filename, for example, ./1.html. The second parameter is the filename I want to save the text to. For example, 1.org. This code can open the webage successfully, but it cannot pass the second parameter to save-buffer.

What's more, it cannot finish the procedure silently, which means it cannot be used to batch convert HTML to text.

How can I solve these two problems?

  • Put everything inside a (progn ...) form, then escape intermediate quotation marks. – InHarmsWay May 24 '18 at 11:40
  • Thank you @InHarmsWay .I did what you say, eweb () { emacsclient -t --eval (progn \"(eww-open-file \"$1\")\" \"(save-buffer \"$2\")\") } , but it shows error. – ytyyutianyun May 24 '18 at 12:51
  • What is the error? And you shouldn’t escape the opening and closing quotation marks. I’ll add an answer – InHarmsWay May 24 '18 at 13:28
  • Untested, but try this: emacsclient -t —eval \”(progn (eww-open-file \\\”$1\\\”)(save-buffer \\\”$2\\\”))\” – InHarmsWay May 24 '18 at 13:34
  • That quoting was for .gitconfig. In a shell script you can also experiment with —eval “(progn (eww-open-file \”$1\”)(save-buffer \”$2\”))” – InHarmsWay May 24 '18 at 13:48

To pass multiple expressions to emacsclient (and emacs as well), you have two options.

The first option is grouping them into one expression with progn:

function eweb() { 
    emacsclient -e "(progn (eww-open-file \"$1\") (write-region nil nil \"$2\"))"

The second option is using multiple -e/--eval:

function eweb() {
    emacsclient -e "(eww-open-file \"$1\")" -e "(write-region nil nil \"$2\")"

By default, emacsclient prints the value of each expression, for example,

$ emacsclient -e 1 -e 2 -e 3

Since Emacs 26.1, you can the -u/--suppress-output option to disable the behaviour

-u, --suppress-output Don't display return values from the server

With the option, emacsclient will print nothing.

$ emacsclient -u -e 1 -e 2 -e 3
  • 1
    Emacsclient can accept an arbitrary number of s-expressions to evaluate after the --eval option. It is Emacs which only accepts a single expression per --eval option. – Basil Aug 27 '18 at 18:14
  • @Basil Oh, you're right. I didn't know that. I think the real issue is that OP (@yuxuan) misused save-buffer. – xuchunyang Aug 27 '18 at 19:53
  • Yes, when they were most likely after write-file/write-region. – Basil Aug 27 '18 at 20:11

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.