- (setq string (substring string (match-end 0)))
- (if (string-match "^Error: " request)
- (message (concat "Server error: " (substring request (match-end 0))))
- (if (string-match "^Client: " request)
- (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)))))
- (setq request (substring request (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]")))))
+ (setq string (substring string (match-end 0)))
+ (setq client (cons proc nil))
+ (while (string-match "[^ ]* " request)
+ (let ((arg (substring request (match-beginning 0) (1- (match-end 0)))))
+ (setq request (substring request (match-end 0)))
+ (cond
+ ((equal "-nowait" arg) (setq nowait t))
+ ((equal "-eval" arg) (setq eval t))
+ ((and (equal "-display" arg) (string-match "\\([^ ]*\\) " request))
+ (let ((display (server-unquote-arg (match-string 1 request))))
+ (setq request (substring request (match-end 0)))
+ (condition-case err
+ (setq tmp-frame (server-select-display display))
+ (error (process-send-string proc (nth 1 err))
+ (setq request "")))))
+ ;; ARG is a line number option.
+ ((string-match "\\`\\+[0-9]+\\'" arg)
+ (setq lineno (string-to-number (substring arg 1))))
+ ;; ARG is line number:column option.
+ ((string-match "\\`+\\([0-9]+\\):\\([0-9]+\\)\\'" arg)
+ (setq lineno (string-to-number (match-string 1 arg))
+ columnno (string-to-number (match-string 2 arg))))
+ (t
+ ;; Undo the quoting that emacsclient does
+ ;; for certain special characters.
+ (setq arg (server-unquote-arg arg))
+ ;; Now decode the file name if necessary.
+ (if coding-system
+ (setq arg (decode-coding-string arg coding-system)))
+ (if eval
+ (let* (errorp
+ (v (condition-case errobj
+ (eval (car (read-from-string arg)))
+ (error (setq errorp t) errobj))))
+ (when v
+ (with-temp-buffer
+ (let ((standard-output (current-buffer)))
+ (if errorp (princ "error: "))
+ (pp v)
+ ;; Suppress the error rose when the pipe to PROC is closed.
+ (condition-case err
+ (process-send-region proc (point-min) (point-max))
+ (file-error nil)
+ (error nil))
+ ))))
+ ;; ARG is a file name.
+ ;; Collapse multiple slashes to single slashes.
+ (setq arg (command-line-normalize-file-name arg))
+ (push (list arg lineno columnno) files))
+ (setq lineno 1)
+ (setq columnno 0)))))
+ (when files
+ (run-hooks 'pre-command-hook)
+ (server-visit-files files client nowait)
+ (run-hooks 'post-command-hook))
+ ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
+ (if (null (cdr client))
+ ;; This client is empty; get rid of it immediately.
+ (progn
+ (delete-process proc)
+ (server-log "Close empty client" proc))
+ ;; We visited some buffer for this client.
+ (or nowait (push client server-clients))
+ (unless (or isearch-mode (minibufferp))
+ (server-switch-buffer (nth 1 client))
+ (run-hooks 'server-switch-hook)
+ (unless nowait
+ (message "%s" (substitute-command-keys
+ "When done with a buffer, type \\[server-edit]")))))
+ ;; If the temporary frame is still the selected frame, make it
+ ;; real. If not (which can happen if the user's customizations
+ ;; call pop-to-buffer etc.), delete it to avoid preserving the
+ ;; connection after the last real frame is deleted.
+ (if tmp-frame
+ (if (eq (selected-frame) tmp-frame)
+ (set-frame-parameter tmp-frame 'visibility t)
+ (delete-frame tmp-frame)))))