unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Reading from pipes directly with a process-filter
@ 2023-01-13 19:01 Peter
  2023-01-13 19:43 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Peter @ 2023-01-13 19:01 UTC (permalink / raw)
  To: emacs-devel

Hello!

I've been slowly sliding into using Emacs more and more like a Lisp OS,
so one thing that has come up is directly reading data from pipes or
special devices (like /dev/input/event...). I can do that fine by
running `start-process' with `cat /dev/input/event..', however that
seems a bit wasteful. Is there any way to *directly* open such a file
and put a process-filter in front of it?

Semi-relatedly, is there any support for `fnctl' or `ioctl' in elisp, so
that I could even *write* to those special devices?

Thanks for any help with this!

Greetings,
Peter



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reading from pipes directly with a process-filter
  2023-01-13 19:01 Reading from pipes directly with a process-filter Peter
@ 2023-01-13 19:43 ` Eli Zaretskii
  2023-01-13 21:51   ` Peter
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2023-01-13 19:43 UTC (permalink / raw)
  To: Peter; +Cc: emacs-devel

> From: "Peter" <emacs@nexoid.at>
> Date: Fri, 13 Jan 2023 20:01:37 +0100
> 
> I've been slowly sliding into using Emacs more and more like a Lisp OS,
> so one thing that has come up is directly reading data from pipes or
> special devices (like /dev/input/event...). I can do that fine by
> running `start-process' with `cat /dev/input/event..', however that
> seems a bit wasteful. Is there any way to *directly* open such a file
> and put a process-filter in front of it?

Did you try to use make-pipe-process?

> Semi-relatedly, is there any support for `fnctl' or `ioctl' in elisp, so
> that I could even *write* to those special devices?

Doesn't a simple 'write' (a.k.a. write-region in Emacs) work?  If not,
can you show a recipe that fails with all the details?



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reading from pipes directly with a process-filter
  2023-01-13 19:43 ` Eli Zaretskii
@ 2023-01-13 21:51   ` Peter
  2023-01-14  6:56     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Peter @ 2023-01-13 21:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

>> I've been slowly sliding into using Emacs more and more like a Lisp OS,
>> so one thing that has come up is directly reading data from pipes or
>> special devices (like /dev/input/event...). I can do that fine by
>> running `start-process' with `cat /dev/input/event..', however that
>> seems a bit wasteful. Is there any way to *directly* open such a file
>> and put a process-filter in front of it?
>
> Did you try to use make-pipe-process?

No, but from my understanding, this will also not read the file
directly, but run an extra process.

>> Semi-relatedly, is there any support for `fnctl' or `ioctl' in elisp, so
>> that I could even *write* to those special devices?
>
> Doesn't a simple 'write' (a.k.a. write-region in Emacs) work?  If not,
> can you show a recipe that fails with all the details?

For example https://www.kernel.org/doc/html/v4.12/input/uinput.html
shows how to write events to uinput. The function emit does the writing
(the encoding can easily be done with bindat in Emacs), however it isn't
sufficient to just *write* events, but some metadata must be set via
ioctl (yea, "everything is a file" ... except for so many things...).

This is not a "normal" use-case for Emacs, however I've been playing
around with running Emacs on the Pinephone, and this would help with the
vibrator for notifications, for example.

Of course this could also be done in C code from a module, but if Emacs
already somehow has support for doing this "directly", that'd be even
greater ;)

Thanks for taking the time to think about this!

Greetings, Peter



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reading from pipes directly with a process-filter
  2023-01-13 21:51   ` Peter
@ 2023-01-14  6:56     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-01-14  6:56 UTC (permalink / raw)
  To: Peter; +Cc: emacs-devel

> From: Peter <emacs@nexoid.at>
> Cc: emacs-devel@gnu.org
> Date: Fri, 13 Jan 2023 22:51:04 +0100
> 
> >> I've been slowly sliding into using Emacs more and more like a Lisp OS,
> >> so one thing that has come up is directly reading data from pipes or
> >> special devices (like /dev/input/event...). I can do that fine by
> >> running `start-process' with `cat /dev/input/event..', however that
> >> seems a bit wasteful. Is there any way to *directly* open such a file
> >> and put a process-filter in front of it?
> >
> > Did you try to use make-pipe-process?
> 
> No, but from my understanding, this will also not read the file
> directly, but run an extra process.

I don't think I understand what you are saying.  make-pipe-process
doesn't create any OS-level process, it creates only an Emacs process
object, similarly to what make-network-process does.

> >> Semi-relatedly, is there any support for `fnctl' or `ioctl' in elisp, so
> >> that I could even *write* to those special devices?
> >
> > Doesn't a simple 'write' (a.k.a. write-region in Emacs) work?  If not,
> > can you show a recipe that fails with all the details?
> 
> For example https://www.kernel.org/doc/html/v4.12/input/uinput.html
> shows how to write events to uinput. The function emit does the writing
> (the encoding can easily be done with bindat in Emacs), however it isn't
> sufficient to just *write* events, but some metadata must be set via
> ioctl (yea, "everything is a file" ... except for so many things...).
> 
> This is not a "normal" use-case for Emacs, however I've been playing
> around with running Emacs on the Pinephone, and this would help with the
> vibrator for notifications, for example.
> 
> Of course this could also be done in C code from a module, but if Emacs
> already somehow has support for doing this "directly", that'd be even
> greater ;)

Sounds like a job for a dynamic module, not for something that has to
be in the Emacs core.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-14  6:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 19:01 Reading from pipes directly with a process-filter Peter
2023-01-13 19:43 ` Eli Zaretskii
2023-01-13 21:51   ` Peter
2023-01-14  6:56     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).