]> code.delx.au - gnu-emacs/blobdiff - lisp/server.el
entered into RCS
[gnu-emacs] / lisp / server.el
index f6518777d2ca10b980bdeee7f4ee6d986078ed22..6cc087c19bf73ec7c14ca44cb0b1d8145fd8cec0 100644 (file)
@@ -1,13 +1,17 @@
-;; Lisp code for GNU Emacs running as server process.
-;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
-;; Author William Sommerfeld, wesommer@athena.mit.edu.
+;;; server.el --- Lisp code for GNU Emacs running as server process.
+
+;; Copyright (C) 1986, 1987, 1992 Free Software Foundation, Inc.
+
+;; Author: William Sommerfeld <wesommer@athena.mit.edu>
+;; Keywords: processes
+
 ;; Changes by peck@sun.com and by rms.
 
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 1, or (at your option)
+;; the Free Software Foundation; either version 2, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; along with GNU Emacs; see the file COPYING.  If not, write to
 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
+;;; Commentary:
 
 ;;; This Lisp code is run in Emacs when it is to operate as
 ;;; a server for other processes.
 
 ;;; Load this library and do M-x server-edit to enable Emacs as a server.
-;;; Emacs runs the program ../etc/emacsserver as a subprocess
+;;; Emacs runs the program ../arch-lib/emacsserver as a subprocess
 ;;; for communication with clients.  If there are no client buffers to edit, 
 ;;; server-edit acts like (switch-to-buffer (other-buffer))
 
 ;;; When some other program runs "the editor" to edit a file,
-;;; "the editor" can be the Emacs client program ../etc/emacsclient.
+;;; "the editor" can be the Emacs client program ../lib-src/emacsclient.
 ;;; This program transmits the file names to Emacs through
 ;;; the server subprocess, and Emacs visits them and lets you edit them.
 
 ;;; the clients who are waiting for this buffer to be edited.  
 ;;; The global variable "server-clients" lists all the waiting clients,
 ;;; and which files are yet to be edited for each.
+
+;;; Code:
 \f
 (defvar server-program "emacsserver"
   "*The program to use as the edit server")
 
 (defvar server-visit-hook nil
+  "*List of hooks to call when visiting a file for the Emacs server.")
+
+(defvar server-switch-hook nil
   "*List of hooks to call when switching to a buffer for the Emacs server.")
 
 (defvar server-process nil 
@@ -88,12 +98,18 @@ When a buffer is marked as \"done\", it is removed from this list.")
 ;; 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.
+If nil, use the selected window.
+If it is a frame, use the frame's selected window.")
+
 (defvar 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.")
 
 (make-variable-buffer-local 'server-buffer-clients)
+(put 'server-buffer-clients 'permanent-local t)
 (setq-default server-buffer-clients nil)
 (or (assq 'server-buffer-clients minor-mode-alist)
     (setq minor-mode-alist (cons '(server-buffer-clients " Server") minor-mode-alist)))
@@ -114,6 +130,7 @@ by the programs that invoke the emacs server.")
        ((eq (process-status proc) 'signal)
         (server-log (message "Server subprocess killed")))))
 
+;;;###autoload
 (defun server-start (&optional leave-dead)
   "Allow this Emacs process to be a server for client processes.
 This starts a server communications subprocess through which
@@ -171,7 +188,8 @@ Prefix arg means just kill any existing server communications subprocess."
       (server-visit-files files client)
       ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
       (setq server-clients (cons client server-clients))
-      (switch-to-buffer (nth 1 client))
+      (server-switch-buffer (nth 1 client))
+      (run-hooks 'server-switch-hook)
       (message (substitute-command-keys
                "When done with a buffer, type \\[server-edit].")))))
 
@@ -244,16 +262,18 @@ are considered temporary."
        (string-match server-temp-file-regexp (buffer-file-name buffer))))
 
 (defun server-done ()
-  "Offer to save current buffer, mark it as \"done\" for clients,
-bury it, and return a suggested buffer to select next."
+  "Offer to save current buffer, mark it as \"done\" for clients.
+Then bury it, and return a suggested buffer to select next."
   (let ((buffer (current-buffer)))
     (if server-buffer-clients
        (progn
          (if (server-temp-file-p buffer)
-             (progn (save-buffer)
-                    (write-region (point-min) (point-max)
-                                  (concat buffer-file-name "~"))
-                    (kill-buffer buffer))
+             ;; For a temp file, save, and do make a non-numeric backup
+             ;; (unless make-backup-files is nil).
+             (let ((version-control nil)
+                   (buffer-backed-up nil))
+               (save-buffer)
+               (kill-buffer buffer))
            (if (and (buffer-modified-p)
                     (y-or-n-p (concat "Save file " buffer-file-name "? ")))
                (save-buffer buffer)))
@@ -265,7 +285,9 @@ If a server buffer is current, it is marked \"done\" and optionally saved.
 When all of a client's buffers are marked as \"done\", the client is notified.
 
 Temporary files such as MH <draft> files are always saved and backed up,
-no questions asked.  The variable `server-temp-file-regexp' controls
+no questions asked.  (The variable `make-backup-files', if nil, still
+inhibits a backup; you can set it locally in a particular buffer to
+prevent a backup for it.)  The variable `server-temp-file-regexp' controls
 which filenames are considered temporary.
 
 If invoked with a prefix argument, or if there is no server process running, 
@@ -281,6 +303,10 @@ starts server process and that is all.  Invoked by \\[server-edit]."
 (defun server-switch-buffer (next-buffer)
   "Switch to another buffer, preferably one that has a client.
 Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it."
+  (cond ((windowp server-window)
+        (select-window server-window))
+       ((framep server-window)
+        (select-window (frame-selected-window server-window))))
   (if next-buffer
       (if (and (bufferp next-buffer)
               (buffer-name next-buffer))
@@ -295,3 +321,7 @@ Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it."
       (switch-to-buffer (other-buffer)))))
 
 (global-set-key "\C-x#" 'server-edit)
+\f
+(provide 'server)
+
+;;; server.el ends here