annotate lisp/gnuserv.el @ 290:c9fe270a4101 r21-0b43

Import from CVS: tag r21-0b43
author cvs
date Mon, 13 Aug 2007 10:36:47 +0200
parents 57709be46d1b
children 8e84bee8ddd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
1 ;;; gnuserv.el --- Lisp interface code between Emacs and gnuserv
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
2 ;; Copyright (C) 1989-1997 Free Software Foundation, Inc.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
3
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
4 ;; Version: 3.11
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
5 ;; Author: Andy Norman (ange@hplb.hpl.hp.com), originally based on server.el
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
6 ;; Hrvoje Niksic <hniksic@srce.hr>
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
7 ;; Maintainer: Jan Vroonhof <vroonhof@math.ethz.ch>,
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
8 ;; Hrvoje Niksic <hniksic@srce.hr>
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
9 ;; Keywords: environment, processes, terminals
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
10
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
12
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify it
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
14 ;; under the terms of the GNU General Public License as published by
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
16 ;; any later version.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
17
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful, but
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
21 ;; General Public License for more details.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
22
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
25 ;; Free Software Foundation, 59 Temple Place - Suite 330,
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
27
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
28 ;;; Synched up with: Not in FSF.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
29
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
30 ;;; Commentary:
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
31
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
32 ;; Gnuserv is run when Emacs needs to operate as a server for other
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
33 ;; processes. Specifically, any number of files can be attached for
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
34 ;; editing to a running XEmacs process using the `gnuclient' program.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
35
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
36 ;; Use `M-x gnuserv-start' to start the server and `gnuclient files'
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
37 ;; to load them to XEmacs. When you are done with a buffer, press
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
38 ;; `C-x #' (`M-x gnuserv-edit'). You can put (gnuserv-start) to your
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
39 ;; .emacs, and enable `gnuclient' as your Unix "editor". When all the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
40 ;; buffers for a client have been edited and exited with
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
41 ;; `gnuserv-edit', the client "editor" will return to the program that
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
42 ;; invoked it.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
43
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
44 ;; Your editing commands and Emacs' display output go to and from the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
45 ;; terminal or X display in the usual way. If you are running under
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
46 ;; X, a new X frame will be open for each gnuclient. If you are on a
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
47 ;; TTY, this TTY will be attached as a new device to the running
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
48 ;; XEmacs, and will be removed once you are done with the buffer.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
49
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
50 ;; To evaluate a Lisp form in a running Emacs, use the `-eval'
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
51 ;; argument of gnuclient. To simplify this, we provide the `gnudoit'
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
52 ;; shell script. For example `gnudoit "(+ 2 3)"' will print `5',
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
53 ;; whereas `gnudoit "(gnus)"' will fire up your favorite newsreader.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
54 ;; Like gnuclient, `gnudoit' requires the server to be started prior
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
55 ;; to using it.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
56
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
57 ;; For more information you can refer to man pages of gnuclient,
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
58 ;; gnudoit and gnuserv, distributed with XEmacs.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
59
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
60 ;; gnuserv.el was originally written by Andy Norman as an improvement
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
61 ;; over William Sommerfeld's server.el. Since then, a number of
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
62 ;; people have worked on it, including Bob Weiner, Darell Kindred,
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
63 ;; Arup Mukherjee, Ben Wing and Jan Vroonhof. It was completely
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
64 ;; rewritten (labeled as version 3) by Hrvoje Niksic in May 1997. The
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
65 ;; new code will not run on GNU Emacs.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
66
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
67 ;; Jan Vroonhof <vroonhof@math.ethz.ch> July/1996
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
68 ;; ported the server-temp-file-regexp feature from server.el
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
69 ;; ported server hooks from server.el
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
70 ;; ported kill-*-query functions from server.el (and made it optional)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
71 ;; synced other behaviour with server.el
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
72 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
73 ;; Jan Vroonhof
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
74 ;; Customized.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
75 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
76 ;; Hrvoje Niksic <hniksic@srce.hr> May/1997
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
77 ;; Completely rewritten. Now uses `defstruct' and other CL stuff
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
78 ;; to define clients cleanly. Many thanks to Dave Gillespie!
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
79 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
80 ;; Mike Scheidler <c23mts@eng.delcoelect.com> July, 1997
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
81 ;; Added 'Done' button to the menubar.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
82
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
83
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
84 ;;; Code:
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
85
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
86 (defgroup gnuserv nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
87 "The gnuserv suite of programs to talk to Emacs from outside."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
88 :group 'environment
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
89 :group 'processes
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
90 :group 'terminals)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
91
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
92
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
93 ;; Provide the old variables as aliases, to avoid breaking .emacs
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
94 ;; files. However, they are obsolete and should be converted to the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
95 ;; new forms. This ugly crock must be before the variable
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
96 ;; declaration, or the scheme fails.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
97
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
98 (define-obsolete-variable-alias 'server-frame 'gnuserv-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
99 (define-obsolete-variable-alias 'server-done-function
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
100 'gnuserv-done-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
101 (define-obsolete-variable-alias 'server-done-temp-file-function
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
102 'gnuserv-done-temp-file-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
103 (define-obsolete-variable-alias 'server-find-file-function
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
104 'gnuserv-find-file-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
105 (define-obsolete-variable-alias 'server-program
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
106 'gnuserv-program)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
107 (define-obsolete-variable-alias 'server-visit-hook
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
108 'gnuserv-visit-hook)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
109 (define-obsolete-variable-alias 'server-done-hook
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
110 'gnuserv-done-hook)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
111 (define-obsolete-variable-alias 'server-kill-quietly
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
112 'gnuserv-kill-quietly)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
113 (define-obsolete-variable-alias 'server-temp-file-regexp
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
114 'gnuserv-temp-file-regexp)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
115 (define-obsolete-variable-alias 'server-make-temp-file-backup
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
116 'gnuserv-make-temp-file-backup)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
117
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
118 ;;;###autoload
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
119 (defcustom gnuserv-frame nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
120 "*The frame to be used to display all edited files.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
121 If nil, then a new frame is created for each file edited.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
122 If t, then the currently selected frame will be used.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
123 If a function, then this will be called with a symbol `x' or `tty' as the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
124 only argument, and its return value will be interpreted as above."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
125 :tag "Gnuserv Frame"
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
126 :type '(radio (const :tag "Create new frame each time" nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
127 (const :tag "Use selected frame" t)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
128 (function-item :tag "Use main Emacs frame"
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
129 gnuserv-main-frame-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
130 (function-item :tag "Use visible frame, otherwise create new"
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
131 gnuserv-visible-frame-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
132 (function-item :tag "Create special Gnuserv frame and use it"
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
133 gnuserv-special-frame-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
134 (function :tag "Other"))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
135 :group 'gnuserv
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
136 :group 'frames)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
137
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
138 (defcustom gnuserv-frame-plist nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
139 "*Plist of frame properties for creating a gnuserv frame."
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
140 :type 'plist
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
141 :group 'gnuserv
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
142 :group 'frames)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
143
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
144 (defcustom gnuserv-done-function 'kill-buffer
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
145 "*Function used to remove a buffer after editing.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
146 It is called with one BUFFER argument. Functions such as `kill-buffer' and
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
147 `bury-buffer' are good values. See also `gnuserv-done-temp-file-function'."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
148 :type '(radio (function-item kill-buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
149 (function-item bury-buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
150 (function :tag "Other"))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
151 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
152
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
153 (defcustom gnuserv-done-temp-file-function 'kill-buffer
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
154 "*Function used to remove a temporary buffer after editing.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
155 It is called with one BUFFER argument. Functions such as `kill-buffer' and
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
156 `bury-buffer' are good values. See also `gnuserv-done-temp-file-function'."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
157 :type '(radio (function-item kill-buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
158 (function-item bury-buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
159 (function :tag "Other"))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
160 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
161
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
162 (defcustom gnuserv-find-file-function 'find-file
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
163 "*Function to visit a file with.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
164 It takes one argument, a file name to visit."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
165 :type 'function
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
166 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
167
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
168 (defcustom gnuserv-view-file-function 'view-file
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
169 "*Function to view a file with.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
170 It takes one argument, a file name to view."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
171 :type '(radio (function-item view-file)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
172 (function-item find-file-read-only)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
173 (function :tag "Other"))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
174 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
175
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
176 (defcustom gnuserv-program "gnuserv"
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
177 "*Program to use as the editing server."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
178 :type 'string
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
179 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
180
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
181 (defcustom gnuserv-visit-hook nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
182 "*Hook run after visiting a file."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
183 :type 'hook
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
184 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
185
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
186 (defcustom gnuserv-done-hook nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
187 "*Hook run when done editing a buffer for the Emacs server.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
188 The hook functions are called after the file has been visited, with the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
189 current buffer set to the visiting buffer."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
190 :type 'hook
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
191 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
192
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
193 (defcustom gnuserv-init-hook nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
194 "*Hook run after the server is started."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
195 :type 'hook
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
196 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
197
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
198 (defcustom gnuserv-shutdown-hook nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
199 "*Hook run before the server exits."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
200 :type 'hook
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
201 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
202
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
203 (defcustom gnuserv-kill-quietly nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
204 "*Non-nil means to kill buffers with clients attached without requiring confirmation."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
205 :type 'boolean
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
206 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
207
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 219
diff changeset
208 (defcustom gnuserv-temp-file-regexp
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 219
diff changeset
209 (concat "^" (temp-directory) "/Re\\|/draft$")
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
210 "*Regexp which should match filenames of temporary files deleted
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
211 and reused by the programs that invoke the Emacs server."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
212 :type 'regexp
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
213 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
214
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
215 (defcustom gnuserv-make-temp-file-backup nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
216 "*Non-nil makes the server backup temporary files also."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
217 :type 'boolean
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
218 :group 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
219
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
220
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
221 ;;; Internal variables:
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
222
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
223 (defstruct gnuclient
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
224 "An object that encompasses several buffers in one.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
225 Normally, a client connecting to Emacs will be assigned an id, and
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
226 will request editing of several files.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
227
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
228 ID - Client id (integer).
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
229 BUFFERS - List of buffers that \"belong\" to the client.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
230 NOTE: one buffer can belong to several clients.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
231 DEVICE - The device this client is on. If the device was also created.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
232 by a client, it will be placed to `gnuserv-devices' list.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
233 FRAME - Frame created by the client, or nil if the client didn't
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
234 create a frame.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
235
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
236 All the slots default to nil."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
237 (id nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
238 (buffers nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
239 (device nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
240 (frame nil))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
241
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
242 (defvar gnuserv-process nil
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
243 "The current gnuserv process.")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
244
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
245 (defvar gnuserv-string ""
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
246 "The last input string from the server.")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
247
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
248 (defvar gnuserv-current-client nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
249 "The client we are currently talking to.")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
250
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
251 (defvar gnuserv-clients nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
252 "List of current gnuserv clients.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
253 Each element is a gnuclient structure that identifies a client.")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
254
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
255 (defvar gnuserv-devices nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
256 "List of devices created by clients.")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
257
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
258 (defvar gnuserv-special-frame nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
259 "Frame created specially for Server.")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
260
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
261 ;; We want the client-infested buffers to have some modeline
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
262 ;; identification, so we'll make a "minor mode".
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
263 (defvar gnuserv-minor-mode nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
264 (make-variable-buffer-local 'gnuserv-mode)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
265 (pushnew '(gnuserv-minor-mode " Server") minor-mode-alist
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
266 :test 'equal)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
267
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
268
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
269 ;; Sample gnuserv-frame functions
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
270
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
271 (defun gnuserv-main-frame-function (type)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
272 "Return a sensible value for the main Emacs frame."
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 276
diff changeset
273 (if (or (eq type 'x)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 276
diff changeset
274 (eq type 'mswindows))
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
275 (car (frame-list))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
276 nil))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
277
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
278 (defun gnuserv-visible-frame-function (type)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
279 "Return a frame if there is a frame that is truly visible, nil otherwise.
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
280 This is meant in the X sense, so it will not return frames that are on another
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
281 visual screen. Totally visible frames are preferred. If none found, return nil."
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 276
diff changeset
282 (if (or (eq type 'x)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 276
diff changeset
283 (eq type 'mswindows))
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
284 (cond ((car (filtered-frame-list 'frame-totally-visible-p
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
285 (selected-device))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
286 ((car (filtered-frame-list (lambda (frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
287 ;; eq t as in not 'hidden
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
288 (eq t (frame-visible-p frame)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
289 (selected-device)))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
290 nil))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
291
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
292 (defun gnuserv-special-frame-function (type)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
293 "Create a special frame for Gnuserv and return it on later invocations."
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
294 (unless (frame-live-p gnuserv-special-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
295 (setq gnuserv-special-frame (make-frame gnuserv-frame-plist)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
296 gnuserv-special-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
297
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
298
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
299 ;;; Communication functions
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
300
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
301 ;; We used to restart the server here, but it's too risky -- if
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
302 ;; something goes awry, it's too easy to wind up in a loop.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
303 (defun gnuserv-sentinel (proc msg)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
304 (let ((msgstring (concat "Gnuserv process %s; restart with `%s'"))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
305 (keystring (substitute-command-keys "\\[gnuserv-start]")))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
306 (case (process-status proc)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
307 (exit
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
308 (message msgstring "exited" keystring)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
309 (gnuserv-prepare-shutdown))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
310 (signal
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
311 (message msgstring "killed" keystring)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
312 (gnuserv-prepare-shutdown))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
313 (closed
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
314 (message msgstring "closed" keystring))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
315 (gnuserv-prepare-shutdown))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
316
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
317 ;; This function reads client requests from our current server. Every
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
318 ;; client is identified by a unique ID within the server
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
319 ;; (incidentally, the same ID is the file descriptor the server uses
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
320 ;; to communicate to client).
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
321 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
322 ;; The request string can arrive in several chunks. As the request
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
323 ;; ends with \C-d, we check for that character at the end of string.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
324 ;; If not found, keep reading, and concatenating to former strings.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
325 ;; So, if at first read we receive "5 (gn", that text will be stored
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
326 ;; to gnuserv-string. If we then receive "us)\C-d", the two will be
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
327 ;; concatenated, `current-client' will be set to 5, and `(gnus)' form
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
328 ;; will be evaluated.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
329 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
330 ;; Server will send the following:
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
331 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
332 ;; "ID <text>\C-d" (no quotes)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
333 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
334 ;; ID - file descriptor of the given client;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
335 ;; <text> - the actual contents of the request.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
336 (defun gnuserv-process-filter (proc string)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
337 "Process gnuserv client requests to execute Emacs commands."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
338 (setq gnuserv-string (concat gnuserv-string string))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
339 ;; C-d means end of request.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
340 (when (string-match "\C-d\\'" gnuserv-string)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
341 (cond ((string-match "^[0-9]+" gnuserv-string) ; client request id
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
342 (let ((header (read-from-string gnuserv-string)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
343 ;; Set the client we are talking to.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
344 (setq gnuserv-current-client (car header))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
345 ;; Evaluate the expression
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
346 (condition-case oops
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
347 (eval (car (read-from-string gnuserv-string (cdr header))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
348 ;; In case of an error, write the description to the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
349 ;; client, and then signal it.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
350 (error (setq gnuserv-string "")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
351 (gnuserv-write-to-client gnuserv-current-client oops)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
352 (setq gnuserv-current-client nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
353 (signal (car oops) (cdr oops)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
354 (quit (setq gnuserv-string "")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
355 (gnuserv-write-to-client gnuserv-current-client oops)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
356 (setq gnuserv-current-client nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
357 (signal 'quit nil)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
358 (setq gnuserv-string "")))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
359 (t
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
360 (error "%s: invalid response from gnuserv" gnuserv-string)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
361 (setq gnuserv-string "")))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
362
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
363 ;; This function is somewhat of a misnomer. Actually, we write to the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
364 ;; server (using `process-send-string' to gnuserv-process), which
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
365 ;; interprets what we say and forwards it to the client. The
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
366 ;; incantation server understands is (from gnuserv.c):
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
367 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
368 ;; "FD/LEN:<text>\n" (no quotes)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
369 ;; FD - file descriptor of the given client (which we obtained from
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
370 ;; the server earlier);
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
371 ;; LEN - length of the stuff we are about to send;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
372 ;; <text> - the actual contents of the request.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
373 (defun gnuserv-write-to-client (client-id form)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
374 "Write the given form to the given client via the gnuserv process."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
375 (when (eq (process-status gnuserv-process) 'run)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
376 (let* ((result (format "%s" form))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
377 (s (format "%s/%d:%s\n" client-id
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
378 (length result) result)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
379 (process-send-string gnuserv-process s))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
380
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
381 ;; The following two functions are helper functions, used by
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
382 ;; gnuclient.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
383
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
384 (defun gnuserv-eval (form)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
385 "Evaluate form and return result to client."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
386 (gnuserv-write-to-client gnuserv-current-client (eval form))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
387 (setq gnuserv-current-client nil))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
388
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
389 (defun gnuserv-eval-quickly (form)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
390 "Let client know that we've received the request, and then eval the form.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
391 This order is important as not to keep the client waiting."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
392 (gnuserv-write-to-client gnuserv-current-client nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
393 (setq gnuserv-current-client nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
394 (eval form))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
395
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
396
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
397 ;; "Execute" a client connection, called by gnuclient. This is the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
398 ;; backbone of gnuserv.el.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
399 (defun gnuserv-edit-files (type list &rest flags)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
400 "For each (line-number . file) pair in LIST, edit the file at line-number.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
401 The visited buffers are memorized, so that when \\[gnuserv-edit] is invoked
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
402 in such a buffer, or when it is killed, or the client's device deleted, the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
403 client will be invoked that the edit is finished.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
404
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
405 TYPE should either be a (tty TTY TERM PID) list, or (x DISPLAY) list.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
406 If a flag is `quick', just edit the files in Emacs.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
407 If a flag is `view', view the files read-only."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
408 (let (quick view)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
409 (mapc (lambda (flag)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
410 (case flag
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
411 (quick (setq quick t))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
412 (view (setq view t))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
413 (t (error "Invalid flag %s" flag))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
414 flags)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
415 (let* ((old-device-num (length (device-list)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
416 (new-frame nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
417 (dest-frame (if (functionp gnuserv-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
418 (funcall gnuserv-frame (car type))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
419 gnuserv-frame))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
420 ;; The gnuserv-frame dependencies are ugly, but it's
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
421 ;; extremely hard to make that stuff cleaner without
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
422 ;; breaking everything in sight.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
423 (device (cond ((frame-live-p dest-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
424 (frame-device dest-frame))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
425 ((null dest-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
426 (case (car type)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
427 (tty (apply 'make-tty-device (cdr type)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
428 (x (make-x-device (cadr type)))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 276
diff changeset
429 (mswindows (make-mswindows-device))
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
430 (t (error "Invalid device type"))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
431 (t
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
432 (selected-device))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
433 (frame (cond ((frame-live-p dest-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
434 dest-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
435 ((null dest-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
436 (setq new-frame (make-frame gnuserv-frame-plist
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
437 device))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
438 new-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
439 (t (selected-frame))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
440 (client (make-gnuclient :id gnuserv-current-client
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
441 :device device
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
442 :frame new-frame)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
443 (setq gnuserv-current-client nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
444 ;; If the device was created by this client, push it to the list.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
445 (and (/= old-device-num (length (device-list)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
446 (push device gnuserv-devices))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
447 (and (frame-iconified-p frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
448 (deiconify-frame frame))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
449 ;; Visit all the listed files.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
450 (while list
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
451 (let ((line (caar list)) (path (cdar list)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
452 (select-frame frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
453 ;; Visit the file.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
454 (funcall (if view
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
455 gnuserv-view-file-function
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
456 gnuserv-find-file-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
457 path)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
458 (goto-line line)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
459 ;; Don't memorize the quick and view buffers.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
460 (unless (or quick view)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
461 (pushnew (current-buffer) (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
462 (setq gnuserv-minor-mode t)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
463 ;; Add the "Done" button to the menubar, only in this buffer.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
464 (if (and (featurep 'menubar) current-menubar)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
465 (progn (set-buffer-menubar current-menubar)
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 219
diff changeset
466 (add-menu-button nil ["Done" gnuserv-edit]))
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
467 ))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
468 (run-hooks 'gnuserv-visit-hook)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
469 (pop list)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
470 (cond
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
471 ((and (or quick view)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
472 (device-on-window-system-p device))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
473 ;; Exit if on X device, and quick or view. NOTE: if the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
474 ;; client is to finish now, it must absolutely /not/ be
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
475 ;; included to the list of clients. This way the client-ids
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
476 ;; should be unique.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
477 (gnuserv-write-to-client (gnuclient-id client) nil))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
478 (t
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
479 ;; Else, the client gets a vote.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
480 (push client gnuserv-clients)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
481 ;; Explain buffer exit options. If dest-frame is nil, the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
482 ;; user can exit via `delete-frame'. OTOH, if FLAGS are nil
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
483 ;; and there are some buffers, the user can exit via
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
484 ;; `gnuserv-edit'.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
485 (if (and (not (or quick view))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
486 (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
487 (message "%s"
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
488 (substitute-command-keys
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
489 "Type `\\[gnuserv-edit]' to finish editing"))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
490 (or dest-frame
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
491 (message "%s"
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
492 (substitute-command-keys
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
493 "Type `\\[delete-frame]' to finish editing")))))))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
494
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
495
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
496 ;;; Functions that hook into Emacs in various way to enable operation
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
497
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
498 ;; Defined later.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
499 (add-hook 'kill-emacs-hook 'gnuserv-kill-all-clients t)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
500
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
501 ;; A helper function; used by others. Try avoiding it whenever
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
502 ;; possible, because it is slow, and conses a list. Use
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
503 ;; `gnuserv-buffer-p' when appropriate, for instance.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
504 (defun gnuserv-buffer-clients (buffer)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
505 "Return a list of clients to which BUFFER belongs."
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
506 (let (res)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
507 (dolist (client gnuserv-clients)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
508 (when (memq buffer (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
509 (push client res)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
510 res))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
511
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
512 ;; Like `gnuserv-buffer-clients', but returns a boolean; doesn't
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
513 ;; collect a list.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
514 (defun gnuserv-buffer-p (buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
515 (member* buffer gnuserv-clients
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
516 :test 'memq
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
517 :key 'gnuclient-buffers))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
518
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
519 ;; This function makes sure that a killed buffer is deleted off the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
520 ;; list for the particular client.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
521 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
522 ;; This hooks into `kill-buffer-hook'. It is *not* a replacement for
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
523 ;; `kill-buffer' (thanks God).
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
524 (defun gnuserv-kill-buffer-function ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
525 "Remove the buffer from the buffer lists of all the clients it belongs to.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
526 Any client that remains \"empty\" after the removal is informed that the
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
527 editing has ended."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
528 (let* ((buf (current-buffer)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
529 (dolist (client (gnuserv-buffer-clients buf))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
530 (callf2 delq buf (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
531 ;; If no more buffers, kill the client.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
532 (when (null (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
533 (gnuserv-kill-client client)))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
534
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
535 (add-hook 'kill-buffer-hook 'gnuserv-kill-buffer-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
536
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
537 ;; Ask for confirmation before killing a buffer that belongs to a
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
538 ;; living client.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
539 (defun gnuserv-kill-buffer-query-function ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
540 (or gnuserv-kill-quietly
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
541 (not (gnuserv-buffer-p (current-buffer)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
542 (yes-or-no-p
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
543 (format "Buffer %s belongs to gnuserv client(s); kill anyway? "
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
544 (current-buffer)))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
545
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
546 (add-hook 'kill-buffer-query-functions
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
547 'gnuserv-kill-buffer-query-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
548
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
549 (defun gnuserv-kill-emacs-query-function ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
550 (or gnuserv-kill-quietly
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
551 (not (some 'gnuclient-buffers gnuserv-clients))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
552 (yes-or-no-p "Gnuserv buffers still have clients; exit anyway? ")))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
553
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
554 (add-hook 'kill-emacs-query-functions
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
555 'gnuserv-kill-emacs-query-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
556
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
557 ;; If the device of a client is to be deleted, the client should die
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
558 ;; as well. This is why we hook into `delete-device-hook'.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
559 (defun gnuserv-check-device (device)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
560 (when (memq device gnuserv-devices)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
561 (dolist (client gnuserv-clients)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
562 (when (eq device (gnuclient-device client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
563 ;; we must make sure that the server kill doesn't result in
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
564 ;; killing the device, because it would cause a device-dead
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
565 ;; error when `delete-device' tries to do the job later.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
566 (gnuserv-kill-client client t))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
567 (callf2 delq device gnuserv-devices))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
568
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
569 (add-hook 'delete-device-hook 'gnuserv-check-device)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
570
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
571 (defun gnuserv-temp-file-p (buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
572 "Return non-nil if BUFFER contains a file considered temporary.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
573 These are files whose names suggest they are repeatedly
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
574 reused to pass information to another program.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
575
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
576 The variable `gnuserv-temp-file-regexp' controls which filenames
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
577 are considered temporary."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
578 (and (buffer-file-name buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
579 (string-match gnuserv-temp-file-regexp (buffer-file-name buffer))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
580
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
581 (defun gnuserv-kill-client (client &optional leave-frame)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
582 "Kill the gnuclient CLIENT.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
583 This will do away with all the associated buffers. If LEAVE-FRAME,
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
584 the function will not remove the frames associated with the client."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
585 ;; Order is important: first delete client from gnuserv-clients, to
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
586 ;; prevent gnuserv-buffer-done-1 calling us recursively.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
587 (callf2 delq client gnuserv-clients)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
588 ;; Process the buffers.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
589 (mapc 'gnuserv-buffer-done-1 (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
590 (unless leave-frame
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
591 (let ((device (gnuclient-device client)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
592 ;; kill frame created by this client (if any), unless
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
593 ;; specifically requested otherwise.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
594 ;;
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
595 ;; note: last frame on a device will not be deleted here.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
596 (when (and (gnuclient-frame client)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
597 (frame-live-p (gnuclient-frame client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
598 (second (device-frame-list device)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
599 (delete-frame (gnuclient-frame client)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
600 ;; If the device is live, created by a client, and no longer used
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
601 ;; by any client, delete it.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
602 (when (and (device-live-p device)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
603 (memq device gnuserv-devices)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
604 (second (device-list))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
605 (not (member* device gnuserv-clients
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
606 :key 'gnuclient-device)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
607 ;; `gnuserv-check-device' will remove it from `gnuserv-devices'.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
608 (delete-device device))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
609 ;; Notify the client.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
610 (gnuserv-write-to-client (gnuclient-id client) nil))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
611
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
612 ;; Do away with the buffer.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
613 (defun gnuserv-buffer-done-1 (buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
614 (dolist (client (gnuserv-buffer-clients buffer))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
615 (callf2 delq buffer (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
616 (when (null (gnuclient-buffers client))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
617 (gnuserv-kill-client client)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
618 ;; Get rid of the buffer.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
619 (save-excursion
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
620 (set-buffer buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
621 (run-hooks 'gnuserv-done-hook)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
622 (setq gnuserv-minor-mode nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
623 ;; Delete the menu button.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
624 (if (and (featurep 'menubar) current-menubar)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
625 (delete-menu-item '("Done")))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
626 (funcall (if (gnuserv-temp-file-p buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
627 gnuserv-done-temp-file-function
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
628 gnuserv-done-function)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
629 buffer)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
630
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
631
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
632 ;;; Higher-level functions
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
633
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
634 ;; Choose a `next' server buffer, according to several criteria, and
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
635 ;; return it. If none are found, return nil.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
636 (defun gnuserv-next-buffer ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
637 (let* ((frame (selected-frame))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
638 (device (selected-device))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
639 client)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
640 (cond
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
641 ;; If we have a client belonging to this frame, return
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
642 ;; the first buffer from it.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
643 ((setq client
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
644 (car (member* frame gnuserv-clients :key 'gnuclient-frame)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
645 (car (gnuclient-buffers client)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
646 ;; Else, look for a device.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
647 ((and
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
648 (memq (selected-device) gnuserv-devices)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
649 (setq client
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
650 (car (member* device gnuserv-clients :key 'gnuclient-device))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
651 (car (gnuclient-buffers client)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
652 ;; Else, try to find any client with at least one buffer, and
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
653 ;; return its first buffer.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
654 ((setq client
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
655 (car (member-if-not #'null gnuserv-clients
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
656 :key 'gnuclient-buffers)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
657 (car (gnuclient-buffers client)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
658 ;; Oh, give up.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
659 (t nil))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
660
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
661 (defun gnuserv-buffer-done (buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
662 "Mark BUFFER as \"done\" for its client(s).
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
663 Does the save/backup queries first, and calls `gnuserv-done-function'."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
664 ;; Check whether this is the real thing.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
665 (unless (gnuserv-buffer-p buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
666 (error "%s does not belong to a gnuserv client" buffer))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
667 ;; Backup/ask query.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
668 (if (gnuserv-temp-file-p buffer)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
669 ;; For a temp file, save, and do NOT make a non-numeric backup
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
670 ;; Why does server.el explicitly back up temporary files?
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
671 (let ((version-control nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
672 (buffer-backed-up (not gnuserv-make-temp-file-backup)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
673 (save-buffer))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
674 (if (and (buffer-modified-p)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
675 (y-or-n-p (concat "Save file " buffer-file-name "? ")))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
676 (save-buffer buffer)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
677 (gnuserv-buffer-done-1 buffer))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
678
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
679 ;; Called by `gnuserv-start-1' to clean everything. Hooked into
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
680 ;; `kill-emacs-hook', too.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
681 (defun gnuserv-kill-all-clients ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
682 "Kill all the gnuserv clients. Ruthlessly."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
683 (mapc 'gnuserv-kill-client gnuserv-clients))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
684
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
685 ;; This serves to run the hook and reset
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
686 ;; `allow-deletion-of-last-visible-frame'.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
687 (defun gnuserv-prepare-shutdown ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
688 (setq allow-deletion-of-last-visible-frame nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
689 (run-hooks 'gnuserv-shutdown-hook))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
690
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
691 ;; This is a user-callable function, too.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
692 (defun gnuserv-shutdown ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
693 "Shutdown the gnuserv server, if one is currently running.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
694 All the clients will be disposed of via the normal methods."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
695 (interactive)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
696 (gnuserv-kill-all-clients)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
697 (when gnuserv-process
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
698 (set-process-sentinel gnuserv-process nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
699 (gnuserv-prepare-shutdown)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
700 (condition-case ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
701 (delete-process gnuserv-process)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
702 (error nil))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
703 (setq gnuserv-process nil)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
704
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
705 ;; Actually start the process. Kills all the clients before-hand.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
706 (defun gnuserv-start-1 (&optional leave-dead)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
707 ;; Shutdown the existing server, if any.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
708 (gnuserv-shutdown)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
709 ;; If we already had a server, clear out associated status.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
710 (unless leave-dead
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
711 (setq gnuserv-string ""
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
712 gnuserv-current-client nil)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
713 (let ((process-connection-type t))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
714 (setq gnuserv-process
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
715 (start-process "gnuserv" nil gnuserv-program)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
716 (set-process-sentinel gnuserv-process 'gnuserv-sentinel)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
717 (set-process-filter gnuserv-process 'gnuserv-process-filter)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
718 (process-kill-without-query gnuserv-process)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
719 (setq allow-deletion-of-last-visible-frame t)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
720 (run-hooks 'gnuserv-init-hook)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
721
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
722
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
723 ;;; User-callable functions:
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
724
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
725 ;;;###autoload
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
726 (defun gnuserv-running-p ()
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
727 "Return non-nil if a gnuserv process is running from this XEmacs session."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
728 (not (not gnuserv-process)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
729
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
730 ;;;###autoload
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
731 (defun gnuserv-start (&optional leave-dead)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
732 "Allow this Emacs process to be a server for client processes.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
733 This starts a gnuserv communications subprocess through which
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 263
diff changeset
734 client \"editors\" (gnuclient and gnudoit) can send editing commands to
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
735 this Emacs job. See the gnuserv(1) manual page for more details.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
736
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
737 Prefix arg means just kill any existing server communications subprocess."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
738 (interactive "P")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
739 (and gnuserv-process
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
740 (not leave-dead)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
741 (message "Restarting gnuserv"))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
742 (gnuserv-start-1 leave-dead))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
743
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
744 (defun gnuserv-edit (&optional count)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
745 "Mark the current gnuserv editing buffer as \"done\", and switch to next one.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
746
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
747 Run with a numeric prefix argument, repeat the operation that number
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
748 of times. If given a universal prefix argument, close all the buffers
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
749 of this buffer's clients.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
750
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
751 The `gnuserv-done-function' (bound to `kill-buffer' by default) is
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
752 called to dispose of the buffer after marking it as done.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
753
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
754 Files that match `gnuserv-temp-file-regexp' are considered temporary and
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
755 are saved unconditionally and backed up if `gnuserv-make-temp-file-backup'
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
756 is non-nil. They are disposed of using `gnuserv-done-temp-file-function'
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
757 \(also bound to `kill-buffer' by default).
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
758
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
759 When all of a client's buffers are marked as \"done\", the client is notified."
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
760 (interactive "P")
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
761 (when (null count)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
762 (setq count 1))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
763 (cond ((numberp count)
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
764 (while (natnump (decf count))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
765 (let ((frame (selected-frame)))
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
766 (gnuserv-buffer-done (current-buffer))
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
767 (when (eq frame (selected-frame))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
768 ;; Switch to the next gnuserv buffer. However, do this
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
769 ;; only if we remain in the same frame.
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
770 (let ((next (gnuserv-next-buffer)))
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
771 (when next
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
772 (switch-to-buffer next)))))))
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
773 (count
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
774 (let* ((buf (current-buffer))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
775 (clients (gnuserv-buffer-clients buf)))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
776 (unless clients
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
777 (error "%s does not belong to a gnuserv client" buf))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
778 (mapc 'gnuserv-kill-client (gnuserv-buffer-clients buf))))))
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
779
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
780 (global-set-key "\C-x#" 'gnuserv-edit)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
781
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
782 (provide 'gnuserv)
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
783
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents:
diff changeset
784 ;;; gnuserv.el ends here