annotate lisp/packages/gnuserv.el @ 149:538048ae2ab8 r20-3b1

Import from CVS: tag r20-3b1
author cvs
date Mon, 13 Aug 2007 09:36:16 +0200
parents b980b6286996
children 59463afc5666
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
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
4 ;; Version: 3.1
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
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
6 ;; Hrvoje Niksic <hniksic@srce.hr>
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
7 ;; Keywords: environment, processes, terminals
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
8
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
9 ;; This file is part of XEmacs.
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 ;; XEmacs is free software; you can redistribute it and/or modify it
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
12 ;; under the terms of the GNU General Public License as published by
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
14 ;; any later version.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
15
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
19 ;; General Public License for more details.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
20
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
21 ;; You should have received a copy of the GNU General Public License
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
23 ;; Free Software Foundation, 59 Temple Place - Suite 330,
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
24 ;; Boston, MA 02111-1307, USA.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
25
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
28 ;;; Commentary:
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
29
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
30 ;; 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
31 ;; processes. Specifically, any number of files can be attached for
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
32 ;; editing to a running XEmacs process using the `gnuclient' program.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
33
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
34 ;; Use `M-x gnuserv-start' to start the server and `gnuclient files'
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
35 ;; 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
36 ;; `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
37 ;; .emacs, and enable `gnuclient' as your Unix "editor". When all the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
38 ;; buffers for a client have been edited and exited with
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
39 ;; `gnuserv-edit', the client "editor" will return to the program that
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
40 ;; invoked it.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
41
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
42 ;; Your editing commands and Emacs' display output go to and from the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
43 ;; 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
44 ;; 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
45 ;; 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
46 ;; XEmacs, and will be removed once you are done with the buffer.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
47
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
48 ;; To evaluate a Lisp form in a running Emacs, use the `gnudoit'
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
49 ;; utility. For example `gnudoit "(+ 2 3)"' will print `5', whereas
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
50 ;; `gnudoit "(gnus)"' will fire up your favorite newsreader. Like
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
51 ;; gnuclient, `gnudoit' requires the server to be started prior to
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
52 ;; using it.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
53
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
54 ;; For more information you can refer to man pages of gnuclient,
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
55 ;; gnudoit and gnuserv, distributed with XEmacs.
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 ;; gnuserv.el was originally written by Andy Norman as an improvement
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
58 ;; ver William Sommerfeld's server.el. Since then, a number of people
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
59 ;; have worked on it, including Bob Weiner, Darell Kindred, Arup
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
60 ;; Mukherjee, Ben Wing and Jan Vroonhof. It was completely rewritten
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
61 ;; (labeled as version 3) by Hrvoje Niksic in May 1997.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
62
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
63 ;; Jan Vroonhof <vroonhof@math.ethz.ch> July/1996
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
64 ;; ported the server-temp-file-regexp feature from server.el
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
65 ;; ported server hooks from server.el
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
66 ;; ported kill-*-query functions from server.el (and made it optional)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
67 ;; synced other behaviour with server.el
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
68 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
69 ;; Jan Vroonhof
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
70 ;; Customized.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
71 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
72 ;; Hrvoje Niksic <hniksic@srce.hr> May/1997
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
73 ;; Completely rewritten. Now uses `defstruct' and other CL stuff
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
74 ;; to define clients cleanly. Dave, thanks!
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
77 ;;; Code:
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
78
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
79 (defconst gnuserv-rcs-version
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
80 "$Id: gnuserv.el,v 1.8 1997/05/18 03:40:06 steve Exp $")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
82 (defgroup gnuserv nil
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
83 "The gnuserv suite of programs to talk to Emacs from outside."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
84 :group 'environment
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
85 :group 'processes
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
86 :group 'terminals)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
87
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
88
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
89 ;;;###autoload
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
90 (defcustom gnuserv-frame nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
91 "*The frame to be used to display all edited files.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
92 If nil, then a new frame is created for each file edited.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
93 If t, then the currently selected frame will be used.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
94 If a function, then this will be called with a symbol `x' or `tty' as the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
95 only argument, and its return value will be interpreted as above."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
96 :tag "Gnuserv Frame"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
97 :type '(radio (const :tag "Create new frame each time" nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
98 (const :tag "Use selected frame" t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
99 (function-item :tag "Use main Emacs frame"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
100 gnuserv-main-frame-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
101 (function-item :tag "Use visible frame, otherwise create new"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
102 gnuserv-visible-frame-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
103 (function-item :tag "Create special Gnuserv frame and use it"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
104 gnuserv-special-frame-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
105 (function :tag "Other"))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
106 :group 'gnuserv)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
108 (defcustom gnuserv-done-function 'kill-buffer
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
109 "*Function used to remove a buffer after editing.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
110 It is called with one BUFFER argument. Functions such as 'kill-buffer' and
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
111 'bury-buffer' are good values. See also `gnuserv-done-temp-file-function'."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
112 :type '(radio (function-item kill-buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
113 (function-item bury-buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
114 (function :tag "Other"))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
115 :group 'gnuserv)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
117 (defcustom gnuserv-done-temp-file-function 'kill-buffer
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
118 "*Function used to remove a temporary buffer after editing.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
119 It is called with one BUFFER argument. Functions such as 'kill-buffer' and
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
120 'bury-buffer' are good values. See also `gnuserv-done-temp-file-function'."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
121 :type '(radio (function-item kill-buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
122 (function-item bury-buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
123 (function :tag "Other"))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
124 :group 'gnuserv)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
125
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
126 (defcustom gnuserv-find-file-function 'find-file
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
127 "*Function to visit a file with.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
128 It takes one argument, a file name to visit."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
129 :type 'function
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
130 :group 'gnuserv)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
131
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
132 (defcustom gnuserv-view-file-function 'view-file
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
133 "*Function to view a file with.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
134 It takes one argument, a file name to view."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
135 :type '(radio (function-item view-file)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
136 (function-item find-file-read-only)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
137 (function :tag "Other"))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
138 :group 'gnuserv)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
140 (defcustom gnuserv-program "gnuserv"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
141 "*Program to use as the editing server."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
142 :type 'string
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
143 :group 'gnuserv)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
145 (defcustom gnuserv-visit-hook nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
146 "*Hook run after visiting a file."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
147 :type 'hook
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
148 :group 'gnuserv)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
149
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
150 (defcustom gnuserv-done-hook nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
151 "*Hook run when done editing a buffer for the Emacs server.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
152 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
153 current buffer set to the visiting buffer."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
154 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
155 :group 'gnuserv)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
156
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
157 (defcustom gnuserv-kill-quietly nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
158 "*Non-nil means to kill buffers with clients attached without requiring confirmation."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
159 :type 'boolean
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
160 :group 'gnuserv)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
161
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
162 (defcustom gnuserv-temp-file-regexp "^/tmp/Re\\|/draft$"
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
163 "*Regexp which should match filenames of temporary files deleted
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
164 and reused by the programs that invoke the Emacs server."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
165 :type 'regexp
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
166 :group 'gnuserv)
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
167
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
168 (defcustom gnuserv-make-temp-file-backup nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
169 "*Non-nil makes the server backup temporary files also."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
170 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
171 :group 'gnuserv)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
172
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
173
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
174 ;; The old functions are provided as aliases, to avoid breaking .emacs
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
175 ;; files. However, they are obsolete and should be avoided.
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
176
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
177 (defvaralias 'server-frame 'gnuserv-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
178 (defvaralias 'server-done-function 'gnuserv-done-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
179 (defvaralias 'server-done-temp-file-function 'gnuserv-done-temp-file-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
180 (defvaralias 'server-find-file-function 'gnuserv-find-file-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
181 (defvaralias 'server-program 'gnuserv-program)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
182 (defvaralias 'server-visit-hook 'gnuserv-visit-hook)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
183 (defvaralias 'server-done-hook 'gnuserv-done-hook)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
184 (defvaralias 'server-kill-quietly 'gnuserv-kill-quietly)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
185 (defvaralias 'server-temp-file-regexp 'gnuserv-temp-file-regexp)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
186 (defvaralias 'server-make-temp-file-backup 'gnuserv-make-temp-file-backup)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
187
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
188
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
189 ;;; Internal variables:
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
190
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
191 (defstruct gnuclient
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
192 "An object that encompasses several buffers in one.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
193 Normally, a client connecting to Emacs will be assigned an id, and
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
194 will request editing of several files.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
195
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
196 ID - Client id (integer).
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
197 BUFFERS - List of buffers that \"belong\" to the client.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
198 NOTE: one buffer can belong to several clients.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
199 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
200 by a client, it will be placed to `gnuserv-devices' list.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
201 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
202 create a frame.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
203
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
204 All the slots default to nil."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
205 (id nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
206 (buffers nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
207 (device nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
208 (frame nil))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
209
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
210 (defvar gnuserv-process nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
211 "The current gnuserv process.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
212
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
213 (defvar gnuserv-string ""
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
214 "The last input string from the server.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
215
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
216 (defvar gnuserv-current-client nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
217 "The client we are currently talking to.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
218
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
219 (defvar gnuserv-clients nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
220 "List of current gnuserv clients.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
221 Each element is a gnuclient structure that identifies a client.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
222
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
223 (defvar gnuserv-devices nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
224 "List of devices created by clients.")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
225
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
226 (defvar gnuserv-special-frame nil
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
227 "Frame created specially for Server.")
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 ;; We want the client-infested buffers to have some modeline
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
230 ;; identification, so we'll make a "minor mode".
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
231 (defvar gnuserv-minor-mode nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
232 (make-variable-buffer-local 'gnuserv-mode)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
233 (pushnew '(gnuserv-minor-mode " Server") minor-mode-alist)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
234
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
235
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
236 ;; Sample gnuserv-frame functions
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
237
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
238 (defun gnuserv-main-frame-function (type)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
239 "Returns a sensible value for the main Emacs frame."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
240 (if (eq type 'x)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
241 (car (frame-list))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
242 nil))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
244 (defun gnuserv-visible-frame-function (type)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
245 "Returns a frame if there is a frame that is truly visible, nil otherwise.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
246 This is meant in the X sense, so it will not return frames that are on another
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
247 visual screen. Totally visible frames are preferred. If none found, return nil."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
248 (if (eq type 'x)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
249 (cond ((car (filtered-frame-list 'frame-totally-visible-p
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
250 (selected-device))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
251 ((car (filtered-frame-list (lambda (frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
252 ;; eq t as in not 'hidden
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
253 (eq t (frame-visible-p frame)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
254 (selected-device)))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
255 nil))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
256
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
257 (defun gnuserv-special-frame-function (type)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
258 "Creates a special frame for Gnuserv and returns it on later invocations."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
259 (unless (frame-live-p gnuserv-special-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
260 (setq gnuserv-special-frame (make-frame)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
261 gnuserv-special-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
262
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
263
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
264 ;;; Communication functions
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
265
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
266 (defun gnuserv-sentinel (proc msg)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
267 (case (process-status proc)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
268 (exit (message "Gnuserv subprocess exited; restarting")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
269 ;; This will also kill all the existing clients.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
270 (gnuserv-start-1))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
271 (closed (message "Gnuserv subprocess closed"))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
272 (signal (message "Gnuserv subprocess killed"))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
273
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
274 (defun gnuserv-process-filter (proc string)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
275 "Process gnuserv client requests to execute Emacs commands."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
276 (setq gnuserv-string (concat gnuserv-string string))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
277 ;; C-d means end of request.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
278 (when (string-match "\C-d$" gnuserv-string)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
279 (cond ((string-match "^[0-9]+" gnuserv-string) ; client request id
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
280 (let ((header (read-from-string gnuserv-string)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
281 ;; Set the client we are talking to.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
282 (setq gnuserv-current-client (car header))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
283 ;; Evaluate the expression
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
284 (condition-case oops
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
285 (eval (car (read-from-string gnuserv-string (cdr header))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
286 ;; In case of an error, write the description to the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
287 ;; client, and then signal it.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
288 (error (setq gnuserv-string "")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
289 (gnuserv-write-to-client gnuserv-current-client oops)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
290 (setq gnuserv-current-client nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
291 (signal (car oops) (cdr oops)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
292 (quit (setq gnuserv-string "")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
293 (gnuserv-write-to-client gnuserv-current-client oops)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
294 (setq gnuserv-current-client nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
295 (signal 'quit nil)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
296 (setq gnuserv-string "")))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
297 (t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
298 (error "%s: invalid response from gnuserv" gnuserv-string)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
299 (setq gnuserv-string "")))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
300
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
301 (defun gnuserv-write-to-client (client-id form)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
302 "Write the given form to the given client via the gnuserv process."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
303 (when (eq (process-status gnuserv-process) 'run)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
304 (let* ((result (format "%s" form))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
305 (s (format "%s/%d:%s\n" client-id
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
306 (length result) result)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
307 (process-send-string gnuserv-process s))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
308
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
309
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
310 ;; The following two functions are helper functions, used by
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
311 ;; gnuclient.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
312
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
313 (defun gnuserv-eval (form)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
314 "Evaluate form and return result to client."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
315 (gnuserv-write-to-client gnuserv-current-client (eval form))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
316 (setq gnuserv-current-client nil))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
317
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
318 (defun gnuserv-eval-quickly (form)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
319 "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
320 This order is important as not to keep the client waiting."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
321 (gnuserv-write-to-client gnuserv-current-client nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
322 (setq gnuserv-current-client nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
323 (eval form))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
324
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
325
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
326 ;; "Execute" a client connection, called by gnuclient. This is the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
327 ;; backbone of gnuserv.el.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
328 (defun gnuserv-edit-files (type list &optional flags)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
329 "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
330 The visited buffers are memorized, so that when \\[gnuserv-edit] is invoked
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
331 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
332 client will be invoked that the edit is finished.
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
333
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
334 TYPE should either be a (tty TTY TERM PID) list, or (x DISPLAY) list.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
335 If FLAGS is `quick', just edit the files in Emacs.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
336 If FLAGS is `view', view the files read-only."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
337 (or (not flags)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
338 (memq flags '(quick view))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
339 (error "Invalid flag %s" flags))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
340 (let* ((old-device-num (length (device-list)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
341 (new-frame nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
342 (dest-frame (if (functionp gnuserv-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
343 (funcall gnuserv-frame (car type))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
344 gnuserv-frame))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
345 ;; The gnuserv-frame dependencies are ugly.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
346 (device (cond ((frame-live-p dest-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
347 (frame-device dest-frame))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
348 ((null dest-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
349 (case (car type)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
350 (tty (apply 'make-tty-device (cdr type)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
351 (x (make-x-device (cadr type)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
352 (t (error "Invalid device type"))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
353 (t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
354 (selected-device))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
355 (frame (cond ((frame-live-p dest-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
356 dest-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
357 ((null dest-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
358 (setq new-frame (make-frame nil device))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
359 new-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
360 (t (selected-frame))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
361 (client (make-gnuclient :id gnuserv-current-client
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
362 :device device
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
363 :frame new-frame)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
364 (setq gnuserv-current-client nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
365 ;; If the device was created by this client, push it to the list.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
366 (and (/= old-device-num (length (device-list)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
367 (push device gnuserv-devices))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
368 ;; Visit all the listed files.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
369 (while list
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
370 (let ((line (caar list)) (path (cdar list)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
371 (select-frame frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
372 ;; Visit the file.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
373 (funcall (if (eq flags 'view)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
374 gnuserv-view-file-function
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
375 gnuserv-find-file-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
376 path)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
377 (goto-line line)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
378 (run-hooks 'gnuserv-visit-hook)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
379 ;; Don't memorize the quick and view buffers.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
380 (when (null flags)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
381 (pushnew (current-buffer) (gnuclient-buffers client))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
382 (setq gnuserv-minor-mode t))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
383 (pop list)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
384 (cond ((and flags (device-on-window-system-p device))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
385 ;; Exit if on X device, and quick or view.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
386 ;; NOTE: if the client is to finish now, it must absolutely
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
387 ;; /not/ be included to the list of clients. This way the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
388 ;; client-ids should be unique.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
389 (gnuserv-write-to-client (gnuclient-id client) nil))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
390 (t
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
391 ;; Else, the client gets a vote.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
392 (push client gnuserv-clients)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
393 ;; Explain buffer exit options. If dest-frame is nil, the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
394 ;; user can exit via `delete-frame'. OTOH, if FLAGS are
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
395 ;; nil and there are some buffers, the user can exit via
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
396 ;; `gnuserv-edit'.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
397 (if (and (null flags)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
398 (gnuclient-buffers client))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
399 (message (substitute-command-keys
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
400 "Type `\\[gnuserv-edit]' to finish editing"))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
401 (or dest-frame
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
402 (message (substitute-command-keys
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
403 "Type `\\[delete-frame]' to finish editing"))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
405
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
406 ;;; Functions that hook into Emacs in various way to enable operation
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
407
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
408 ;; Defined later.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
409 (add-hook 'kill-emacs-hook 'gnuserv-kill-all-clients t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
410
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
411 ;; A helper function; used by others.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
412 (defun gnuserv-buffer-clients (buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
413 "Returns a list of clients to which BUFFER belongs."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
414 (let ((client gnuserv-clients)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
415 res)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
416 (while client
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
417 (if (memq buffer (gnuclient-buffers (car client)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
418 (push (car client) res))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
419 (pop client))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
420 res))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
421
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
422 ;; This function makes sure that a killed buffer is deleted off the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
423 ;; list for the particular client.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
424 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
425 ;; This hooks into `kill-buffer-hook'. It is *not* a replacement for
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
426 ;; `kill-buffer' (thanks God).
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
427 (defun gnuserv-kill-buffer-function ()
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
428 "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
429 Any client that remains \"empty\" after the removal is informed that the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
430 editing has ended."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
431 (let* ((buf (current-buffer))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
432 (clients (gnuserv-buffer-clients buf)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
433 (while clients
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
434 (callf2 delq buf (gnuclient-buffers (car clients)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
435 ;; If no more buffers, kill the client.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
436 (when (null (gnuclient-buffers (car clients)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
437 (gnuserv-kill-client (car clients)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
438 (pop clients))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
439
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
440 (add-hook 'kill-buffer-hook 'gnuserv-kill-buffer-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
441
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
442 ;; Ask for confirmation before killing a buffer that belongs to a
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
443 ;; living client.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
444 (defun gnuserv-kill-buffer-query-function ()
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
445 (or gnuserv-kill-quietly
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
446 (not (gnuserv-buffer-clients (current-buffer)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
447 (yes-or-no-p
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
448 (format "Buffer %s belongs to gnuserv client(s); kill anyway? "
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
449 (current-buffer)))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
450
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
451 (add-hook 'kill-buffer-query-functions
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
452 'gnuserv-kill-buffer-query-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
453
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
454 (defun gnuserv-kill-emacs-query-function ()
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
455 (or gnuserv-kill-quietly
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
456 (not (some 'gnuclient-buffers gnuserv-clients))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
457 (yes-or-no-p "Gnuserv buffers still have clients; exit anyway? ")))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
458
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
459 (add-hook 'kill-emacs-query-functions
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
460 'gnuserv-kill-emacs-query-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
461
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
462 ;; 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
463 ;; as well. This is why we hook into `delete-device-hook'.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
464 (defun gnuserv-check-device (device)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
465 (when (memq device gnuserv-devices)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
466 (let ((client gnuserv-clients))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
467 (while client
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
468 (when (eq device (gnuclient-device (car client)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
469 ;; we must make sure that the server kill doesn't result in
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
470 ;; killing the device, because it would cause a device-dead
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
471 ;; error when `delete-device' tries to do the job later.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
472 (gnuserv-kill-client (car client) t))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
473 (pop client)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
474 (callf2 delq device gnuserv-devices)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
475
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
476 (add-hook 'delete-device-hook 'gnuserv-check-device)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
477
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
478 (defun gnuserv-temp-file-p (buffer)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
479 "Return non-nil if BUFFER contains a file considered temporary.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
480 These are files whose names suggest they are repeatedly
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
481 reused to pass information to another program.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
482
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
483 The variable `gnuserv-temp-file-regexp' controls which filenames
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
484 are considered temporary."
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
485 (and (buffer-file-name buffer)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
486 (string-match gnuserv-temp-file-regexp (buffer-file-name buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
488 (defun gnuserv-kill-client (client &optional leave-frame)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
489 "Kill the gnuclient CLIENT.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
490 This will do away with all the associated buffers. If LEAVE-FRAME,
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
491 the function will not remove the frames associated with the client."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
492 ;; Order is important: first delete client from gnuserv-clients, to
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
493 ;; prevent gnuserv-buffer-done-1 calling us recursively.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
494 (callf2 delq client gnuserv-clients)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
495 ;; Process the buffers.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
496 (mapc 'gnuserv-buffer-done-1 (gnuclient-buffers client))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
497 (unless leave-frame
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
498 (let ((device (gnuclient-device client)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
499 ;; kill frame created by this client (if any), unless
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
500 ;; specifically requested otherwise.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
501 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
502 ;; note: last frame on a device will not be deleted here.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
503 (when (and (gnuclient-frame client)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
504 (frame-live-p (gnuclient-frame client))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
505 (second (device-frame-list device)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
506 (delete-frame (gnuclient-frame client)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
507 ;; 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
508 ;; by any client, delete it.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
509 (when (and (device-live-p device)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
510 (memq device gnuserv-devices)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
511 (second (device-list))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
512 (not (member* device gnuserv-clients
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
513 :key 'gnuclient-device)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
514 ;; `gnuserv-check-device' will remove it from `gnuserv-devices'.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
515 (delete-device device))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
516 ;; Notify the client.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
517 (gnuserv-write-to-client (gnuclient-id client) nil))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
519 ;; Do away with the buffer.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
520 (defun gnuserv-buffer-done-1 (buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
521 (let ((clients (gnuserv-buffer-clients buffer)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
522 (while clients
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
523 (callf2 delq buffer (gnuclient-buffers (car clients)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
524 (when (null (gnuclient-buffers (car clients)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
525 (gnuserv-kill-client (car clients)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
526 (pop clients))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
527 ;; Get rid of the buffer
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
528 (save-excursion
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
529 (set-buffer buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
530 (run-hooks 'gnuserv-done-hook)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
531 (setq gnuserv-minor-mode nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
532 (funcall (if (gnuserv-temp-file-p buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
533 gnuserv-done-temp-file-function
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
534 gnuserv-done-function)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
535 buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
537
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
538 ;;; Higher-level functions
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
540 ;; Choose a `next' server buffer, according to several criteria, and
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
541 ;; return it. If none appropriate are found, return nil.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
542 (defun gnuserv-next-buffer ()
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
543 (let* ((frame (selected-frame))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
544 (device (selected-device))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
545 client)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
546 (cond
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
547 ;; If we have a client belonging to this frame, return
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
548 ;; the first buffer from it.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
549 ((setq client
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
550 (car (member* frame gnuserv-clients :key 'gnuclient-frame)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
551 (car (gnuclient-buffers client)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
552 ;; Else, look for a device.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
553 ((and
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
554 (memq (selected-device) gnuserv-devices)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
555 (setq client
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
556 (car (member* device gnuserv-clients :key 'gnuclient-device))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
557 (car (gnuclient-buffers client)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
558 ;; Else, try to find just any client, and return its first buffer.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
559 (gnuserv-clients
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
560 (car (gnuclient-buffers (car gnuserv-clients))))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
561 ;; Oh, give up.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
562 (t nil))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
564 (defun gnuserv-buffer-done (buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
565 "Mark BUFFER as \"done\" for its client(s).
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
566 Calls `gnuserv-done-function' and returns another gnuserv buffer as a
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
567 suggestion for the new current buffer."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
568 ;; Check whether this is the real thing.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
569 (unless (gnuserv-buffer-clients buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
570 (error "%s does not belong to a gnuserv client" buffer))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
571 ;; Backup/ask query.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
572 (if (gnuserv-temp-file-p buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
573 ;; For a temp file, save, and do NOT make a non-numeric backup
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
574 ;; Why does server.el explicitly back up temporary files?
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
575 (let ((version-control nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
576 (buffer-backed-up (not gnuserv-make-temp-file-backup)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
577 (save-buffer))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
578 (if (and (buffer-modified-p)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
579 (y-or-n-p (concat "Save file " buffer-file-name "? ")))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
580 (save-buffer buffer)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
581 (gnuserv-buffer-done-1 buffer)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
582 (gnuserv-next-buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
584 ;; Called by `gnuserv-start-1' to clean everything. Hooked into
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
585 ;; `kill-emacs-hook', too.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
586 (defun gnuserv-kill-all-clients ()
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
587 "Kill all the gnuserv clients. Ruthlessly."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
588 (mapc 'gnuserv-kill-client gnuserv-clients))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
589
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
590 ;; Actually start the process. Kills all the clients before-hand.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
591 (defun gnuserv-start-1 (&optional leave-dead)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
592 (gnuserv-kill-all-clients)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
593 (when gnuserv-process
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
594 (set-process-sentinel gnuserv-process nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
595 (condition-case ()
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
596 (delete-process gnuserv-process)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
597 (error nil)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
598 ;; If we already had a server, clear out associated status.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
599 (unless leave-dead
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
600 (setq gnuserv-string "")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
601 (setq gnuserv-current-client nil)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
602 (let ((process-connection-type t))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
603 (setq gnuserv-process
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
604 (start-process "gnuserv" nil gnuserv-program)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
605 (set-process-sentinel gnuserv-process 'gnuserv-sentinel)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
606 (set-process-filter gnuserv-process 'gnuserv-process-filter)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
607 (process-kill-without-query gnuserv-process)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
608
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
609
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
610 ;;; User-callable functions:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (defun gnuserv-start (&optional leave-dead)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 "Allow this Emacs process to be a server for client processes.
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
615 This starts a gnuserv communications subprocess through which
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 client \"editors\" (gnuclient and gnudoit) can send editing commands to
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
617 this Emacs job. See the gnuserv(1) manual page for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 Prefix arg means just kill any existing server communications subprocess."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;; kill it dead!
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
622 (and gnuserv-process
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
623 (not leave-dead)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
624 (message "Restarting gnuserv"))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
625 (gnuserv-start-1 leave-dead))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
627 ;;;###autoload
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
628 (defun gnuserv-edit (&optional arg)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
629 "Mark the current gnuserv editing buffer as \"done\", and switch to next one.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
631 The `gnuserv-done-function' is used to dispose of the buffer after marking it
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
632 as done; it is `kill-buffer' by default.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
634 Files that match `gnuserv-temp-file-regexp' are considered temporary and
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
635 are saved unconditionally and backed up if `gnuserv-make-temp-file-backup'
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
636 is non-nil. They are disposed of using `gnuserv-done-temp-file-function'.
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 108
diff changeset
637
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
638 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
639
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
640 If invoked with a prefix argument, or if there is no gnuserv process
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
641 running, only starts server process. Invoked with \\[gnuserv-edit]."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (interactive "P")
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
643 (if (or arg (not gnuserv-process)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
644 (memq (process-status gnuserv-process) '(signal exit)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
645 (gnuserv-start)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
646 (switch-to-buffer (or (gnuserv-buffer-done (current-buffer))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
647 (current-buffer)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
649 ;;;###autoload
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 136
diff changeset
650 (global-set-key "\C-x#" 'gnuserv-edit)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (provide 'gnuserv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
654 ;;; gnuserv.el ends here