Mercurial > hg > xemacs-beta
comparison lisp/packages/server.el @ 2:ac2d302a0011 r19-15b2
Import from CVS: tag r19-15b2
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:35 +0200 |
parents | 376386a54a3c |
children |
comparison
equal
deleted
inserted
replaced
1:c0c6a60d29db | 2:ac2d302a0011 |
---|---|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 ;; General Public License for more details. | 20 ;; General Public License for more details. |
21 | 21 |
22 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free | 23 ;; along with XEmacs; see the file COPYING. If not, write to the Free |
24 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
25 | 25 ;; 02111-1307, USA. |
26 ;;; Synched up with FSF 19.30. | 26 |
27 ;;; Synched up with FSF 19.34. | |
27 | 28 |
28 ;;; Commentary: | 29 ;;; Commentary: |
29 | 30 |
30 ;;; This Lisp code is run in Emacs when it is to operate as | 31 ;; This Lisp code is run in Emacs when it is to operate as |
31 ;;; a server for other processes. | 32 ;; a server for other processes. |
32 | 33 |
33 ;;; Load this library and do M-x server-edit to enable Emacs as a server. | 34 ;; Load this library and do M-x server-edit to enable Emacs as a server. |
34 ;;; Emacs runs the program ../etc/emacsserver as a subprocess | 35 ;; Emacs runs the program ../../lib-src/emacsserver as a subprocess |
35 ;;; for communication with clients. If there are no client buffers to edit, | 36 ;; for communication with clients. If there are no client buffers to edit, |
36 ;;; server-edit acts like (switch-to-buffer (other-buffer)) | 37 ;; server-edit acts like (switch-to-buffer (other-buffer)) |
37 | 38 |
38 ;;; When some other program runs "the editor" to edit a file, | 39 ;; When some other program runs "the editor" to edit a file, |
39 ;;; "the editor" can be the Emacs client program ../etc/emacsclient. | 40 ;; "the editor" can be the Emacs client program ../../lib-src/emacsclient. |
40 ;;; This program transmits the file names to Emacs through | 41 ;; This program transmits the file names to Emacs through |
41 ;;; the server subprocess, and Emacs visits them and lets you edit them. | 42 ;; the server subprocess, and Emacs visits them and lets you edit them. |
42 | 43 |
43 ;;; Note that any number of clients may dispatch files to emacs to be edited. | 44 ;; Note that any number of clients may dispatch files to emacs to be edited. |
44 | 45 |
45 ;;; When you finish editing a Server buffer, again call server-edit | 46 ;; When you finish editing a Server buffer, again call server-edit |
46 ;;; to mark that buffer as done for the client and switch to the next | 47 ;; to mark that buffer as done for the client and switch to the next |
47 ;;; Server buffer. When all the buffers for a client have been edited | 48 ;; Server buffer. When all the buffers for a client have been edited |
48 ;;; and exited with server-edit, the client "editor" will return | 49 ;; and exited with server-edit, the client "editor" will return |
49 ;;; to the program that invoked it. | 50 ;; to the program that invoked it. |
50 | 51 |
51 ;;; Your editing commands and Emacs's display output go to and from | 52 ;; Your editing commands and Emacs's display output go to and from |
52 ;;; the terminal in the usual way. Thus, server operation is possible | 53 ;; the terminal in the usual way. Thus, server operation is possible |
53 ;;; only when Emacs can talk to the terminal at the time you invoke | 54 ;; only when Emacs can talk to the terminal at the time you invoke |
54 ;;; the client. This is possible in four cases: | 55 ;; the client. This is possible in four cases: |
55 | 56 |
56 ;;; 1. On a window system, where Emacs runs in one window and the | 57 ;; 1. On a window system, where Emacs runs in one window and the |
57 ;;; program that wants to use "the editor" runs in another. | 58 ;; program that wants to use "the editor" runs in another. |
58 | 59 |
59 ;;; 2. On a multi-terminal system, where Emacs runs on one terminal and the | 60 ;; 2. On a multi-terminal system, where Emacs runs on one terminal and the |
60 ;;; program that wants to use "the editor" runs on another. | 61 ;; program that wants to use "the editor" runs on another. |
61 | 62 |
62 ;;; 3. When the program that wants to use "the editor" is running | 63 ;; 3. When the program that wants to use "the editor" is running |
63 ;;; as a subprocess of Emacs. | 64 ;; as a subprocess of Emacs. |
64 | 65 |
65 ;;; 4. On a system with job control, when Emacs is suspended, the program | 66 ;; 4. On a system with job control, when Emacs is suspended, the program |
66 ;;; that wants to use "the editor" will stop and display | 67 ;; that wants to use "the editor" will stop and display |
67 ;;; "Waiting for Emacs...". It can then be suspended, and Emacs can be | 68 ;; "Waiting for Emacs...". It can then be suspended, and Emacs can be |
68 ;;; brought into the foreground for editing. When done editing, Emacs is | 69 ;; brought into the foreground for editing. When done editing, Emacs is |
69 ;;; suspended again, and the client program is brought into the foreground. | 70 ;; suspended again, and the client program is brought into the foreground. |
70 | 71 |
71 ;;; The buffer local variable "server-buffer-clients" lists | 72 ;; The buffer local variable "server-buffer-clients" lists |
72 ;;; the clients who are waiting for this buffer to be edited. | 73 ;; the clients who are waiting for this buffer to be edited. |
73 ;;; The global variable "server-clients" lists all the waiting clients, | 74 ;; The global variable "server-clients" lists all the waiting clients, |
74 ;;; and which files are yet to be edited for each. | 75 ;; and which files are yet to be edited for each. |
75 | 76 |
76 ;;; Code: | 77 ;;; Code: |
77 | 78 |
78 (defvar server-program (expand-file-name "emacsserver" exec-directory) | 79 (defvar server-program (expand-file-name "emacsserver" exec-directory) |
79 "*The program to use as the edit server.") | 80 "*The program to use as the edit server.") |
192 (files nil) | 193 (files nil) |
193 (lineno 1)) | 194 (lineno 1)) |
194 ;; Remove this line from STRING. | 195 ;; Remove this line from STRING. |
195 (setq string (substring string (match-end 0))) | 196 (setq string (substring string (match-end 0))) |
196 (if (string-match "^Error: " request) | 197 (if (string-match "^Error: " request) |
197 (message (concat "Server error: " (substring request (match-end 0)))) | 198 (message "Server error: %s" (substring request (match-end 0))) |
198 (if (string-match "^Client: " request) | 199 (if (string-match "^Client: " request) |
199 (progn | 200 (progn |
200 (setq request (substring request (match-end 0))) | 201 (setq request (substring request (match-end 0))) |
201 (setq client (list (substring request 0 (string-match " " request)))) | 202 (setq client (list (substring request 0 (string-match " " request)))) |
202 (setq request (substring request (match-end 0))) | 203 (setq request (substring request (match-end 0))) |
203 (while (string-match "[^ ]+ " request) | 204 (while (string-match "[^ ]+ " request) |
204 (let ((arg | 205 (let ((arg |
205 (substring request (match-beginning 0) (1- (match-end 0))))) | 206 (substring request (match-beginning 0) (1- (match-end 0))))) |
206 (setq request (substring request (match-end 0))) | 207 (setq request (substring request (match-end 0))) |
207 (if (string-match "\\`\\+[0-9]+\\'" arg) | 208 (if (string-match "\\`\\+[0-9]+\\'" arg) |
209 ;; ARG is a line number option. | |
208 (setq lineno (read (substring arg 1))) | 210 (setq lineno (read (substring arg 1))) |
211 ;; ARG is a file name. | |
212 ;; Collapse multiple slashes to single slashes. | |
213 (setq arg (command-line-normalize-file-name arg)) | |
209 (setq files | 214 (setq files |
210 (cons (list arg lineno) | 215 (cons (list arg lineno) |
211 files)) | 216 files)) |
212 (setq lineno 1)))) | 217 (setq lineno 1)))) |
213 (server-visit-files files client) | 218 (server-visit-files files client) |
221 (setq server-previous-string string)) | 226 (setq server-previous-string string)) |
222 | 227 |
223 (defun server-visit-files (files client) | 228 (defun server-visit-files (files client) |
224 "Finds FILES and returns the list CLIENT with the buffers nconc'd. | 229 "Finds FILES and returns the list CLIENT with the buffers nconc'd. |
225 FILES is an alist whose elements are (FILENAME LINENUMBER)." | 230 FILES is an alist whose elements are (FILENAME LINENUMBER)." |
226 (let (client-record (obuf (current-buffer))) | 231 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries. |
232 ;; XEmacs: this doesn't work as far as I can tell. -sb | |
233 (let (client-record (last-nonmenu-event t) (obuf (current-buffer))) | |
227 ;; Restore the current buffer afterward, but not using save-excursion, | 234 ;; Restore the current buffer afterward, but not using save-excursion, |
228 ;; because we don't want to save point in this buffer | 235 ;; because we don't want to save point in this buffer |
229 ;; if it happens to be one of those specified by the server. | 236 ;; if it happens to be one of those specified by the server. |
230 (unwind-protect | 237 (unwind-protect |
231 (while files | 238 (while files |
282 (progn | 289 (progn |
283 ;; Don't send emacsserver two commands in close succession. | 290 ;; Don't send emacsserver two commands in close succession. |
284 ;; It cannot handle that. | 291 ;; It cannot handle that. |
285 (or first (sit-for 1)) | 292 (or first (sit-for 1)) |
286 (setq first nil) | 293 (setq first nil) |
294 ;; XEmacs: FSF uses obsolete send-string | |
287 (process-send-string server-process | 295 (process-send-string server-process |
288 (format "Close: %s Done\n" (car client))) | 296 (format "Close: %s Done\n" (car client))) |
289 (server-log (format "Close: %s Done\n" (car client))))) | 297 (server-log (format "Close: %s Done\n" (car client))))) |
290 (setq server-clients (delq client server-clients)))) | 298 (setq server-clients (delq client server-clients)))) |
291 (setq old-clients (cdr old-clients))) | 299 (setq old-clients (cdr old-clients))) |