[emacs-berlin] `server-eval-at' turns out to be pretty useful...

Grant Rettke grant at wisdomandwonder.com
Sat Apr 3 05:08:38 UTC 2021


In the code I set up, instead of returning the value as it is displayed for
a human to read, the output from `princ' to STDOUT is captured and returned
as the value.

This seems to be the one thing I can't figure how to do with emacsclient.

The reason I need this is that in other programs I don't want to manage
return values like "Hello world" should be two words instead of one word
wrapped in double quotes.



On Sat, Apr 3, 2021 at 12:03 AM Grant Rettke <grant at wisdomandwonder.com>
wrote:

> The one thing I really wanted is to get the result without double-quotes.
>
> I have to figure that out.
>
> On Fri, Apr 2, 2021 at 5:49 PM Grant Rettke <grant at wisdomandwonder.com>
> wrote:
>
>> ---
>> /Applications/Emacs.app/Contents/MacOS/bin/emacsclient
>> --socket-name="/Users/gcr/server-sockets/emacs.sock" --eval 'emacs-version'
>> OK...
>>
>> "26.3"
>> ---
>>
>> Oh gosh.
>>
>> ---
>> /usr/bin/emacsclient --version
>> OK...
>>
>> emacsclient 22.1
>> ---
>>
>> Lol.
>>
>> ---
>> ✔ gsmac:~> ll /usr/local/bin/emacs
>> OK...
>>
>> lrwxr-xr-x 1 gcr admin gcr 44 2019-11-22 21:24 "/usr/local/bin/emacs" ->
>> "/Applications/Emacs.app/Contents/MacOS/Emacs"*
>> ✔ gsmac:~> which emacsclient
>> OK...
>>
>> /usr/bin/emacsclient
>> ✔ gsmac:~> ll /usr/bin/emacsclient
>> OK...
>>
>> -rwxr-xr-x 1 root wheel root 33k 2020-09-10 22:16 "/usr/bin/emacsclient"*
>> ✔ gsmac:~>
>> ---
>>
>> The problem: I forgot to link to the newer emacsclient.
>>
>> Thank you Til.
>>
>> On Fri, Apr 2, 2021 at 3:47 PM Grant Rettke <grant at wisdomandwonder.com>
>> wrote:
>>
>>> Here is how it works for me:
>>>
>>> ✔ gsmac:~/src/be2 [main|✚ 2]> emacsclient
>>> --socket-name="/Users/gcr/server-sockets/emacs.sock" --eval 'emacs-version'
>>> OK...
>>>
>>> -emacs-pid 9230
>>> -print "26.3"
>>> ✔ gsmac:~/src/be2 [main|✚ 2]> emacs --batch --eval "(progn (require
>>> 'server) (princ (server-eval-at \"/Users/gcr/server-sockets/emacs.sock\"
>>> 'emacs-version)))"
>>> OK...
>>>
>>> 26.3
>>> ✔ gsmac:~/src/be2 [main|✚ 2]>
>>>
>>> I just want the value 26.3 not the -emacs-pid and -print stuff.
>>>
>>> I can't wait to try this on v27.
>>>
>>> On Fri, Apr 2, 2021 at 3:24 PM Grant Rettke <grant at wisdomandwonder.com>
>>> wrote:
>>>
>>>> Forgot to share this is what it does on my machine:
>>>>
>>>> ---
>>>> emacsclient --socket-name="/Users/gcr/server-sockets/emacs.sock" --eval
>>>> "(+ 1 1)"
>>>> OK...
>>>>
>>>> -emacs-pid 9230
>>>> -print 2
>>>> ---
>>>> emacsclient --socket-name="/Users/gcr/server-sockets/emacs.sock" --eval
>>>> "emacs-version"
>>>> OK...
>>>>
>>>> -emacs-pid 9230
>>>> -print "26.3"
>>>> ---
>>>> emacsclient --socket-name="/Users/gcr/server-sockets/emacs.sock" --eval
>>>> '(with-current-buffer "*scratch*" (insert "Hello scratch buffer"))'
>>>> OK...
>>>>
>>>> -emacs-pid 9230
>>>> -print nil
>>>> ---
>>>>
>>>> Want to bet that it is because I'm on Emacs 26?
>>>>
>>>> On Fri, Apr 2, 2021 at 2:37 PM Grant Rettke <grant at wisdomandwonder.com>
>>>> wrote:
>>>>
>>>>> My computer is trying to drive insane. That is what is happening here..
>>>>> And it is working.
>>>>>
>>>>> It has to be working wrong on my machine.
>>>>>
>>>>> Thanks for sharing that Til.
>>>>>
>>>>> On Fri, Apr 2, 2021 at 7:09 AM Tilmann Singer <tils at tils.net> wrote:
>>>>>
>>>>>> I might be missing something obvious, but what exactly is it that
>>>>>> emacsclient can not do? With a running Emacs instance in which
>>>>>> (server-start) has been called before, the following commands on a
>>>>>> terminal with the bash shell work out of the box for me:
>>>>>>
>>>>>> $ emacsclient -e "(+ 1 1)"
>>>>>> 2
>>>>>>
>>>>>> $ printf "How many is binary? $(emacsclient -e '(+ 1 1)')\n"
>>>>>> How many is binary? 2
>>>>>>
>>>>>> $ emacsclient -e 'emacs-version'
>>>>>> "27.2"
>>>>>>
>>>>>> $ emacsclient -e '(with-current-buffer "*scratch*" (insert "Hello
>>>>>> scratch buffer"))'
>>>>>> nil
>>>>>> => Text was inserted into buffer *scratch*
>>>>>>
>>>>>>
>>>>>> At least on this (arch) linux machine, the default server-socket-dir
>>>>>> of
>>>>>> "/run/user/1000/emacs" seems to be working fine.
>>>>>>
>>>>>>
>>>>>> Til
>>>>>>
>>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailb.org/pipermail/emacs-berlin/attachments/20210403/53920a7d/attachment.htm>


More information about the emacs-berlin mailing list