emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proposal: emacsclient --readonly


From: Stefan Monnier
Subject: Re: Proposal: emacsclient --readonly
Date: Mon, 25 Mar 2013 09:15:11 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> I don't understand your comment--the `server-custom-option-list' 
> variable is the list of options for parsing; the 
> `server-custom-option-functions' variable is the list of functions to 
> handle the options.  I can certainly see how we can merge these two
> but I'm still confused by your comment.

> If we were to merge the variables, we could end up with a list with 
> entries like the following:

>    ("OPTION" {PRED|t|nil|string-only} HANDLER)

My proposal is that you don't declare which function handles
which argument.  Just use a single server-custom-option-function which
is called regardless of which arguments were received and can do
anything it likes with them.

> I don't understand what arguments "takes the list of arguments and 
> returns a new list of arguments" you are referring to?  Do you mean
> parsing the command line args and removing the ones that it is 
> processing?

Yes.

>  I had looked at that a little, but figured I'd let the parsing
> be done in C in emacsclient and just forward the unrecognized to lisp.

Hmm... I don't understand what you're saying here.  I'm only talking
about the server.el side, and AFAICT you also were only talking about
the server.el side, since the client side does not have access to
Elisp customizations.

But yes, clearly the C side would do the parsing it does now, except
that it would additionally pass through any unrecognized argument.

> But even if we assemble the custom args into a list and try to handle
> them in lisp, how does that simplify the lisp side of the fence?

The server.el code already turns the string received from emacsclient
into a list of strings.  My suggestion is to try and limit the server.el
change to something like the patch below.


        Stefan


=== modified file 'lisp/server.el'
--- lisp/server.el      2013-02-13 04:31:09 +0000
+++ lisp/server.el      2013-03-25 13:07:44 +0000
@@ -909,6 +909,12 @@
     (process-put proc 'continuation nil)
     (if continuation (ignore-errors (funcall continuation)))))
 
+(defvar server-custom-option-function #'identity
+  "Function to process additional emacsclient arguments.
+The function is called with a single argument (a list of args received
+from emacsclient) and returns the list of args left to process.
+The easiest way to modify this variable is through `add-function'.")
+
 (cl-defun server-process-filter (proc string)
   "Process a request from the server to edit some files.
 PROC is the server process.  STRING consists of a sequence of
@@ -1067,7 +1076,8 @@
            (setq string (substring string (match-end 0)))
            (setq args-left
                  (mapcar 'server-unquote-arg (split-string request " " t)))
-           (while args-left
+           (while (setq arg-left (funcall server-custom-option-function
+                                           args-left))
               (pcase (pop args-left)
                 ;; -version CLIENT-VERSION: obsolete at birth.
                 (`"-version" (pop args-left))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]