* [QUESTION] How to use :filter in `make-process'?
@ 2020-03-03 7:49 stardiviner
2020-03-03 8:19 ` Joost Kremers
2020-03-03 14:39 ` Stefan Monnier
0 siblings, 2 replies; 11+ messages in thread
From: stardiviner @ 2020-03-03 7:49 UTC (permalink / raw)
To: Emacs Help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
I have an code example try to use :filter handler of make-process.
```
(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*"))
```
I don't know how to use it correctly. Can you give some good examples of using
this `:filter' handler, and explain it a little?
Thanks in advanced.
- --
[ 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-----
iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5eDCEUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsOYiQgAvbGnIiyR+SMjgf9Cr6ZQ5jSRcbwo
cPDl8tsWSAZkv8sYCbdlPWsLSAGg8pipTP/jSsB2wSF2xALAkxntNGSLwfryQcO4
nmKsDuPE6W2VewB6D7WrAmMjNUrQi0b27Frev017wYIWnWE1nK6cSpzh69/V/rOE
ACl+ReskQcv5lAhtHgBQXVmmqGvbrq0fbeZyqjIpw0MPACuRFjG03S+zPXIiE/Rn
tKtIvnniMutz8qxx37soV5VpcBazG5rrSc3pFGTTMb/dreiqz7Bmxh/xlVJXgCec
2GYz1H1TxHuHD5MZLvzgOIkuiFVH71x4KcilEA/j+4ZsVacaVgCPBGPgNA==
=R9s9
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 7:49 [QUESTION] How to use :filter in `make-process'? stardiviner
@ 2020-03-03 8:19 ` Joost Kremers
2020-03-03 16:18 ` [SOLVED] " stardiviner
2020-03-03 14:39 ` Stefan Monnier
1 sibling, 1 reply; 11+ messages in thread
From: Joost Kremers @ 2020-03-03 8:19 UTC (permalink / raw)
To: help-gnu-emacs
On Tue, Mar 03 2020, stardiviner wrote:
> I have an code example try to use :filter handler of
> make-process.
[...]
> I don't know how to use it correctly. Can you give some good
> examples of using
> this `:filter' handler, and explain it a little?
There is quite an elaborate explanation in the Elisp manual:
Elisp > Processes > Output from Processes > Filter Functions
or:
(info "(elisp) Filter Functions") ⇐ put cursor here and press C-x
C-e
HTH
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 11+ messages in thread
* [SOLVED] Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 8:19 ` Joost Kremers
@ 2020-03-03 16:18 ` stardiviner
2020-03-03 16:51 ` Stefan Monnier
0 siblings, 1 reply; 11+ messages in thread
From: stardiviner @ 2020-03-03 16:18 UTC (permalink / raw)
To: Joost Kremers; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Thanks Joost.
After reading the Info manual (even though the Info manual is not very friendly.)
I have following source code example which works great.
#+begin_src emacs-lisp
(shell-command "touch /tmp/tail.log")
(let ((proc (make-process
:name "*tail log*"
:command (list "tail" "-f" "/tmp/tail.log")
:filter (lambda (proc output)
(message "append log captured")
(let ((p (get-process "*tail log*")))
(when (buffer-live-p (process-buffer p))
(with-current-buffer (process-buffer p)
(let ((moving (= (point) (process-mark proc))))
(save-excursion
;; Insert the text, advancing the process marker.
(goto-char (process-mark proc))
(insert output)
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc))))))))
:sentinel (lambda (proc event)
(message "done!"))
:buffer "*tail log*")))
(display-buffer "*tail log*"))
#+end_src
#+RESULTS[<2020-03-04 00:15:51> 9c0b6b462a594bd21b9d5579bd9a9254a3279e62]:
: #<window 183 on *info elisp*>
Then execute following command to append content into the log file:
#+begin_src sh
for N in {0..10}; do
echo $N >> /tmp/tail.log
done
#+end_src
- --
[ 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-----
iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5eg1IUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsOaCgf+P+aEoz8powv4LhelGuypm71n2AVK
Kmx4wNu967+Uz5pCSpKAhFhRp1ZLIOVypQ1lkpoJD/40kK/vr2GCdKAfX4XSUbqb
aIasFL6xOZE+4V9fw7BJQAqz9T5deFv46scjXsAvaUAMquP8qAd1X6EMEx2PrQ9t
u0NCqTNY4Emob1bkMtDUyfjCYZ1wno+c6mxrpyUTk0AiRLLKA/mqv7p5HdhYZQq5
vsr8Yeg/SwLPoZSQpvXorvhO3chlB1/JL7R65P+cvv+56uaEsWh/PzHRK2FCLzWA
6wI9nGsW05mKzddoNPdU2ZiNuPcwvXPFrHliRyNCR8tHtBvieKEBLqVyzA==
=Pwf1
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [SOLVED] Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 16:18 ` [SOLVED] " stardiviner
@ 2020-03-03 16:51 ` Stefan Monnier
2020-03-03 17:33 ` stardiviner
0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2020-03-03 16:51 UTC (permalink / raw)
To: help-gnu-emacs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/x-markdown; coding=UTF-8, Size: 320 bytes --]
> After reading the Info manual (even though the Info manual is not very friendly.)
I suggest you `M-x report-emacs-bug` describing what you found
unfriendly, so the maintainers get a chance to improve it (tho of
course, what's friendly for one user can be very hostile for another
and vice versa).
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [SOLVED] Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 16:51 ` Stefan Monnier
@ 2020-03-03 17:33 ` stardiviner
0 siblings, 0 replies; 11+ messages in thread
From: stardiviner @ 2020-03-03 17:33 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> After reading the Info manual (even though the Info manual is not very friendly.)
>
> I suggest you `M-x report-emacs-bug` describing what you found
> unfriendly, so the maintainers get a chance to improve it (tho of
> course, what's friendly for one user can be very hostile for another
> and vice versa).
>
I agree. The point I think unfriendly is where it does not have example with
:filter code example. The Info manual use other functions like
set-process-filter etc instead. Of course the Info manual already explained the
document about :filter though.
- --
[ 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-----
iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5elPMUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsPPewgAyHFQABpeN742IEAIWGtN3GeX80/b
nMvaagfFYiJFKn2kujnbJySLk79UB/X9abiE1wQ+43vzS8QQYoHkQY2xb0sbNNlm
EskzT94qNxRMLznD6IA7yVwniodDEZXaXHE7Ncsv1CO+7zHFjiN59+SvbvYFU2JI
cyKoOGkZuYj5+uxsKKN8plliXGrjRJY1uwTHTq60kuEgTJI9o86NYVpx4Zl35u8f
mSqMaO0vhSwLuGHdDtDOOhprsjfkeGxH+/EUie8NI4MKCUINpfnRelDl+lu9tAhi
5+QD69Ep8lQmYsclOEauIsl6b3mVGa/66RfmD4QhSa4PlV3+RHRhbAE16w==
=HlNy
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 7:49 [QUESTION] How to use :filter in `make-process'? stardiviner
2020-03-03 8:19 ` Joost Kremers
@ 2020-03-03 14:39 ` Stefan Monnier
2020-03-03 15:08 ` stardiviner
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2020-03-03 14:39 UTC (permalink / raw)
To: help-gnu-emacs
> (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*"))
-- Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 14:39 ` Stefan Monnier
@ 2020-03-03 15:08 ` stardiviner
2020-03-03 15:25 ` Michael Heerdegen
2020-03-03 16:49 ` Stefan Monnier
0 siblings, 2 replies; 11+ messages in thread
From: stardiviner @ 2020-03-03 15:08 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Stefan Monnier <monnier@iro.umontreal.ca> 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-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 15:08 ` stardiviner
@ 2020-03-03 15:25 ` Michael Heerdegen
2020-03-03 17:34 ` stardiviner
2020-03-03 16:49 ` Stefan Monnier
1 sibling, 1 reply; 11+ messages in thread
From: Michael Heerdegen @ 2020-03-03 15:25 UTC (permalink / raw)
To: stardiviner; +Cc: help-gnu-emacs, Stefan Monnier
stardiviner <numbchild@gmail.com> writes:
> 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]
Note that you need to bind the buffer-local variable lexical-binding to
a non-nil value before you eval the example. Typically as file-local
variable in your source file.
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 15:25 ` Michael Heerdegen
@ 2020-03-03 17:34 ` stardiviner
0 siblings, 0 replies; 11+ messages in thread
From: stardiviner @ 2020-03-03 17:34 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs, Stefan Monnier
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Michael Heerdegen <michael_heerdegen@web.de> writes:
> stardiviner <numbchild@gmail.com> writes:
>
>> 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]
>
> Note that you need to bind the buffer-local variable lexical-binding to
> a non-nil value before you eval the example. Typically as file-local
> variable in your source file.
>
> Michael.
Aha, I see. Thanks Michael
- --
[ 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-----
iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5elSMUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsNI6QgAn2LZb3xR4Sir4mEMGD1VAkCtcIKz
eZLNGlYByQavcpef3yImhE2yEnVQK2V8vOHS3JyKayTQHreOSUOSREgJi/Y8M/dE
pZXiY4HYxe1O2yEBkJkDW0Kn+Dc2gccO0JSVf64GfBxQPHYLB1op9mgshu9kJMD3
gVWMKosL9VroZvKdQxDcpNi8g2PXj/WiEc50H97ixwvAhzCdJwv2TGwkPvS+1p3Z
FGdKdFTIYliWQs0FnpFPqxA00avCaCfQBsBfvSjB4M2xutxjWfEKrbbrL6E974SI
5LmVpK+DZsLQp9oGt7aawz0TiyPIHtB/fnvxHcRhB7r/H5Q3QeZuGbH4NA==
=9WPF
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 15:08 ` stardiviner
2020-03-03 15:25 ` Michael Heerdegen
@ 2020-03-03 16:49 ` Stefan Monnier
2020-03-03 17:35 ` stardiviner
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2020-03-03 16:49 UTC (permalink / raw)
To: help-gnu-emacs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/x-markdown; coding=UTF-8, Size: 128 bytes --]
> Use lexical-binding in your example, it does not work.
What steps did you take to "Use lexical-binding"?
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [QUESTION] How to use :filter in `make-process'?
2020-03-03 16:49 ` Stefan Monnier
@ 2020-03-03 17:35 ` stardiviner
0 siblings, 0 replies; 11+ messages in thread
From: stardiviner @ 2020-03-03 17:35 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Use lexical-binding in your example, it does not work.
>
> What steps did you take to "Use lexical-binding"?
>
>
I thought the lexical-binding is the let-binding.... Sorry, misunderstood.
- --
[ 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-----
iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl5elVIUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsPIVQf+MfAa8yYp2YOrhXdGnE8GhNUwLEg/
m91GPyA2zJYISpJngvTnEWYCGMS+iI5Jb+iBYMJ0ryC7QcOB2fP3sDedb44dXmsJ
5rFcs/nfrioGhFlk2Ivd13Wbm8OFrjKSxmzKgw/LV933k/MAI7+bWx4KiDGPiFwX
PwtR45ycneXj/TH1yC4323sEXBaKyEcIqrfwkvu2RVMi6nWZY6GA7mZwX80PqQgG
jPXRMvaQXE2VVQ4ynJDMAmp2fhv7s+HsjUA24vBu3ZQk6DAIdiRH+ruSAExjeNDz
hHohRYpzJOcNiI/iNlGIAiaGiauaD/GckqGsmR3HPaFY0B/Ok/ebaE7iEw==
=rTPc
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-03-03 17:35 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-03 7:49 [QUESTION] How to use :filter in `make-process'? stardiviner
2020-03-03 8:19 ` Joost Kremers
2020-03-03 16:18 ` [SOLVED] " stardiviner
2020-03-03 16:51 ` Stefan Monnier
2020-03-03 17:33 ` stardiviner
2020-03-03 14:39 ` Stefan Monnier
2020-03-03 15:08 ` stardiviner
2020-03-03 15:25 ` Michael Heerdegen
2020-03-03 17:34 ` stardiviner
2020-03-03 16:49 ` Stefan Monnier
2020-03-03 17:35 ` stardiviner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).