all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] * server.el (server-process-filter): Use `command-line-args-left'
@ 2007-11-23 20:18 David Kastrup
  2007-11-23 23:02 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: David Kastrup @ 2007-11-23 20:18 UTC (permalink / raw)
  To: emacs-devel

---
Hi, the following change is intended for making emacsclient operation
more similar to the Emacs startup operation.  There are several things
to be noted: I am not sure this does the right thing with empty
arguments, and it would appear that the Emacs client changed -eval x y z
into -eval x -eval y -eval z when parsing.  Since that is different from
the operation on the command line, I have no idea what this should be
good for.  So basically this patch is a first step in the direction of
making emacsclient and emacs more similar.  Perhaps at some point, the
command line parsing code might largely be shared (server.el just
filling in command-line-args-left and calling the normal option parser,
which should basically then be made to ignore startup options it can no
longer sensibly execute).

Comments?

 lisp/ChangeLog |    2 +
 lisp/server.el |   72 +++++++++++++++++++++++++------------------------------
 2 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 38c3ee8..64b2876 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -3896,6 +3896,8 @@
 
 2007-09-30  David Kastrup  <dak@gnu.org>
 
+	* server.el (server-process-filter): Use `command-line-args-left'
+
 	* startup.el (argv): Alias for `command-line-args-left' to use as
 	`(pop argv)' inside of --eval command sequences.  Allows for
 	passing shell commands into Emacs verbatim without need for Lisp
diff --git a/lisp/server.el b/lisp/server.el
index 329010c..779ba04 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -811,17 +811,18 @@ The following commands are accepted by the client:
                 tty-type             ;string.
 		(files nil)
 		(lineno 1)
-		(columnno 0))
+		(columnno 0)
+		command-line-args-left
+		arg)
 	    ;; Remove this line from STRING.
 	    (setq string (substring string (match-end 0)))
-	    (while (string-match " *[^ ]* " request)
-	      (let ((arg (substring request (match-beginning 0)
-                                    (1- (match-end 0)))))
-		(setq request (substring request (match-end 0)))
+	    (setq command-line-args-left
+		  (mapcar 'server-unquote-arg (split-string request " " t)))
+	    (while (setq arg (pop command-line-args-left))
 		(cond
 		 ;; -version CLIENT-VERSION: obsolete at birth.
-		 ((and (equal "-version" arg) (string-match "[^ ]+ " request))
-                  (setq request (substring request (match-end 0))))
+		 ((and (equal "-version" arg) command-line-args-left)
+		  (pop command-line-args-left))
 
 		 ;; -nowait:  Emacsclient won't wait for a result.
 		 ((equal "-nowait" arg) (setq nowait t))
@@ -831,10 +832,8 @@ The following commands are accepted by the client:
 
 		 ;; -display DISPLAY:
 		 ;; Open X frames on the given display instead of the default.
-		 ((and (equal "-display" arg)
-                       (string-match "\\([^ ]*\\) " request))
-                  (setq display (match-string 1 request))
-		  (setq request (substring request (match-end 0))))
+		 ((and (equal "-display" arg) command-line-args-left)
+		  (setq display (pop command-line-args-left)))
 
 		 ;; -window-system:  Open a new X frame.
 		 ((equal "-window-system" arg)
@@ -863,33 +862,32 @@ The following commands are accepted by the client:
 
 		 ;; -ignore COMMENT:  Noop; useful for debugging emacsclient.
 		 ;; (The given comment appears in the server log.)
-		 ((and (equal "-ignore" arg) (string-match "[^ ]* " request))
-		  (setq dontkill t
-			request (substring request (match-end 0))))
+		 ((and (equal "-ignore" arg) command-line-args-left
+		  (setq dontkill t)
+		  (pop command-line-args-left)))
 
 		 ;; -tty DEVICE-NAME TYPE:  Open a new tty frame at the client.
 		 ((and (equal "-tty" arg)
-                       (string-match "\\([^ ]*\\) \\([^ ]*\\) " request))
-                  (setq tty-name (match-string 1 request))
-                  (setq tty-type (match-string 2 request))
-                  (setq dontkill t)
-                  (setq request (substring request (match-end 0))))
+                       (cdr command-line-args-left))
+                  (setq tty-name (pop command-line-args-left)
+			tty-type (pop command-line-args-left)
+			dontkill t))
 
 		 ;; -position LINE[:COLUMN]:  Set point to the given
 		 ;;  position in the next file.
 		 ((and (equal "-position" arg)
-                       (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)? "
-                                     request))
-		  (setq lineno (string-to-number (match-string 1 request))
+		       command-line-args-left
+                       (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?"
+                                     (car command-line-args-left)))
+		  (setq arg (pop command-line-args-left))
+		  (setq lineno (string-to-number (match-string 1 arg))
 			columnno (if (null (match-end 2)) 0
-                                   (string-to-number (match-string 2 request)))
-			request (substring request (match-end 0))))
+                                   (string-to-number (match-string 2 arg)))))
 
 		 ;; -file FILENAME:  Load the given file.
 		 ((and (equal "-file" arg)
-                       (string-match "\\([^ ]+\\) " request))
-		  (let ((file (server-unquote-arg (match-string 1 request))))
-		    (setq request (substring request (match-end 0)))
+		       command-line-args-left)
+		  (let ((file (pop command-line-args-left)))
 		    (if coding-system
 			(setq file (decode-coding-string file coding-system)))
 		    (setq file (command-line-normalize-file-name file))
@@ -901,10 +899,8 @@ The following commands are accepted by the client:
 
 		 ;; -eval EXPR:  Evaluate a Lisp expression.
 		 ((and (equal "-eval" arg)
-                       (string-match "\\([^ ]+\\) " request))
-		  (lexical-let ((expr (server-unquote-arg
-                                       (match-string 1 request))))
-		    (setq request (substring request (match-end 0)))
+                       command-line-args-left)
+		  (lexical-let ((expr (pop command-line-args-left)))
 		    (if coding-system
 			(setq expr (decode-coding-string expr coding-system)))
                     (push (lambda () (server-eval-and-print expr proc))
@@ -913,24 +909,22 @@ The following commands are accepted by the client:
 			  columnno 0)))
 
 		 ;; -env NAME=VALUE:  An environment variable.
-		 ((and (equal "-env" arg) (string-match "\\([^ ]+\\) " request))
-		  (let ((var (server-unquote-arg (match-string 1 request))))
+		 ((and (equal "-env" arg) command-line-args-left)
+		  (let ((var (pop command-line-args-left)))
 		    ;; XXX Variables should be encoded as in getenv/setenv.
-		    (setq request (substring request (match-end 0)))
                     (process-put proc 'env
                                  (cons var (process-get proc 'env)))))
 
 		 ;; -dir DIRNAME:  The cwd of the emacsclient process.
-		 ((and (equal "-dir" arg) (string-match "\\([^ ]+\\) " request))
-		  (setq dir (server-unquote-arg (match-string 1 request)))
-		  (setq request (substring request (match-end 0)))
+		 ((and (equal "-dir" arg) command-line-args-left)
+		  (setq dir (pop command-line-args-left))
 		  (if coding-system
 		      (setq dir (decode-coding-string dir coding-system)))
 		  (setq dir (command-line-normalize-file-name dir)))
 
 		 ;; Unknown command.
-		 (t (error "Unknown command: %s" arg)))))
-
+		 (t (error "Unknown command: %s" arg))))
+            
             (setq frame
                   (case tty-name
                     ((nil) (if display (server-select-display display)))
-- 
1.5.3.6.733.g13ee3

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

end of thread, other threads:[~2007-11-23 23:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-23 20:18 [PATCH] * server.el (server-process-filter): Use `command-line-args-left' David Kastrup
2007-11-23 23:02 ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.