annotate lisp/packages/gnuserv.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 56c54cf7c5b6
children c7528f8e288d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ; Lisp Interface code between GNU Emacs and gnuserv.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ; Copying is permitted under those conditions described by the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ; General Public License.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
8 ; Copyright (C) 1989-1994 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ; Author: Andy Norman (ange@hplb.hpl.hp.com) based on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ; 'lisp/server.el' from the 18.52 GNU Emacs distribution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ; Please mail bugs and suggestions to the author at the above address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ; Updated for XEmacs, GNU Emacs 19 and Epoch V4 to use multiple frames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ; by Bob Weiner, <weiner@mot.com>, 1/20/94. (Still works with Emacs V18, too.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ; Modified 'server-process-filter' to use \^D as end of request terminator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ; as gnuclient and gnudoit have been modified to send. This permits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ; multi-line requests.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ; Modified 'server-make-window-visible' to work with multiple frames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ; Modified 'server-find-file' to display in a separate frame when possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ; Modified 'server-edit' to delete newly created frame when used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ; terminate an edit and to signal an error if called within a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ; non-server-edit buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ; Bob Weiner, <weiner@mot.com>, 5/9/94.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ; Added 'server-done-function' variable. Made default value 'kill-buffer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ; instead of 'bury-buffer' as in original gnuserv.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ; Darrell Kindred <dkindred+@cmu.edu> May/1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ; Updated to allow multi-line return values:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ; - output to gnuserv is "m/n:xxx" where m is the client number,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ; n is the length of the data, and xxx is the data itself, followed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ; by newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ; Arup Mukherjee <arup+@cmu.edu> May/1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ; Updated for XEmacs 19.10, and others:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ; - use find-file-other-screen if present
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
40 ; - new variable gnuserv-frame can be set to a frame or screen which
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ; is used for all edited files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ; - check to see if server.el is already loaded and complain if it is, since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ; gnuserv.el can't coexist with server.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ; - rename server-start to gnuserv-start, although server-start remains as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ; an alias. This allows gnuserv-start to be autoloaded from gnuserv.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ; - changed server-get-buffer to take into account that in newer emacsen,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ; get buffer returns nil on deleted buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ; - only try to create/delete frames or screens if window-system is non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ; (otherwise things don't work w/ emacs19 on a dumb terminal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ; Ben Wing <wing@666.com> sometime in 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ; Updated to allow `gnuattach'-type connections to the existing TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ; Ben Wing <wing@666.com> May/1996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ; patch to get TTY terminal type correct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defconst gnuserv-rcs-header-id "!Header: gnuserv.el,v 2.1 95/02/16 12:00:16 arup alpha !")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; server.el and gnuserv.el can't coexist because of conflicting defvar's and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; function names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if (and (boundp 'server-buffer-clients)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (not (featurep 'gnuserv)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (error "Can't run gnuserv because server.el appears to be loaded already"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvar gnuserv-frame nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "*If non-nil, the frame to be used to display all edited files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 If nil, then a new frame is created for each file edited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 This variable has no effect in XEmacs versions older than 19.9.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar server-done-function 'kill-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "*A function of one argument, a buffer, which removes the buffer after editing.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
76 Functions such as 'kill-buffer' and 'bury-buffer' are good values.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defvar server-program "gnuserv"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 "*The program to use as the edit server")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defvar server-process nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "The current server process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar server-string ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "The last input string from the server")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defvar current-client nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "The client we are currently talking to")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defvar server-clients nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "List of current server clients.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Each element is (CLIENTID BUFFER...) where CLIENTID is an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 that can be given to the server process to identify a client.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 When a buffer is killed, it is removed from this list.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defvar server-buffer-clients nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "List of client ids for clients requesting editing of the current buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (make-variable-buffer-local 'server-buffer-clients)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (setq-default server-buffer-clients nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (or (assq 'server-buffer-clients minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq minor-mode-alist (cons '(server-buffer-clients " Server")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun server-log (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "If a *server* buffer exists, write STRING to it for logging purposes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (get-buffer "*server*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (set-buffer "*server*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (or (bolp) (newline)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun server-sentinel (proc msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (cond ((eq (process-status proc) 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (server-log (message "Server subprocess exited")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ((eq (process-status proc) 'signal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (server-log (message "Server subprocess killed")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defun server-process-display-error (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 "Whenever a gnuserv error is reported, display it in a pop-up window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (let ((cur (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (pop-up-windows t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (pop-to-buffer (get-buffer-create "*server*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (set-window-start (selected-window) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (server-log string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (select-window cur)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defun server-process-filter (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 "Process client gnuserv requests to execute Emacs commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (setq server-string (concat server-string string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (if (string-match "\^D$" server-string) ; requests end with ctrl-D
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (if (string-match "^[0-9]+" server-string) ; client request id
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (server-log server-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (let ((header (read-from-string server-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq current-client (car header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (condition-case oops
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (eval (car (read-from-string server-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (cdr header))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (error (setq server-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (server-write-to-client current-client oops)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (setq current-client nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (signal (car oops) (cdr oops)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (quit (setq server-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (server-write-to-client current-client oops)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setq current-client nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (signal 'quit nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq server-string "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (progn ;error string from server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (server-process-display-error server-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (setq server-string "")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defun server-release-outstanding-buffers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 "Release all buffers that have clients waiting for them to be finished."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (while server-clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (let ((buffer (nth 1 (car server-clients)))) ; for all buffers...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (server-buffer-done buffer)))) ; destructively modifies server-clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defun gnuserv-start (&optional leave-dead)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 "Allow this Emacs process to be a server for client processes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 This starts a server communications subprocess through which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 client \"editors\" (gnuclient and gnudoit) can send editing commands to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 this Emacs job. See the gnuserv(1) manual page for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Prefix arg means just kill any existing server communications subprocess."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; kill it dead!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (server-release-outstanding-buffers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (set-process-sentinel server-process nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (delete-process server-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; If we already had a server, clear out associated status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (if leave-dead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (if server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (server-log (message "Restarting server")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (setq server-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (setq current-client nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (let ((process-connection-type t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (setq server-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (start-process "server" nil server-program)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (set-process-sentinel server-process 'server-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (set-process-filter server-process 'server-process-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (process-kill-without-query server-process)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; make gnuserv-start an alias to server-start, for backward compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (fset 'server-start (function gnuserv-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
199
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun server-write-to-client (client form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 "Write the given form to the given client via the server process."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (if (and client
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (eq (process-status server-process) 'run))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (let* ((result (format "%s" form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (s (format "%s/%d:%s\n" client (length result) result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (process-send-string server-process s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (server-log s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (defun server-eval (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 "Evaluate form and return result to client."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (server-write-to-client current-client (eval form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq current-client nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (defun server-eval-quickly (form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "Let client know that we've received the request, but eval the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 afterwards in order to not keep the client waiting."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (server-write-to-client current-client nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (setq current-client nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (eval form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (defun server-make-window-visible ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 "Try to make this window even more visible."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
224 (cond
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
225 ;; XEmacs can (in theory) raise any kind of frame
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
226 ((fboundp 'raise-frame)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
227 (raise-frame (selected-frame)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
228 ((not (and (boundp 'window-system) window-system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
229 nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
230 ((fboundp 'deiconify-screen)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
231 (deiconify-screen (selected-screen))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
232 (raise-screen (selected-screen)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
233 ((fboundp 'mapraised-screen)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
234 (mapraised-screen))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
235 ((fboundp 'x-remap-window)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
236 (x-remap-window)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
237 ;; give window chance to re-display text
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
238 (accept-process-output))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
240 (defun server-tty-find-file (tty termtype file)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
241 (let ((device (make-tty-device tty termtype)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (select-frame (make-frame nil device))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (if (not file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (switch-to-buffer (get-buffer-create "*scratch*"))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
245 (find-file file))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (defun server-find-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 "Edit file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 Switch to a buffer visiting file FILENAME,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 creating one if none already exists."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (let ((obuf (get-file-buffer file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; XEmacs addition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (force-dialog-box-use t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (if (and obuf (set-buffer obuf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if (file-exists-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (if (or (not (verify-visited-file-modtime obuf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (buffer-modified-p obuf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (revert-buffer t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (if (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (concat "File no longer exists: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ", write buffer to file? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (write-file file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (cond ((and window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 gnuserv-frame (fboundp 'frame-live-p) ;; v19 & XEmacs 19.12+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (frame-live-p gnuserv-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (select-frame gnuserv-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (find-file file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ((and window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 gnuserv-frame (fboundp 'live-screen-p) ;; XEmacs 19.9+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (live-screen-p gnuserv-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (select-screen gnuserv-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (find-file file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ((and window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (fboundp 'select-frame)) ;; v19 & XEmacs 19.12+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (select-frame (make-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (find-file file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ((and window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (fboundp 'select-screen) ;; XEmacs 19.10+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (fboundp 'make-screen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (select-screen (make-screen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (find-file file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ((and (eq window-system 'x) ;; XEmacs 19.9-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (fboundp 'select-screen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (fboundp 'x-create-screen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (select-screen (x-create-screen nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (find-file file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ((and window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (fboundp 'create-screen)) ;; epoch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if (screenp gnuserv-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (progn (select-screen gnuserv-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (find-file file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (select-screen (create-screen (find-file-noselect file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
300 (t (find-file file))))) ;; emacs18+
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (defun server-edit-files-quickly (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 "For each (line-number . file) pair in LIST, edit the file at line-number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Unlike (server-edit-files), no information is saved about clients waiting on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 edits to this buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (server-write-to-client current-client nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (setq current-client nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (let ((line (car (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (path (cdr (car list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (server-find-file path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (server-make-window-visible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (goto-line line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (setq list (cdr list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (defun server-edit-files (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 "For each (line-number . file) pair in LIST, edit the file at line-number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 Save enough information for (server-kill-buffer) to inform the client when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 the edit is finished."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (let ((line (car (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (path (cdr (car list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (server-find-file path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (server-make-window-visible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (let ((old-clients (assq current-client server-clients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (goto-line line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq server-buffer-clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (cons current-client server-buffer-clients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (if old-clients ;client already waiting for buffers?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (nconc old-clients (list buffer)) ;yes -- append this one as well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (setq server-clients ;nope -- make a new record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (cons (list current-client buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 server-clients)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (message (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (if (and (boundp 'infodock-version) window-system)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 "Type {\\[server-edit]} or select Frame/Delete to finish edit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 "When done with a buffer, type \\[server-edit]."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
343 (defun server-tty-edit-files (tty termtype list)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 "For each (line-number . file) pair in LIST, edit the file at line-number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 Save enough information for (server-kill-buffer) to inform the client when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 the edit is finished."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (or list (setq list '((1 . nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (let ((line (car (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (path (cdr (car list))))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
351 (server-tty-find-file tty termtype path)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (server-make-window-visible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (let ((old-clients (assq current-client server-clients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (goto-line line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (setq server-buffer-clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (cons current-client server-buffer-clients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (if old-clients ;client already waiting for buffers?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (nconc old-clients (list buffer)) ;yes -- append this one as well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (setq server-clients ;nope -- make a new record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (cons (list current-client buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 server-clients)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (message (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (if (and (boundp 'infodock-version) window-system)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 "Type {\\[server-edit]} or select Frame/Delete to finish edit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 "When done with a buffer, type \\[server-edit]."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (defun server-get-buffer (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 "One arg, a BUFFER or a buffer name. Return the buffer object even if killed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 Signal an error if there is no record of BUFFER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (if (null buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (let ((buf (get-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (if (null buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (if (bufferp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (if (stringp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (error "No buffer named %s" buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (error "Invalid buffer argument")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defun server-kill-buffer (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 "Kill the BUFFER. The argument may be a buffer object or buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 NOTE: This function has been enhanced to allow for remote editing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 in the following way:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 If the buffer is waited upon by one or more clients, and a client is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 not waiting for other buffers to be killed, then the client is told
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 that the buffer has been killed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (interactive "bKill buffer ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (setq buffer (server-get-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (if (buffer-name buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (let ((old-clients server-clients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (server-real-kill-buffer buffer) ;try to kill it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (if (buffer-name buffer) ;succeeded in killing?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 nil ;nope
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (while old-clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (let ((client (car old-clients)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (delq buffer client)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (if (cdr client) ;pending buffers?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 nil ;yep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (server-write-to-client (car client) nil) ;nope, tell client
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (setq server-clients (delq client server-clients))))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
407 (setq old-clients (cdr old-clients))))))))
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 30
diff changeset
408
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 30
diff changeset
409
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (defun server-kill-all-local-variables ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 "Eliminate all the buffer-local variable values of the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 This buffer will then see the default values of all variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 NOTE: This function has been modified to ignore the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 server-buffer-clients."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (let ((clients server-buffer-clients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (server-real-kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (if clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (setq server-buffer-clients clients))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (or (fboundp 'server-real-kill-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (fset 'server-real-kill-buffer (symbol-function 'kill-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (fset 'kill-buffer 'server-kill-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (or (fboundp 'server-real-kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (fset 'server-real-kill-all-local-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (symbol-function 'kill-all-local-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (fset 'kill-all-local-variables 'server-kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (defun server-buffer-done (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 "Mark BUFFER as \"done\" for its client(s).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 Buries the buffer, and returns another server buffer as a suggestion for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 new current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (let ((next-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (old-clients server-clients))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (while old-clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (let ((client (car old-clients)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (or next-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq next-buffer (nth 1 (memq buffer client))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (delq buffer client)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;; If client now has no pending buffers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;; tell it that it is done, and forget it entirely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (if (cdr client)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 nil
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
448 (server-write-to-client (car client) nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
449 (setq server-clients (delq client server-clients))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (setq old-clients (cdr old-clients)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
451 (if (buffer-name buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
452 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
453 (set-buffer buffer)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
454 (setq server-buffer-clients nil)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
455 (funcall server-done-function buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 next-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (defun mh-draft-p (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 "Return non-nil if this BUFFER is an mh <draft> file. Since MH deletes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 draft *BEFORE* it is edited, the server treats them specially."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; This may not be appropriately robust for all cases.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (string= (buffer-name buffer) "draft"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (defun server-done ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 "Offer to save current buffer and mark it as \"done\" for clients.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 Also bury it, and return a suggested new current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (let ((buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (if server-buffer-clients
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (progn
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
472 (if (mh-draft-p buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (progn (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (write-region (point-min) (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (concat buffer-file-name "~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (kill-buffer buffer))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
477 (if (and (buffer-modified-p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
478 (y-or-n-p (concat "Save file " buffer-file-name "? ")))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
479 (save-buffer buffer)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (server-buffer-done buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (defun server-edit (&optional arg)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
484 "Switch to next server editing buffer and mark current one as \"done\".
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
485 If a server buffer is current, it is marked \"done\" and optionally saved.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
486 MH <draft> files are always saved and backed up, no questions asked.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
487 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
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 If invoked with a prefix argument, or if there is no server process running,
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
490 starts server process and that is all. Invoked by \\[server-edit]."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (if (or arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (not server-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (memq (process-status server-process) '(signal exit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (server-start nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (if server-buffer-clients
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
497 (progn (server-switch-buffer (server-done))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
498 (cond ((fboundp 'console-type) ;; XEmacs 19.14+
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
499 (or (and (equal (console-type) 'x)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
500 gnuserv-frame
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
501 (frame-live-p gnuserv-frame))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
502 (condition-case ()
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
503 (delete-frame (selected-frame) nil)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
504 (error
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
505 (message "Not deleting last visible frame...")))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
506 ((or (not window-system)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (and gnuserv-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (or (and (fboundp 'frame-live-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (frame-live-p gnuserv-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (and (fboundp 'live-screen-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (live-screen-p gnuserv-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (and (fboundp 'create-screen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (screenp gnuserv-frame)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ()) ;; do nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 ((fboundp 'delete-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (delete-frame (selected-frame) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ((fboundp 'delete-screen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (delete-screen))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 "(server-edit): Use only on buffers created by external programs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
523 (defun server-switch-buffer (next-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 "Switch to NEXT-BUFFER if a live buffer, otherwise switch to another buffer
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
525 with gnuserv clients. If no such buffer is available, simply choose another
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
526 one."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (if next-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (if (and (bufferp next-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (buffer-name next-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (switch-to-buffer next-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; If NEXT-BUFFER is a dead buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;; remove the server records for it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; and try the next surviving server buffer.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
534 (server-switch-buffer
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
535 (server-buffer-done next-buffer)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
536 (if server-clients
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
537 (server-switch-buffer (nth 1 (car server-clients)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
538 (switch-to-buffer (other-buffer)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (global-set-key "\C-x#" 'server-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (provide 'gnuserv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543