annotate lisp/gnuserv.el @ 5402:308d34e9f07d

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