Function: server-delete-client

server-delete-client is a byte-compiled function defined in server.el.gz.

Signature

(server-delete-client PROC &optional NOFRAME)

Documentation

Delete PROC, including its buffers, terminals and frames.

If NOFRAME is non-nil, let the frames live. If NOFRAME is the symbol 'dont-kill-client, also don't delete PROC or its terminals, just kill its buffers: this is for when find-alternate-file calls this via kill-buffer-hook. Updates server-clients.

Source Code

;; Defined in /usr/src/emacs/lisp/server.el.gz
(defun server-delete-client (proc &optional noframe)
  "Delete PROC, including its buffers, terminals and frames.
If NOFRAME is non-nil, let the frames live.
If NOFRAME is the symbol \\='dont-kill-client, also don't
delete PROC or its terminals, just kill its buffers: this is
for when `find-alternate-file' calls this via `kill-buffer-hook'.
Updates `server-clients'."
  (server-log (concat "server-delete-client" (if noframe " noframe")) proc)
  ;; Force a new lookup of client (prevents infinite recursion).
  (when (memq proc server-clients)
    (let ((buffers (process-get proc 'buffers)))

      ;; Kill the client's buffers.
      (dolist (buf buffers)
	(when (buffer-live-p buf)
	  (with-current-buffer buf
	    ;; Kill the buffer if necessary.
	    (when (and (equal server-buffer-clients
			      (list proc))
		       (or (and server-kill-new-buffers
				(not server-existing-buffer))
			   (server-temp-file-p))
		       (not (buffer-modified-p)))
	      (let (flag)
		(unwind-protect
		    (progn (setq server-buffer-clients nil)
			   (kill-buffer (current-buffer))
			   (setq flag t))
		  (unless flag
		    ;; Restore clients if user pressed C-g in `kill-buffer'.
		    (setq server-buffer-clients (list proc)))))))))

      ;; Delete the client's frames.
      (unless noframe
	(dolist (frame (frame-list))
	  (when (and (frame-live-p frame)
		     (equal proc (frame-parameter frame 'client)))
	    ;; Prevent `server-handle-delete-frame' from calling us
	    ;; recursively.
	    (set-frame-parameter frame 'client nil)
	    (delete-frame frame))))

      (or (eq noframe 'dont-kill-client)
          (setq server-clients (delq proc server-clients)))

      ;; Delete the client's tty, except on Windows (both GUI and
      ;; console), where there's only one terminal and does not make
      ;; sense to delete it, or if we are explicitly told not.
      (unless (or (eq system-type 'windows-nt)
                  ;; 'find-alternate-file' caused the last client
                  ;; buffer to be killed, but we will reuse the client
                  ;; for another buffer.
                  (eq noframe 'dont-kill-client)
                  (process-get proc 'no-delete-terminal))
	(let ((terminal (process-get proc 'terminal)))
	  ;; Only delete the terminal if it is non-nil.
	  (when (and terminal (eq (terminal-live-p terminal) t))
	    (delete-terminal terminal))))

      ;; Delete the client's process (or don't).
      (unless (eq noframe 'dont-kill-client)
        (if (eq (process-status proc) 'open)
	    (delete-process proc))
        (server-log "Deleted" proc)))))