unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Teaching emacsclient to act as a pager, and more
@ 2016-06-07  1:25 Spencer Baugh
  2016-06-07  1:25 ` [PATCH 1/5] process: add features for direct use of FDs Spencer Baugh
                   ` (9 more replies)
  0 siblings, 10 replies; 40+ messages in thread
From: Spencer Baugh @ 2016-06-07  1:25 UTC (permalink / raw)
  To: emacs-devel

Hi emacs-devel,

I've added the ability for emacsclient to act as a pager, such that
you can pipe data to emacsclient and page through it in the emacs
frame of your choice. The attached patches are on top of commit
549470fdf234acb4da7941e3bb9b28ed63a51876

Here is a video demo: https://catern.com/files/emacspager.webm

To do this, I've used the file descriptor passing feature of Unix
sockets, which allows a process to transmit a duplicate of any of its
open file descriptors over a Unix socket to another process. The other
process can then make full use of that file descriptor, including, of
course, reading and writing from it.

In the attached patches, I taught emacsclient to (when a new option
--pipeline/-l is passed) send its stdin/stdout/stderr to the emacs
server, and I taught the emacs server to accept those file descriptors
and make an Elisp process out of them. Then the process machinery does
the rest of the work of reading data from the Elisp process (which is
actually data coming in on emacsclient's stdin) and putting it in a
buffer.

This functionality is exposed to Elisp by simply directly passing
received file descriptor numbers to the process filter function (with
a new argument, to processes that have opted in with a new keyword
argument :ancillary). Those file descriptor numbers can be passed to a
new function make-fd-process.

I've written a function in Elisp, server-pager, which should be run
with emacsclient -l --eval (server-pager). I added a new dynamic
variable server-emacsclient-proc which is non-nil if we are currently
evaluating Lisp for an emacsclient, and holds the Elisp process
corresponding to that Emacsclient. server-pager uses this variable to
retrieve the file descriptors for the current emacs-client, invoke
make-fd-process, and pop-to-buffer the output buffer. server-pager
stores the Elisp process it creates in the plist of the corresponding
emacsclient, so when the Elisp process is killed, emacsclient is told
to exit (if it didn't also open frames). Likewise if emacsclient is
killed, the server-pager Elisp process is killed.

The primary issue here, it seems to me, is that this leads to huge
amounts of file descriptor leakage - if any passed-in file descriptor
is unused, it is eternally left open. I think a good way to fix this
is to add a native Elisp file descriptor type, so the file descriptor
can be closed on garbage collect. But perhaps there's a better
solution? In any case I would need guidance on how to create such a
new Elisp type - this is my first attempt to hack on the Emacs C
codebase.

I am sure that these patches are terrible style, not in keeping with
the Emacs coding conventions, and totally unportable (I wrote this on
GNU/Linux) - I just wanted to get out a quick proof of concept.




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

end of thread, other threads:[~2018-02-17 15:46 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-07  1:25 Teaching emacsclient to act as a pager, and more Spencer Baugh
2016-06-07  1:25 ` [PATCH 1/5] process: add features for direct use of FDs Spencer Baugh
2016-06-07  1:25 ` [PATCH 2/5] server.el: accept FDs from emacsclient Spencer Baugh
2016-06-07  1:25 ` [PATCH 3/5] emacsclient: support passing stdin/out/err to emacs Spencer Baugh
2016-06-07  1:25 ` [PATCH 4/5] server: add pager tapping and show-active Spencer Baugh
2016-06-07  1:25 ` [PATCH 5/5] emacsclient: add extra-quiet mode Spencer Baugh
2016-06-08 15:51 ` Teaching emacsclient to act as a pager, and more Tassilo Horn
2016-06-08 16:13   ` Anders Lindgren
2016-06-08 17:30     ` Tassilo Horn
2016-06-09  0:25   ` raman
2016-06-09 11:31 ` H. Dieter Wilhelm
2016-06-27 22:42 ` Ole JørgenBrønner
2016-07-24 18:22 ` sbaugh
2016-09-09 13:42   ` Noam Postavsky
2016-09-09 14:14     ` sbaugh
2016-09-09 14:59       ` Stefan Monnier
2016-09-09 15:58         ` sbaugh
2016-09-09 19:26           ` Stefan Monnier
2016-09-09 19:42             ` Eli Zaretskii
2016-09-09 21:13             ` sbaugh
2016-09-10  6:37               ` Using file descriptors in Emacs (was: Teaching emacsclient to act as a pager, and more) Eli Zaretskii
2016-09-10 20:15             ` Teaching emacsclient to act as a pager, and more sbaugh
2016-09-11  2:11               ` Leo Liu
2018-02-16 23:14               ` Kaushal Modi
2018-02-17 15:46                 ` Göktuğ Kayaalp
2016-09-09 15:53       ` Eli Zaretskii
2016-09-09 17:16         ` sbaugh
2016-09-09 18:50           ` Eli Zaretskii
2016-09-09 19:03             ` sbaugh
2016-09-09 19:26               ` Eli Zaretskii
2016-09-09 20:38                 ` sbaugh
2016-09-10  7:12                   ` Using file descriptors in Emacs Eli Zaretskii
2016-09-10 14:28                     ` sbaugh
2016-09-11 15:28                       ` Eli Zaretskii
2016-09-11 16:00                         ` sbaugh
2016-09-11 16:39                           ` Eli Zaretskii
2016-09-11 16:57                             ` sbaugh
2016-09-11 17:13                               ` Eli Zaretskii
2016-09-12 15:40                               ` Davis Herring
2016-09-09 13:27 ` Teaching emacsclient to act as a pager, and more sbaugh

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