- (setq string (substring string (match-end 0)))
- (while (string-match "[^ ]+ " string)
- (let ((arg
- (substring string (match-beginning 0) (1- (match-end 0)))))
- (setq string (substring string (match-end 0)))
- (if (string-match "\\`\\+[0-9]+\\'" arg)
- (setq lineno (read (substring arg 1)))
- (setq files
- (cons (list arg lineno)
- files))
- (setq lineno 1))))
- (server-visit-files files client)
- ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
- (setq server-clients (cons client server-clients))
- (server-switch-buffer (nth 1 client))
- (run-hooks 'server-switch-hook)
- (message (substitute-command-keys
- "When done with a buffer, type \\[server-edit].")))))
-
-(defun server-visit-files (files client)
+ ;; Remove this line from STRING.
+ (setq string (substring string (match-end 0)))
+ (if (string-match "^Error: " request)
+ (message "Server error: %s" (substring request (match-end 0)))
+ (if (string-match "^Client: " request)
+ (progn
+ (setq request (substring request (match-end 0)))
+ (setq client (list (substring request 0 (string-match " " request))))
+ (setq request (substring request (match-end 0)))
+ (while (string-match "[^ ]+ " request)
+ (let ((arg
+ (substring request (match-beginning 0) (1- (match-end 0))))
+ (pos 0))
+ (setq request (substring request (match-end 0)))
+ (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))
+ ;; 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...)
+ (or nowait
+ (setq server-clients (cons client server-clients)))
+ (server-switch-buffer (nth 1 client))
+ (run-hooks 'server-switch-hook)
+ (message (substitute-command-keys
+ "When done with a buffer, type \\[server-edit]")))))))
+ ;; Save for later any partial line that remains.
+ (setq server-previous-string string))
+
+(defun server-visit-files (files client &optional nowait)