changeset 49267:cc4646701e99

(server-window): Customize. (server-mode): New. (server-unload-hook): Call server-start.
author Dave Love <fx@gnu.org>
date Wed, 15 Jan 2003 17:49:32 +0000
parents f4d32be2d504
children 7d1c850ef43a
files lisp/server.el
diffstat 1 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/server.el	Wed Jan 15 16:06:49 2003 +0000
+++ b/lisp/server.el	Wed Jan 15 17:49:32 2003 +0000
@@ -1,6 +1,6 @@
 ;;; server.el --- Lisp code for GNU Emacs running as server process
 
-;; Copyright (C) 1986, 87, 92, 94, 95, 96, 97, 98, 99, 2000, 2001
+;; Copyright (C) 1986, 87, 92, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
 ;;	 Free Software Foundation, Inc.
 
 ;; Author: William Sommerfeld <wesommer@athena.mit.edu>
@@ -114,17 +114,29 @@
 ;; Changing major modes should not erase this local.
 (put 'server-buffer-clients 'permanent-local t)
 
-(defvar server-window nil
-  "*The window to use for selecting Emacs server buffers.
+(defcustom server-window nil
+  "*Specification of the window to use for selecting Emacs server buffers.
 If nil, use the selected window.
+If it is a function, it should take one argument (a buffer) and
+display and select it.  A common value is `pop-to-buffer'.
+If it is a window, use that.
 If it is a frame, use the frame's selected window.
-If it is a function, it should take one argument (a buffer) and
-display and select it.  A common value is `pop-to-buffer'.")
+
+It is not meaningful to set this to a specific frame or window with Custom.
+Only programs can do so."
+  :group 'server
+  :version "21.4"
+  :type '(choice (const :tag "Use selected window"
+			:match (lambda (widget value)
+				 (not (functionp value)))
+			nil)
+		 (function-item :tag "Use pop-to-buffer" pop-to-buffer)
+		 (function :tag "Other function")))
 
 (defcustom server-temp-file-regexp "^/tmp/Re\\|/draft$"
-  "*Regexp which should match filenames of temporary files
-which are deleted and reused after each edit
-by the programs that invoke the Emacs server."
+  "*Regexp matching names of temporary files.
+These are deleted and reused after each edit by the programs that
+invoke the Emacs server."
   :group 'server
   :type 'regexp)
 
@@ -149,13 +161,15 @@
 are done with it in the server.")
 (make-variable-buffer-local 'server-existing-buffer)
 
+;; Fixme: This doesn't look secure.  If it really is, it deserves a
+;; comment, but I'd expect it to be created in a protected subdir as
+;; normal.  -- fx
 (defvar server-socket-name
   (format "/tmp/esrv%d-%s" (user-uid)
 	  (substring (system-name) 0 (string-match "\\." (system-name)))))
 
-;; If a *server* buffer exists,
-;; write STRING to it for logging purposes.
 (defun server-log (string &optional client)
+  "If a *server* buffer exists, write STRING to it for logging purposes."
   (if (get-buffer "*server*")
       (with-current-buffer "*server*"
 	(goto-char (point-max))
@@ -249,10 +263,24 @@
 		   ;; to file-name-coding-system.
 		   :coding 'raw-text)))
 	(set-default-file-modes umask)))))
+
+;;;###autoload
+(define-minor-mode server-mode
+  "Toggle Server mode.
+With ARG, turn Server mode on if ARG is positive, off otherwise.
+Server mode runs a process that accepts commands from the
+`emacsclient' program.  See `server-start' and Info node `Emacs server'."
+  :global t
+  :group 'server
+  :version "21.4"
+  ;; Fixme: Should this check for an existing server socket and do
+  ;; nothing if there is one (for multiple Emacs sessions)?
+  (server-start (not server-mode)))
+(custom-add-version 'server-mode "21.4")
 
-;Process a request from the server to edit some files.
-;Format of STRING is "PATH PATH PATH... \n"
 (defun server-process-filter (proc string)
+  "Process a request from the server to edit some files.
+PROC is the server process.  Format of STRING is \"PATH PATH PATH... \\n\"."
   (server-log string proc)
   (let ((ps (assq proc server-previous-strings)))
     (when (cdr ps)
@@ -587,6 +615,7 @@
 (global-set-key "\C-x#" 'server-edit)
 
 (defun server-unload-hook ()
+  (server-start t)
   (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
   (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function)
   (remove-hook 'kill-buffer-hook 'server-kill-buffer))