Function: server-execute
server-execute is a byte-compiled function defined in server.el.gz.
Signature
(server-execute PROC FILES NOWAIT COMMANDS EVALEXPRS DONTKILL FRAME TTY-NAME)
Source Code
;; Defined in /usr/src/emacs/lisp/server.el.gz
(defun server-execute (proc files nowait commands evalexprs dontkill frame tty-name)
;; This is run from timers and process-filters, i.e. "asynchronously".
;; But w.r.t the user, this is not really asynchronous since the timer
;; is run after 0s and the process-filter is run in response to the
;; user running `emacsclient'. So it is OK to override the
;; inhibit-quit flag, which is good since `evalexprs' (as well as
;; find-file-noselect via the major-mode) can run arbitrary code,
;; including code that needs to wait.
(with-local-quit
(condition-case err
(let ((buffers (server-visit-files files proc nowait))
;; On Android, the Emacs server generally can't provide
;; feedback to the user except by means of dialog boxes,
;; which are displayed in the GUI emacsclient wrapper.
(use-dialog-box-override (featurep 'android)))
(mapc 'funcall (nreverse commands))
(let ((server-eval-args-left (nreverse evalexprs)))
(while server-eval-args-left
(server-eval-and-print (pop server-eval-args-left) proc)))
;; If we were told only to open a new client, obey
;; `initial-buffer-choice' if it specifies a file
;; or a function.
(unless (or files commands evalexprs)
(let ((buf
(cond ((stringp initial-buffer-choice)
(find-file-noselect initial-buffer-choice))
((functionp initial-buffer-choice)
(funcall initial-buffer-choice)))))
(switch-to-buffer
(if (buffer-live-p buf) buf (get-scratch-buffer-create))
'norecord)))
;; Delete the client if necessary.
(cond
(nowait
;; Client requested nowait; return immediately.
(server-log "Close nowait client" proc)
(server-delete-client proc))
((and (not dontkill) (null buffers))
;; This client is empty; get rid of it immediately.
(server-log "Close empty client" proc)
(server-delete-client proc)))
(cond
((or isearch-mode (minibufferp))
nil)
((and frame (null buffers))
(run-hooks 'server-after-make-frame-hook)
(when server-client-instructions
(message "%s"
(substitute-command-keys
"When done with this frame, type \\[delete-frame]"))))
((not (null buffers))
(run-hooks 'server-after-make-frame-hook)
(server-switch-buffer
(car buffers) nil (cdr (car files))
;; When triggered from "emacsclient -c", we popped up a
;; new frame. Ensure that we switch to the requested
;; buffer in that frame, and not in some other frame
;; where it may be displayed.
(plist-get (process-plist proc) 'frame))
(run-hooks 'server-switch-hook)
(when (and (not nowait)
server-client-instructions)
(message "%s"
(substitute-command-keys
"When done with a buffer, type \\[server-edit]")))))
(when (and frame (null tty-name))
(server-unselect-display frame)))
((quit error)
(when (eq (car err) 'quit)
(message "Quit emacsclient request"))
(server-return-error proc err)))))