From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Mauger Newsgroups: gmane.emacs.devel Subject: Re: Proposal: emacsclient --readonly Date: Mon, 25 Mar 2013 19:56:06 -0700 (PDT) Message-ID: <1364266566.22342.YahooMailNeo@web160905.mail.bf1.yahoo.com> References: <87zjxtq304.fsf@michael-laptop.hsd1.ma.comcast.net> <1364142142.92134.YahooMailNeo@web160904.mail.bf1.yahoo.com> Reply-To: Michael Mauger NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1364266582 25168 80.91.229.3 (26 Mar 2013 02:56:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Mar 2013 02:56:22 +0000 (UTC) Cc: "emacs-devel@gnu.org" To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 26 03:56:48 2013 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 1UKK47-00066u-3j for ged-emacs-devel@m.gmane.org; Tue, 26 Mar 2013 03:56:47 +0100 Original-Received: from localhost ([::1]:48553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKK3j-0000Bm-CP for ged-emacs-devel@m.gmane.org; Mon, 25 Mar 2013 22:56:23 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKK3b-0000B5-A9 for emacs-devel@gnu.org; Mon, 25 Mar 2013 22:56:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKK3U-0007qU-Fb for emacs-devel@gnu.org; Mon, 25 Mar 2013 22:56:15 -0400 Original-Received: from nm39-vm7.bullet.mail.bf1.yahoo.com ([72.30.239.151]:28835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKK3U-0007pn-1Q for emacs-devel@gnu.org; Mon, 25 Mar 2013 22:56:08 -0400 Original-Received: from [98.139.212.149] by nm39.bullet.mail.bf1.yahoo.com with NNFMP; 26 Mar 2013 02:56:07 -0000 Original-Received: from [98.139.212.211] by tm6.bullet.mail.bf1.yahoo.com with NNFMP; 26 Mar 2013 02:56:07 -0000 Original-Received: from [127.0.0.1] by omp1020.mail.bf1.yahoo.com with NNFMP; 26 Mar 2013 02:56:07 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 68118.30058.bm@omp1020.mail.bf1.yahoo.com Original-Received: (qmail 23771 invoked by uid 60001); 26 Mar 2013 02:56:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1364266566; bh=rvlBJst9+ul+tNw6owt/RL1LuW5C5kmaJp8JAlf3+bM=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-RocketYMMF:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=KFjvWus7JvjkDzHpP+BR/sw/dPBTd/QhQCXcgCUyQqCXaQdnrsad9maPLypwBvjK5eBeNqhXU8pAUyeu7c9R8tc4qkVUY15bJVqSGVCxyIGnvsEy8FAxygEcm7cHLCus/4IA0bYO5xBe5TwL+X9w9yQp7/zhv+xOYCM2xEKNdQM= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-RocketYMMF:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=AClb6QQfa88A0WrlCWU/vwU6nB94G03Ojjrk1AuJNXQQn4E8X8+wNofXZIzEf20cPP/Ey7B670RsfP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PiArKysgbGlzcC9zZXJ2ZXIuZWzCoMKgwqAgMjAxMy0wMy0yNSAxMzowNzo0NCABMAEBAQE- X-RocketYMMF: mmaug X-Mailer: YahooMailWebService/0.8.139.530 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 72.30.239.151 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:158184 Archived-At: > From: Stefan Monnier =0A=0A>=A0=0A> My suggesti= on is to try and limit the server.el=A0change to=0A> something like the pat= ch below.=0A> =0A> =3D=3D=3D modified file 'lisp/server.el'=0A> --- lisp/se= rver.el=A0=A0=A0 2013-02-13 04:31:09 +0000=0A> +++ lisp/server.el=A0=A0=A0 = 2013-03-25 13:07:44 +0000=0A> @@ -909,6 +909,12 @@=0A> =A0 =A0 (process-pu= t proc 'continuation nil)=0A> =A0 =A0 (if continuation (ignore-errors (fun= call continuation)))))=0A> =0A> +(defvar server-custom-option-function #'id= entity=0A> +=A0 "Function to process additional emacsclient arguments.=0A> = +The function is called with a single argument (a list of args received=0A>= +from emacsclient) and returns the list of args left to process.=0A> +The = easiest way to modify this variable is through `add-function'.")=0A> +=0A> = (cl-defun server-process-filter (proc string)=0A> =A0 "Process a request f= rom the server to edit some files.=0A> PROC is the server process.=A0 STRIN= G consists of a sequence of=0A> @@ -1067,7 +1076,8 @@=0A> =A0=A0=A0 =A0 =A0= (setq string (substring string (match-end 0)))=0A> =A0=A0=A0 =A0 =A0 (setq= args-left=0A> =A0=A0=A0 =A0=A0=A0 =A0 (mapcar 'server-unquote-arg (split-s= tring request " " =0A> t)))=0A> -=A0=A0=A0 =A0 =A0 (while args-left=0A> += =A0=A0=A0 =A0 =A0 (while (setq arg-left (funcall server-custom-option-funct= ion=0A> +=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 args-left))=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (pcase (p= op args-left)=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; -version CLIENT-VERSI= ON: obsolete at birth.=0A> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (`"-version" (p= op args-left))=0A> =0A=0ASo with this structure, how would I implement the = --readonly custom=0Aargument?=0A=0AMy guess is that the server-custom-optio= n-function would scan the=0Aincoming list of options for the -nowait entry = because that will=0Adetermine our exit action. =A0However, we will leave th= e entry in place=0Abecause it needs the standard processing. =A0We will the= n look for the=0A--readonly entry and record that we want to view files rat= her than=0Aedit them. =A0We will then remove the --readonly entry from the = list to=0Aallow the remainder of the processing to continue.=0A=0AWe can on= ly record these settings at this point because the files have=0Anot been ac= tually opened yet. =A0And then we need to attach ourselves to=0Athe server-= visit-hook possibly to actually activate the readonly=0Abehavior. =A0Or we = could essentially duplicate the server processing by=0Aconsuming all of the= arguments and replicating their actions with the=0Awrinkles we wish to int= roduce which is obviously not a great solution.=0A=0ASo it looks with the s= olution may be more flexible but requires global=0Avariables specific to th= e feature and two hook functions to implement=0Ait. My goal was for a solut= ion the declares the options we want to add=0Aand somewhat automate the par= sing and validation of the option value=0Aso that custom options behave as = other command line arguments do. =A0It=0Athen provides a handler function t= hat implements the feature either=0Aglobally or on a per-buffer basis. =A0W= ith this design, features could=0Abe added to emacsclient by loading a libr= ary and adding an entry to a=0Alist that defines the syntax and handling.= =0A=0AI have reworked my code to use a single list with option-name, handle= r=0Afunction, and value-predicate. =A0The result is that we could implement= =0Amodules in ELPA that would enhance emacsclient with new options=0Awithou= t requiring the modules to be integrated together into a single=0Afunction.= =A0The readonly feature becomes about 10 lines of code; easily=0Amaintaine= d and separate from any other features.=0A=0A-- Michael=0A