Mercurial > hg > xemacs-beta
comparison lisp/packages/gnuserv.el @ 114:8619ce7e4c50 r20-1b9
Import from CVS: tag r20-1b9
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:21:54 +0200 |
parents | 360340f9fd5f |
children | cca96a509cfe |
comparison
equal
deleted
inserted
replaced
113:2ec2fe4a4c89 | 114:8619ce7e4c50 |
---|---|
3 ; This file is part of GNU Emacs. | 3 ; This file is part of GNU Emacs. |
4 ; | 4 ; |
5 ; Copying is permitted under those conditions described by the GNU | 5 ; Copying is permitted under those conditions described by the GNU |
6 ; General Public License. | 6 ; General Public License. |
7 ; | 7 ; |
8 ; Copyright (C) 1989-1994 Free Software Foundation, Inc. | 8 ; Copyright (C) 1989-1996 Free Software Foundation, Inc. |
9 ; | 9 ; |
10 ; Author: Andy Norman (ange@hplb.hpl.hp.com) based on | 10 ; Author: Andy Norman (ange@hplb.hpl.hp.com) based on |
11 ; 'lisp/server.el' from the 18.52 GNU Emacs distribution. | 11 ; 'lisp/server.el' from the 18.52 GNU Emacs distribution. |
12 ; | 12 ; |
13 ; Please mail bugs and suggestions to the author at the above address. | 13 ; Please mail bugs and suggestions to the author at the above address. |
51 ; Ben Wing <wing@666.com> sometime in 1995 | 51 ; Ben Wing <wing@666.com> sometime in 1995 |
52 ; Updated to allow `gnuattach'-type connections to the existing TTY | 52 ; Updated to allow `gnuattach'-type connections to the existing TTY |
53 ; | 53 ; |
54 ; Ben Wing <wing@666.com> May/1996 | 54 ; Ben Wing <wing@666.com> May/1996 |
55 ; patch to get TTY terminal type correct. | 55 ; patch to get TTY terminal type correct. |
56 ; | |
57 ; Jan Vroonhof <vroonhof@math.ethz.ch> July/1996 | |
58 ; ported the server-temp-file-regexp feature from server.el | |
59 ; ported server hooks from server.el | |
60 ; ported kill-*-query functions from server.el (and made it optional) | |
61 ; synced other behaviour with server.el | |
56 | 62 |
57 | 63 |
58 | 64 |
59 (defconst gnuserv-rcs-header-id "!Header: gnuserv.el,v 2.1 95/02/16 12:00:16 arup alpha !") | 65 (defconst gnuserv-rcs-header-id "!Header: gnuserv.el,v 2.1 95/02/16 12:00:16 arup alpha !") |
60 | 66 |
72 If nil, then a new frame is created for each file edited. | 78 If nil, then a new frame is created for each file edited. |
73 This variable has no effect in XEmacs versions older than 19.9.") | 79 This variable has no effect in XEmacs versions older than 19.9.") |
74 | 80 |
75 (defvar server-done-function 'kill-buffer | 81 (defvar server-done-function 'kill-buffer |
76 "*A function of one argument, a buffer, which removes the buffer after editing. | 82 "*A function of one argument, a buffer, which removes the buffer after editing. |
77 Functions such as 'kill-buffer' and 'bury-buffer' are good values.") | 83 Functions such as 'kill-buffer' and 'bury-buffer' are good values. See also |
84 `server-done-temp-file-function'") | |
85 | |
86 (defvar server-done-temp-file-function 'kill-buffer | |
87 "*A function of one argument, a buffer, which removes the buffer after editing a | |
88 temporary file. Functions such as 'kill-buffer' and 'bury-buffer' are | |
89 good values. See also `server-done-function'") | |
78 | 90 |
79 (defvar server-program "gnuserv" | 91 (defvar server-program "gnuserv" |
80 "*The program to use as the edit server") | 92 "*The program to use as the edit server") |
93 | |
94 | |
95 (defvar server-visit-hook nil | |
96 "*List of hooks to call when visiting a file for the Emacs server.") | |
97 | |
98 ;; defined by server.el but obsolete? | |
99 ;; (defvar server-switch-hook nil | |
100 ;; "*List of hooks to call when switching to a buffer for the Emacs server.") | |
101 | |
102 (defvar server-done-hook nil | |
103 "*List of hooks to call when done editing a buffer for the Emacs server.") | |
104 | |
81 | 105 |
82 (defvar server-process nil | 106 (defvar server-process nil |
83 "The current server process") | 107 "The current server process") |
84 | 108 |
85 (defvar server-string "" | 109 (defvar server-string "" |
95 "List of current server clients. | 119 "List of current server clients. |
96 Each element is (CLIENTID BUFFER...) where CLIENTID is an integer | 120 Each element is (CLIENTID BUFFER...) where CLIENTID is an integer |
97 that can be given to the server process to identify a client. | 121 that can be given to the server process to identify a client. |
98 When a buffer is killed, it is removed from this list.") | 122 When a buffer is killed, it is removed from this list.") |
99 | 123 |
124 (defvar server-kill-quietly nil | |
125 "If this variable is set then don't confirm kills of buffers with | |
126 clients attached") | |
127 | |
128 | |
100 (defvar server-buffer-clients nil | 129 (defvar server-buffer-clients nil |
101 "List of client ids for clients requesting editing of the current buffer.") | 130 "List of client ids for clients requesting editing of the current buffer.") |
131 | |
132 (defvar server-temp-file-regexp "^/tmp/Re\\|/draft$" | |
133 "*Regexp which should match filenames of temporary files | |
134 which are deleted and reused after each edit | |
135 by the programs that invoke the emacs server.") | |
136 | |
137 (defvar server-make-temp-file-backup nil | |
138 "Non-nil makes the server backup temporary files also") | |
102 | 139 |
103 (make-variable-buffer-local 'server-buffer-clients) | 140 (make-variable-buffer-local 'server-buffer-clients) |
104 (setq-default server-buffer-clients nil) | 141 (setq-default server-buffer-clients nil) |
105 (or (assq 'server-buffer-clients minor-mode-alist) | 142 (or (assq 'server-buffer-clients minor-mode-alist) |
106 (setq minor-mode-alist (cons '(server-buffer-clients " Server") | 143 (setq minor-mode-alist (cons '(server-buffer-clients " Server") |
107 minor-mode-alist))) | 144 minor-mode-alist))) |
145 | |
146 (defun server-temp-file-p (buffer) | |
147 "Return non-nil if BUFFER contains a file considered temporary. | |
148 These are files whose names suggest they are repeatedly | |
149 reused to pass information to another program. | |
150 | |
151 The variable `server-temp-file-regexp' controls which filenames | |
152 are considered temporary." | |
153 (and (buffer-file-name buffer) | |
154 (string-match server-temp-file-regexp (buffer-file-name buffer)))) | |
155 | |
108 | 156 |
109 (defun server-log (string) | 157 (defun server-log (string) |
110 "If a *server* buffer exists, write STRING to it for logging purposes." | 158 "If a *server* buffer exists, write STRING to it for logging purposes." |
111 (if (get-buffer "*server*") | 159 (if (get-buffer "*server*") |
112 (save-excursion | 160 (save-excursion |
198 (process-kill-without-query server-process))) | 246 (process-kill-without-query server-process))) |
199 | 247 |
200 ;; make gnuserv-start an alias to server-start, for backward compatibility | 248 ;; make gnuserv-start an alias to server-start, for backward compatibility |
201 (fset 'server-start (function gnuserv-start)) | 249 (fset 'server-start (function gnuserv-start)) |
202 | 250 |
203 | 251 ; Can gnuserv handle commands in close succesion? (See server.el line 283) JV |
204 (defun server-write-to-client (client form) | 252 (defun server-write-to-client (client form) |
205 "Write the given form to the given client via the server process." | 253 "Write the given form to the given client via the server process." |
206 (if (and client | 254 (if (and client |
207 (eq (process-status server-process) 'run)) | 255 (eq (process-status server-process) 'run)) |
208 (let* ((result (format "%s" form)) | 256 (let* ((result (format "%s" form)) |
244 (defun server-tty-find-file (tty termtype pid file) | 292 (defun server-tty-find-file (tty termtype pid file) |
245 (let ((device (make-tty-device tty termtype pid ))) | 293 (let ((device (make-tty-device tty termtype pid ))) |
246 (select-frame (make-frame nil device)) | 294 (select-frame (make-frame nil device)) |
247 (if (not file) | 295 (if (not file) |
248 (switch-to-buffer (get-buffer-create "*scratch*")) | 296 (switch-to-buffer (get-buffer-create "*scratch*")) |
249 (find-file file)))) | 297 (find-file file))) |
298 (run-hooks 'server-visit-hook)) | |
250 | 299 |
251 (defun server-find-file (file) | 300 (defun server-find-file (file) |
252 "Edit file FILENAME. | 301 "Edit file FILENAME. |
253 Switch to a buffer visiting file FILENAME, | 302 Switch to a buffer visiting file FILENAME, |
254 creating one if none already exists." | 303 creating one if none already exists." |
299 (if (screenp gnuserv-frame) | 348 (if (screenp gnuserv-frame) |
300 (progn (select-screen gnuserv-frame) | 349 (progn (select-screen gnuserv-frame) |
301 (find-file file)) | 350 (find-file file)) |
302 (select-screen (create-screen (find-file-noselect file))))) | 351 (select-screen (create-screen (find-file-noselect file))))) |
303 | 352 |
304 (t (find-file file))))) ;; emacs18+ | 353 (t (find-file file)))) ;; emacs18+ |
354 (run-hooks 'server-visit-hook)) | |
305 | 355 |
306 | 356 |
307 (defun server-edit-files-quickly (list) | 357 (defun server-edit-files-quickly (list) |
308 "For each (line-number . file) pair in LIST, edit the file at line-number. | 358 "For each (line-number . file) pair in LIST, edit the file at line-number. |
309 Unlike (server-edit-files), no information is saved about clients waiting on | 359 Unlike (server-edit-files), no information is saved about clients waiting on |
409 (server-write-to-client (car client) nil) ;nope, tell client | 459 (server-write-to-client (car client) nil) ;nope, tell client |
410 (setq server-clients (delq client server-clients)))) | 460 (setq server-clients (delq client server-clients)))) |
411 (setq old-clients (cdr old-clients)))))))) | 461 (setq old-clients (cdr old-clients)))))))) |
412 | 462 |
413 | 463 |
464 ;; Ask before killing a server buffer. | |
465 ;; It was suggested to release its client instead, | |
466 ;; but I think that is dangerous--the client would proceed | |
467 ;; using whatever is on disk in that file. -- rms. | |
468 (defun server-kill-buffer-query-function () | |
469 (or server-kill-quietly | |
470 (not server-buffer-clients) | |
471 (yes-or-no-p (format "Buffer `%s' still has clients; kill it? " | |
472 (buffer-name (current-buffer)))))) | |
473 | |
474 (add-hook 'kill-buffer-query-functions | |
475 'server-kill-buffer-query-function) | |
476 | |
477 (defun server-kill-emacs-query-function () | |
478 (let (live-client | |
479 (tail server-clients)) | |
480 ;; See if any clients have any buffers that are still alive. | |
481 (while tail | |
482 (if (memq t (mapcar 'stringp (mapcar 'buffer-name (cdr (car tail))))) | |
483 (setq live-client t)) | |
484 (setq tail (cdr tail))) | |
485 (or server-kill-quietly | |
486 (not live-client) | |
487 (yes-or-no-p "Server buffers still have clients; exit anyway? ")))) | |
488 | |
489 (add-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) | |
490 | |
491 | |
414 (defun server-kill-all-local-variables () | 492 (defun server-kill-all-local-variables () |
415 "Eliminate all the buffer-local variable values of the current buffer. | 493 "Eliminate all the buffer-local variable values of the current buffer. |
416 This buffer will then see the default values of all variables. | 494 This buffer will then see the default values of all variables. |
417 NOTE: This function has been modified to ignore the variable | 495 NOTE: This function has been modified to ignore the variable |
418 server-buffer-clients." | 496 server-buffer-clients." |
436 | 514 |
437 (defun server-buffer-done (buffer) | 515 (defun server-buffer-done (buffer) |
438 "Mark BUFFER as \"done\" for its client(s). | 516 "Mark BUFFER as \"done\" for its client(s). |
439 Buries the buffer, and returns another server buffer as a suggestion for the | 517 Buries the buffer, and returns another server buffer as a suggestion for the |
440 new current buffer." | 518 new current buffer." |
519 ; Note we do NOT return a list with a killed flag, doesn't seem usefull to me. JV | |
441 (let ((next-buffer nil) | 520 (let ((next-buffer nil) |
442 (old-clients server-clients)) | 521 (old-clients server-clients)) |
443 (while old-clients | 522 (while old-clients |
444 (let ((client (car old-clients))) | 523 (let ((client (car old-clients))) |
445 (or next-buffer | 524 (or next-buffer |
446 (setq next-buffer (nth 1 (memq buffer client)))) | 525 (setq next-buffer (nth 1 (memq buffer client)))) |
447 (delq buffer client) | 526 (delq buffer client) |
527 ;; Delete all dead buffers from CLIENT. (Why? JV , copyed from server.el) | |
528 (let ((tail client)) | |
529 (while tail | |
530 (and (bufferp (car tail)) | |
531 (null (buffer-name (car tail))) | |
532 (delq (car tail) client)) | |
533 (setq tail (cdr tail)))) | |
448 ;; If client now has no pending buffers, | 534 ;; If client now has no pending buffers, |
449 ;; tell it that it is done, and forget it entirely. | 535 ;; tell it that it is done, and forget it entirely. |
450 (if (cdr client) | 536 (if (cdr client) |
451 nil | 537 nil |
452 (if (buffer-name buffer) | 538 (if (buffer-name buffer) |
453 (save-excursion | 539 (save-excursion |
454 (set-buffer buffer) | 540 (set-buffer buffer) |
455 (setq server-buffer-clients nil))) | 541 (setq server-buffer-clients nil) |
542 (run-hooks 'server-done-hook))) | |
456 ; Order is important here -- | 543 ; Order is important here -- |
457 ; server-kill-buffer tries to notify clients that | 544 ; server-kill-buffer tries to notify clients that |
458 ; they are done, too, but if we try and notify twice, | 545 ; they are done, too, but if we try and notify twice, |
459 ; we are h0zed -- Hunter Kelly 3/3/97 | 546 ; we are h0zed -- Hunter Kelly 3/3/97 |
460 (setq server-clients (delq client server-clients)) | 547 (setq server-clients (delq client server-clients)) |
461 (funcall server-done-function buffer) | 548 (if (server-temp-file-p buffer) |
549 (funcall server-done-temp-file-function buffer) | |
550 (funcall server-done-function buffer)) | |
462 (server-write-to-client (car client) nil))) | 551 (server-write-to-client (car client) nil))) |
463 (setq old-clients (cdr old-clients))) | 552 (setq old-clients (cdr old-clients))) |
464 next-buffer)) | 553 next-buffer)) |
465 | 554 |
466 | 555 |
475 "Offer to save current buffer and mark it as \"done\" for clients. | 564 "Offer to save current buffer and mark it as \"done\" for clients. |
476 Also bury it, and return a suggested new current buffer." | 565 Also bury it, and return a suggested new current buffer." |
477 (let ((buffer (current-buffer))) | 566 (let ((buffer (current-buffer))) |
478 (if server-buffer-clients | 567 (if server-buffer-clients |
479 (progn | 568 (progn |
480 (if (mh-draft-p buffer) | 569 (if (mh-draft-p buffer);; Does this comflict with temp-file ? JV |
481 (progn (save-buffer) | 570 (progn (save-buffer) |
482 (write-region (point-min) (point-max) | 571 (write-region (point-min) (point-max) |
483 (concat buffer-file-name "~")) | 572 (concat buffer-file-name "~")) |
484 (kill-buffer buffer)) | 573 (kill-buffer buffer)) |
485 (if (and (buffer-modified-p) | 574 (if (server-temp-file-p buffer) |
486 (y-or-n-p (concat "Save file " buffer-file-name "? "))) | 575 ;; For a temp file, save, and do NOT make a non-numeric backup |
487 (save-buffer buffer))) | 576 ;; Why does server.el explicitly back up temporary files? |
577 (let ((version-control nil) | |
578 (buffer-backed-up (not server-make-temp-file-backup))) | |
579 (save-buffer)) | |
580 (if (and (buffer-modified-p) | |
581 (y-or-n-p (concat "Save file " buffer-file-name "? "))) | |
582 (save-buffer buffer)))) | |
488 (server-buffer-done buffer))))) | 583 (server-buffer-done buffer))))) |
489 | 584 |
490 | 585 |
491 (defun server-edit (&optional arg) | 586 (defun server-edit (&optional arg) |
492 "Switch to next server editing buffer and mark current one as \"done\". | 587 "Switch to next server editing |
493 If a server buffer is current, it is marked \"done\" and optionally saved. | 588 buffer and mark current one as \"done\". If a server buffer is |
494 MH <draft> files are always saved and backed up, no questions asked. | 589 current, it is marked \"done\" and optionally saved. MH <draft> files |
495 When all of a client's buffers are marked as \"done\", the client is notified. | 590 are always saved and backed up, no questions asked. Files that match |
591 server-temp-file-regexp are considered temporary and are saved | |
592 unconditionally and | |
593 backed up if server-make-temp-file-backup is non-nil. When all of a | |
594 client's buffers are marked as \"done\", the client is notified. | |
496 | 595 |
497 If invoked with a prefix argument, or if there is no server process running, | 596 If invoked with a prefix argument, or if there is no server process running, |
498 starts server process and that is all. Invoked by \\[server-edit]. | 597 starts server process and that is all. Invoked by \\[server-edit]. |
499 | 598 |
500 If `server-kill-last-frame' is t, then the final frame will be killed." | 599 If `server-kill-last-frame' is t, then the final frame will be killed." |
502 (if (or arg | 601 (if (or arg |
503 (not server-process) | 602 (not server-process) |
504 (memq (process-status server-process) '(signal exit))) | 603 (memq (process-status server-process) '(signal exit))) |
505 (server-start nil) | 604 (server-start nil) |
506 (if server-buffer-clients | 605 (if server-buffer-clients |
507 (progn (server-switch-buffer (server-done)) | 606 (progn (server-done-and-switch) |
508 (cond ((fboundp 'console-type) ;; XEmacs 19.14+ | 607 (cond ((fboundp 'console-type) ;; XEmacs 19.14+ |
509 (or (and (equal (console-type) 'x) | 608 (or (and (equal (console-type) 'x) |
510 gnuserv-frame | 609 gnuserv-frame |
511 (frame-live-p gnuserv-frame)) | 610 (frame-live-p gnuserv-frame)) |
512 (condition-case () | 611 (condition-case () |
529 (delete-screen)))) | 628 (delete-screen)))) |
530 (error | 629 (error |
531 "(server-edit): Use only on buffers created by external programs.") | 630 "(server-edit): Use only on buffers created by external programs.") |
532 ))) | 631 ))) |
533 | 632 |
534 (defun server-switch-buffer (next-buffer) | 633 (defun server-switch-buffer-internal (next-buffer always) |
535 "Switch to NEXT-BUFFER if a live buffer, otherwise switch to another buffer | 634 "Switch to NEXT-BUFFER if a live buffer, otherwise switch to another buffer |
536 with gnuserv clients. If no such buffer is available, simply choose another | 635 with gnuserv clients. If no such buffer is available, we switch to |
537 one." | 636 another normal buffer if `always' is non-nil!" |
637 ;; switching | |
538 (if next-buffer | 638 (if next-buffer |
539 (if (and (bufferp next-buffer) | 639 (if (and (bufferp next-buffer) |
540 (buffer-name next-buffer)) | 640 (buffer-name next-buffer)) |
541 (switch-to-buffer next-buffer) | 641 (switch-to-buffer next-buffer) |
542 ;; If NEXT-BUFFER is a dead buffer, | 642 ;; If NEXT-BUFFER is a dead buffer, |
543 ;; remove the server records for it | 643 ;; remove the server records for it |
544 ;; and try the next surviving server buffer. | 644 ;; and try the next surviving server buffer. |
545 (server-switch-buffer | 645 (server-switch-buffer-internal |
546 (server-buffer-done next-buffer))) | 646 (server-buffer-done next-buffer) always)) |
547 (if server-clients | 647 (if server-clients |
548 (server-switch-buffer (nth 1 (car server-clients))) | 648 (server-switch-buffer-internal (nth 1 (car server-clients)) always) |
549 (switch-to-buffer (other-buffer))))) | 649 (if always |
650 (switch-to-buffer (other-buffer)))))) | |
651 | |
652 ;; For compatability | |
653 (defun server-switch-buffer (next-buffer) | |
654 (server-switch-buffer-internal next-buffer t)) | |
655 | |
656 ;; The below function calles server-done and switches to the next | |
657 ;; sensible buffer. This implementation works regardless of the values | |
658 ;; of server-*-function and doens't need the tail recursion | |
659 ;; variable passing of server.el. It is more transparant too. JV | |
660 (defun server-done-and-switch () | |
661 "Be done with the current buffer and switch to another server buffer | |
662 if there is one, otherwise just switch buffer" | |
663 (let ((old-current (current-buffer))) | |
664 (server-switch-buffer-internal (server-done) nil) | |
665 (if (eq old-current (current-buffer)) | |
666 (switch-to-buffer (other-buffer))))) | |
550 | 667 |
551 (global-set-key "\C-x#" 'server-edit) | 668 (global-set-key "\C-x#" 'server-edit) |
552 | 669 |
553 (provide 'gnuserv) | 670 (provide 'gnuserv) |
554 | 671 |