Function: server-apply-stop-automatically

server-apply-stop-automatically is a byte-compiled function defined in server.el.gz.

Signature

(server-apply-stop-automatically)

Documentation

Apply the current value of server-stop-automatically(var)/server-stop-automatically(fun).

This function adds or removes the necessary helpers to manage stopping the Emacs server automatically, depending on the whether the server is running or not. This function only applies when running Emacs as a daemon.

Source Code

;; Defined in /usr/src/emacs/lisp/server.el.gz
(defun server-apply-stop-automatically ()
  "Apply the current value of `server-stop-automatically'.
This function adds or removes the necessary helpers to manage
stopping the Emacs server automatically, depending on the whether
the server is running or not.  This function only applies when
running Emacs as a daemon."
  (when (daemonp)
    (let (empty-timer-p delete-frame-p)
      (when server-process
        (pcase server-stop-automatically
          ('empty        (setq empty-timer-p t))
          ('delete-frame (setq delete-frame-p t))))
      ;; Start or stop the timer.
      (if empty-timer-p
          (unless server-stop-automatically--timer
            (setq server-stop-automatically--timer
                  (run-with-timer
                   10 2
		   #'server-stop-automatically--maybe-kill-emacs)))
        (when server-stop-automatically--timer
          (cancel-timer server-stop-automatically--timer)
          (setq server-stop-automatically--timer nil)))
      ;; Add or remove the delete-frame hook.
      (if delete-frame-p
          (add-hook 'delete-frame-functions
		    #'server-stop-automatically--handle-delete-frame)
        (remove-hook 'delete-frame-functions
                     #'server-stop-automatically--handle-delete-frame))))
  ;; Return the current value of `server-stop-automatically'.
  server-stop-automatically)