From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: dieter@duenenhof-wilhelm.de (H. Dieter Wilhelm) Newsgroups: gmane.emacs.devel Subject: Re: Teaching emacsclient to act as a pager, and more Date: Thu, 09 Jun 2016 13:31:43 +0200 Organization: The Church of Emacs Message-ID: <87mvmuegyo.fsf@duenenhof-wilhelm.de> References: <1465262706-5229-1-git-send-email-sbaugh@catern.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1465472008 5298 80.91.229.3 (9 Jun 2016 11:33:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 9 Jun 2016 11:33:28 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 09 13:33:19 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bAyD7-0002tn-Ab for ged-emacs-devel@m.gmane.org; Thu, 09 Jun 2016 13:33:17 +0200 Original-Received: from localhost ([::1]:33839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAyD6-0000fk-II for ged-emacs-devel@m.gmane.org; Thu, 09 Jun 2016 07:33:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAyCz-0000ad-WB for emacs-devel@gnu.org; Thu, 09 Jun 2016 07:33:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAyCv-00023A-PZ for emacs-devel@gnu.org; Thu, 09 Jun 2016 07:33:08 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:59864) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAyCv-00022q-IM for emacs-devel@gnu.org; Thu, 09 Jun 2016 07:33:05 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1bAyC8-00023Z-8e for emacs-devel@gnu.org; Thu, 09 Jun 2016 13:32:16 +0200 Original-Received: from p57acecc8.dip0.t-ipconnect.de ([87.172.236.200]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 09 Jun 2016 13:32:16 +0200 Original-Received: from dieter by p57acecc8.dip0.t-ipconnect.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 09 Jun 2016 13:32:16 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 67 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: p57acecc8.dip0.t-ipconnect.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (gnu/linux) Cancel-Lock: sha1:1K0n6DiZkKca2ONtkZAyhNd0D8o= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:204247 Archived-At: Spencer Baugh writes: > 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 +1 thanks > 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. > > > -- Best wishes H. Dieter Wilhelm Kelkheim, Germany