(server-process-filter): Undo the quoting with
[bpt/emacs.git] / lisp / server.el
index 7649660..dbadb63 100644 (file)
@@ -185,7 +185,7 @@ Prefix arg means just kill any existing server communications subprocess."
   ;; process each line individually.
   (while (string-match "\n" string)
     (let ((request (substring string 0 (match-beginning 0)))
-         client
+         client nowait
          (files nil)
          (lineno 1))
       ;; Remove this line from STRING.
@@ -201,21 +201,34 @@ Prefix arg means just kill any existing server communications subprocess."
                (let ((arg
                       (substring request (match-beginning 0) (1- (match-end 0)))))
                  (setq request (substring request (match-end 0)))
-                 (if (string-match "\\`\\+[0-9]+\\'" arg)
-                     ;; ARG is a line number option.
-                     (setq lineno (read (substring arg 1)))
-                   ;; ARG is a file name.
-                   ;; Collapse multiple slashes to single slashes,
-                   ;; since in Emacs a multiple slash is not equiv to one.
-                   (while (string-match "//+" arg)
-                     (setq arg (replace-match "/" t t arg)))
-                   (setq files
-                         (cons (list arg lineno)
-                               files))
-                   (setq lineno 1))))
-             (server-visit-files files client)
+                 (if (string-match "\\`-nowait" arg)
+                     (setq nowait t)
+                   (if (string-match "\\`\\+[0-9]+\\'" arg)
+                       ;; ARG is a line number option.
+                       (setq lineno (read (substring arg 1)))
+                     ;; ARG is a file name.
+                     ;; Collapse multiple slashes to single slashes.
+                     (setq arg (command-line-normalize-file-name arg))
+                     (setq pos 0)
+                     ;; Undo the quoting that emacsclient does
+                     ;; for certain special characters.
+                     (while (string-match "\\\\." arg pos)
+                       (setq pos (1+ (match-beginning 0)))
+                       (let ((nextchar (aref arg pos)))
+                         (cond ((= nextchar ?\\)
+                                (setq arg (replace-match "\\" t t arg)))
+                               ((= nextchar ?-)
+                                (setq arg (replace-match "-" t t arg)))
+                               (t
+                                (setq arg (replace-match " " t t arg))))))
+                     (setq files
+                           (cons (list arg lineno)
+                                 files))
+                     (setq lineno 1)))))
+             (server-visit-files files client nowait)
              ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
-             (setq server-clients (cons client server-clients))
+             (or nowait
+                 (setq server-clients (cons client server-clients)))
              (server-switch-buffer (nth 1 client))
              (run-hooks 'server-switch-hook)
              (message (substitute-command-keys
@@ -223,9 +236,11 @@ Prefix arg means just kill any existing server communications subprocess."
   ;; Save for later any partial line that remains.
   (setq server-previous-string string))
 
-(defun server-visit-files (files client)
+(defun server-visit-files (files client &optional nowait)
   "Finds FILES and returns the list CLIENT with the buffers nconc'd.
-FILES is an alist whose elements are (FILENAME LINENUMBER)."
+FILES is an alist whose elements are (FILENAME LINENUMBER).
+NOWAIT non-nil means this client is not waiting for the results,
+so don't mark these buffers specially, just visit them normally."
   ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries.
   (let (client-record (last-nonmenu-event t) (obuf (current-buffer)))
     ;; Restore the current buffer afterward, but not using save-excursion,
@@ -251,7 +266,9 @@ FILES is an alist whose elements are (FILENAME LINENUMBER)."
              (set-buffer (find-file-noselect filen))
              (run-hooks 'server-visit-hook)))
          (goto-line (nth 1 (car files)))
-         (setq server-buffer-clients (cons (car client) server-buffer-clients))
+         (if (not nowait)
+             (setq server-buffer-clients
+                   (cons (car client) server-buffer-clients)))
          (setq client-record (cons (current-buffer) client-record))
          (setq files (cdr files)))
       (set-buffer obuf))