[gnu.emacs.bug] Minor

gore@ODDJOB.UCHICAGO.EDU (Jacob Gore) (10/08/88)

These are some changes that I think should be made in server.el for the
next release (we are using them locally now):

	1.  Addition of server-mode-hook;
	2.  An easy way to have client buffers deleted automatically
	    when the client is done;
	3.  Some clarifications in the comments.

Change #1 does not seem controversial at all -- I was very surprised that
there was no such hook.  For example, I use it to select a default major
mode other than Fundamental, and to locally bind server-edit to C-x C-c
instead of C-x #.

Change #2 is suggested for three reasons:

	1.  Aesthetic: if you use the server frequently on different files
	    (especially from a program that likes to edit temporary files),
	    your buffer list gets cluttered with old client buffers that will
	    eventually be deleted by hand anyway.

	2.  It allows you to emulate a "start-for-every-file" type editor more
	    accurately: the question of whether a buffer needs to be reverted
	    or not does not come into play at all -- very convenient in cases
	    where the client program calls emacsclient on a temp-file, then
	    modifies that temp-file, then calls emacsclient on it again.

	3.  It is a trivial change (not a reason in itself, but...).

Change #3 should be studied by somebody who works on non-4.2BSD
environment.  I *think* that my comments are more accurate, but I can see
that they may not be portable -- especially one about running server on one
terminal and client on another.  Also, it's not my place to add 1988 to the
Copyright notice, but I did it as long as I was at it...

Jacob Gore				Gore@EECS.NWU.Edu
Northwestern Univ., EECS Dept.		{oddjob,gargoyle,att}!nucsrl!gore

(This patch should be applied to server.el of 18.52.)

*** /usr/local/lib/emacs/lisp/server.el	Thu Aug  4 18:38:06 1988
--- server.el	Fri Oct  7 12:39:55 1988
***************
*** 1,5 ****
  ;; Lisp code for GNU Emacs running as server process.
! ;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.
  ;; Author William Sommerfeld, wesommer@athena.mit.edu.
  ;; Changes by peck@sun.com and by rms.
  
--- 1,5 ----
  ;; Lisp code for GNU Emacs running as server process.
! ;; Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
  ;; Author William Sommerfeld, wesommer@athena.mit.edu.
  ;; Changes by peck@sun.com and by rms.
  
***************
*** 45,63 ****
  ;;; Your editing commands and Emacs's display output go to and from
  ;;; the terminal in the usual way.  Thus, server operation is possible
  ;;; only when Emacs can talk to the terminal at the time you invoke
! ;;; the client.  This is possible in two cases:
  
  ;;; 1. On a window system, where Emacs runs in one window and the
  ;;; program that wants to use "the editor" runs in another.
  
! ;;; 2. When the program that wants to use "the editor" is running
  ;;; as a subprocess of Emacs.
  
  ;;; The buffer local variable "server-buffer-clients" lists 
  ;;; 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.
  
  (defvar server-program "server"
    "*The program to use as the edit server")
  
--- 45,84 ----
  ;;; Your editing commands and Emacs's display output go to and from
  ;;; the terminal in the usual way.  Thus, server operation is possible
  ;;; only when Emacs can talk to the terminal at the time you invoke
! ;;; the client.  This is possible in four cases:
  
  ;;; 1. On a window system, where Emacs runs in one window and the
  ;;; program that wants to use "the editor" runs in another.
  
! ;;; 2. On a multi-terminal system, where Emacs runs on one terminal and the
! ;;; program that wants to use "the editor" runs on another.
! 
! ;;; 3. When the program that wants to use "the editor" is running
  ;;; as a subprocess of Emacs.
  
+ ;;; 4. On a system with job control, when Emacs is suspended, the program
+ ;;; that wants to use "the editor" will stop and display
+ ;;; "Waiting for Emacs...".  It can then be suspended, and Emacs can be
+ ;;; brought into the foreground for editing.  When done editing, Emacs is
+ ;;; suspended again, and the client program is brought into the foreground.
+ 
  ;;; The buffer local variable "server-buffer-clients" lists 
  ;;; 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.
+ 
+ ;;; If the global variable "server-kill-buffers-when-done" is non-nil,
+ ;;; the buffer in which the client editing was performed is deleted.
+ ;;; This can be used for general housekeeping purposes.  It is also
+ ;;; useful when the client program frequently edits the file that Emacs
+ ;;; edits too -- it avoids the guesswork about whether the buffer needs
+ ;;; to be reverted or not.
  
+ (defconst server-kill-buffers-when-done nil
+   "*If non-nil, every \"Done\" buffer is deleted
+ after it is passed back to the client.")
+ 
  (defvar server-program "server"
    "*The program to use as the edit server")
  
***************
*** 147,152 ****
--- 168,175 ----
        ;; CLIENT is now a list (CLIENTNUM BUFFERS...)
        (setq server-clients (cons client server-clients))
        (switch-to-buffer (nth 1 client))
+       ;; Call hook here in case it redefines \[server-edit].
+       (run-hooks 'server-mode-hook)
        (message (substitute-command-keys
  		"When done with a buffer, type \\[server-edit].")))))
  
***************
*** 204,210 ****
  	(save-excursion
  	  (set-buffer buffer)
  	  (setq server-buffer-clients nil)))
!     (bury-buffer buffer)
      next-buffer))
  
  (defun mh-draft-p (buffer)
--- 227,235 ----
  	(save-excursion
  	  (set-buffer buffer)
  	  (setq server-buffer-clients nil)))
!     (if server-kill-buffers-when-done
! 	(kill-buffer buffer)
!       (bury-buffer buffer))
      next-buffer))
  
  (defun mh-draft-p (buffer)