help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [QUESTION] How to use :filter in `make-process'?


From: stardiviner
Subject: Re: [QUESTION] How to use :filter in `make-process'?
Date: Tue, 03 Mar 2020 23:08:24 +0800
User-agent: mu4e 1.3.8; emacs 27.0.50

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


Stefan Monnier <address@hidden> writes:

>> (let ((op-fn (lambda () (message "call the fn"))))
>>   (make-process
>>    :name "sleep command test"
>>    :command (list "sleep" "3")
>>    :filter `(lambda (proc event)
>>               (message "event catched!")
>                                 ^^^^^^^
>                                 caught ;-)
>>               (funcall ,op-fn))
>>    :buffer "*sleep test*"))
>
> More importantly, the ,op-fn is incorrect, it should be ',op-fn
> otherwise the value contained in op-fn will be re-interpreted as an
> expression (which will sometimes be harmless but sometimes not,
> depending on how the function value ends up represented).
>
> Of course, the better solution is to use `lexical-binding` so you can
> just write:
>
>     (let ((op-fn (lambda () (message "call the fn"))))
>       (make-process
>        :name "sleep command test"
>        :command (list "sleep" "3")
>        :filter (lambda (proc event)
>                  (message "event catched!")
>                  (funcall op-fn))
>        :buffer "*sleep test*"))
>
Use lexical-binding in your example, it does not work. report error:

: error in process sentinel: Symbol’s value as variable is void: op-fn [2 times]

>
> -- Stefan


- -- 
[ stardiviner ]
       I try to make every word tell the meaning what I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
      
-----BEGIN PGP SIGNATURE-----

iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5ecugUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsPRXAgAzjfJp3dgJ7fKBf0C6flThJXqEhiL
TXrDnJ2mFehQzZO21lmMoGjy2Td6nxuGHJO7VdryhsE0b6hwaVVqbTD1TC+nvbtO
dBZ8ZiSWnbYYgLraLtOU+oFQ6ZTa+gN6ADpbm+44xMk3mL41xjgg5Nx+a4U8+poG
EDLZZNpbuQF9BjL9Bzvkb14lTMV0rOZKuRfo8+Q5VDu92rbQbk1Fkr4dDOgdc5eV
BsPXtkc+zw4PZ8Vcx+GNy52PcthAX2A0Div+TK7sfRm1FIERdQiIk1PuwEub8dT8
Z5WhZSYMjvhwFwRISm7N2K7Fj0qIwLnT/DAiWn/c0uovdNId42jivO9qYA==
=cLpZ
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]