annotate lisp/packages/gnuserv.el @ 207:e45d5e7c476e r20-4b2

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