Mercurial > emacs
comparison lisp/server.el @ 83215:a9f716fbb9c6
Small tweaks in server.el.
* lisp/server.el: Doc updates.
(server-select-display): Remove (unused).
(server-handle-suspend-tty): Kill the client in case of errors from
process-send-string.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-255
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Sun, 10 Oct 2004 16:41:15 +0000 |
parents | 1199c806ed07 |
children | 8131adf4ac7b |
comparison
equal
deleted
inserted
replaced
83214:2bd6d4c2d21c | 83215:a9f716fbb9c6 |
---|---|
40 ;; When some other program runs "the editor" to edit a file, | 40 ;; When some other program runs "the editor" to edit a file, |
41 ;; "the editor" can be the Emacs client program ../lib-src/emacsclient. | 41 ;; "the editor" can be the Emacs client program ../lib-src/emacsclient. |
42 ;; This program transmits the file names to Emacs through | 42 ;; This program transmits the file names to Emacs through |
43 ;; the server subprocess, and Emacs visits them and lets you edit them. | 43 ;; the server subprocess, and Emacs visits them and lets you edit them. |
44 | 44 |
45 ;; Note that any number of clients may dispatch files to emacs to be edited. | 45 ;; Note that any number of clients may dispatch files to Emacs to be edited. |
46 | 46 |
47 ;; When you finish editing a Server buffer, again call server-edit | 47 ;; When you finish editing a Server buffer, again call server-edit |
48 ;; to mark that buffer as done for the client and switch to the next | 48 ;; to mark that buffer as done for the client and switch to the next |
49 ;; Server buffer. When all the buffers for a client have been edited | 49 ;; Server buffer. When all the buffers for a client have been edited |
50 ;; and exited with server-edit, the client "editor" will return | 50 ;; and exited with server-edit, the client "editor" will return |
250 (delete-process (car client))) | 250 (delete-process (car client))) |
251 | 251 |
252 (server-log "Deleted" proc)))) | 252 (server-log "Deleted" proc)))) |
253 | 253 |
254 (defun server-log (string &optional client) | 254 (defun server-log (string &optional client) |
255 "If a *server* buffer exists, write STRING to it for logging purposes." | 255 "If a *server* buffer exists, write STRING to it for logging purposes. |
256 If CLIENT is non-nil, add a description of it to the logged | |
257 message." | |
256 (if (get-buffer "*server*") | 258 (if (get-buffer "*server*") |
257 (with-current-buffer "*server*" | 259 (with-current-buffer "*server*" |
258 (goto-char (point-max)) | 260 (goto-char (point-max)) |
259 (insert (current-time-string) | 261 (insert (current-time-string) |
260 (cond | 262 (cond |
288 | 290 |
289 (defun server-handle-suspend-tty (display) | 291 (defun server-handle-suspend-tty (display) |
290 "Notify the emacsclient process to suspend itself when its tty device is suspended." | 292 "Notify the emacsclient process to suspend itself when its tty device is suspended." |
291 (dolist (proc (server-clients-with 'display display)) | 293 (dolist (proc (server-clients-with 'display display)) |
292 (server-log (format "server-handle-suspend-tty, display %s" display) proc) | 294 (server-log (format "server-handle-suspend-tty, display %s" display) proc) |
293 (process-send-string proc "-suspend \n"))) | 295 (condition-case err |
294 | 296 (process-send-string proc "-suspend \n") |
295 (defun server-select-display (display) | 297 (file-error (condition-case nil (server-delete-client proc) (error nil)))))) |
296 ;; If the current frame is on `display' we're all set. | |
297 (unless (equal (frame-parameter (selected-frame) 'display) display) | |
298 ;; Otherwise, look for an existing frame there and select it. | |
299 (dolist (frame (frame-list)) | |
300 (when (equal (frame-parameter frame 'display) display) | |
301 (select-frame frame))) | |
302 ;; If there's no frame on that display yet, create a dummy one | |
303 ;; and select it. | |
304 (unless (equal (frame-parameter (selected-frame) 'display) display) | |
305 (select-frame | |
306 (make-frame-on-display display))))) | |
307 ;; This frame is only there in place of an actual "current display" | |
308 ;; setting, so we want it to be as unobtrusive as possible. That's | |
309 ;; what the invisibility is for. The minibuffer setting is so that | |
310 ;; we don't end up displaying a buffer in it (which noone would | |
311 ;; notice). | |
312 ;; XXX I have found this behaviour to be surprising and annoying. -- Lorentey | |
313 ;; '((visibility . nil) (minibuffer . only))))))) | |
314 | 298 |
315 (defun server-unquote-arg (arg) | 299 (defun server-unquote-arg (arg) |
316 "Remove &-quotation from ARG." | 300 "Remove &-quotation from ARG." |
317 (replace-regexp-in-string | 301 (replace-regexp-in-string |
318 "&." (lambda (s) | 302 "&." (lambda (s) |
354 | 338 |
355 ;;;###autoload | 339 ;;;###autoload |
356 (defun server-start (&optional leave-dead) | 340 (defun server-start (&optional leave-dead) |
357 "Allow this Emacs process to be a server for client processes. | 341 "Allow this Emacs process to be a server for client processes. |
358 This starts a server communications subprocess through which | 342 This starts a server communications subprocess through which |
359 client \"editors\" can send your editing commands to this Emacs job. | 343 client \"editors\" can send your editing commands to this Emacs |
360 To use the server, set up the program `emacsclient' in the | 344 job. To use the server, set up the program `emacsclient' in the |
361 Emacs distribution as your standard \"editor\". | 345 Emacs distribution as your standard \"editor\". |
362 | 346 |
363 Prefix arg means just kill any existing server communications subprocess." | 347 Prefix arg LEAVE-DEAD means just kill any existing server |
348 communications subprocess." | |
364 (interactive "P") | 349 (interactive "P") |
365 (when (or | 350 (when (or |
366 (not server-clients) | 351 (not server-clients) |
367 (yes-or-no-p | 352 (yes-or-no-p |
368 "The current server still has clients; delete them? ")) | 353 "The current server still has clients; delete them? ")) |
629 (setq string "") | 614 (setq string "") |
630 (server-log (error-message-string err) proc) | 615 (server-log (error-message-string err) proc) |
631 (delete-process proc))))) | 616 (delete-process proc))))) |
632 | 617 |
633 (defun server-goto-line-column (file-line-col) | 618 (defun server-goto-line-column (file-line-col) |
619 "Move point to the position indicated in FILE-LINE-COL. | |
620 FILE-LINE-COL should be a three-element list as described in | |
621 `server-visit-files'." | |
634 (goto-line (nth 1 file-line-col)) | 622 (goto-line (nth 1 file-line-col)) |
635 (let ((column-number (nth 2 file-line-col))) | 623 (let ((column-number (nth 2 file-line-col))) |
636 (if (> column-number 0) | 624 (if (> column-number 0) |
637 (move-to-column (1- column-number))))) | 625 (move-to-column (1- column-number))))) |
638 | 626 |
639 (defun server-visit-files (files client &optional nowait) | 627 (defun server-visit-files (files client &optional nowait) |
640 "Find FILES and return a list of buffers created. | 628 "Find FILES and return a list of buffers created. |
641 FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER). | 629 FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER). |
630 CLIENT is the client that requested this operation. | |
642 NOWAIT non-nil means this client is not waiting for the results, | 631 NOWAIT non-nil means this client is not waiting for the results, |
643 so don't mark these buffers specially, just visit them normally." | 632 so don't mark these buffers specially, just visit them normally." |
644 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries. | 633 ;; Bind last-nonmenu-event to force use of keyboard, not mouse, for queries. |
645 (let ((last-nonmenu-event t) client-record) | 634 (let ((last-nonmenu-event t) client-record) |
646 ;; Restore the current buffer afterward, but not using save-excursion, | 635 ;; Restore the current buffer afterward, but not using save-excursion, |
792 | 781 |
793 (defvar server-kill-buffer-running nil | 782 (defvar server-kill-buffer-running nil |
794 "Non-nil while `server-kill-buffer' or `server-buffer-done' is running.") | 783 "Non-nil while `server-kill-buffer' or `server-buffer-done' is running.") |
795 | 784 |
796 (defun server-kill-buffer () | 785 (defun server-kill-buffer () |
786 "Remove the current buffer from its clients' buffer list. | |
787 Designed to be added to `kill-buffer-hook'." | |
797 ;; Prevent infinite recursion if user has made server-done-hook | 788 ;; Prevent infinite recursion if user has made server-done-hook |
798 ;; call kill-buffer. | 789 ;; call kill-buffer. |
799 (or server-kill-buffer-running | 790 (or server-kill-buffer-running |
800 (and server-buffer-clients | 791 (and server-buffer-clients |
801 (let ((server-kill-buffer-running t)) | 792 (let ((server-kill-buffer-running t)) |
823 (server-start nil) | 814 (server-start nil) |
824 (apply 'server-switch-buffer (server-done)))) | 815 (apply 'server-switch-buffer (server-done)))) |
825 | 816 |
826 (defun server-switch-buffer (&optional next-buffer killed-one) | 817 (defun server-switch-buffer (&optional next-buffer killed-one) |
827 "Switch to another buffer, preferably one that has a client. | 818 "Switch to another buffer, preferably one that has a client. |
828 Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it." | 819 Arg NEXT-BUFFER is a suggestion; if it is a live buffer, use it. |
829 ;; KILLED-ONE is t in a recursive call | 820 |
830 ;; if we have already killed one temp-file server buffer. | 821 KILLED-ONE is t in a recursive call if we have already killed one |
831 ;; This means we should avoid the final "switch to some other buffer" | 822 temp-file server buffer. This means we should avoid the final |
832 ;; since we've already effectively done that. | 823 \"switch to some other buffer\" since we've already effectively |
824 done that." | |
833 (if (null next-buffer) | 825 (if (null next-buffer) |
834 (progn | 826 (progn |
835 (let ((rest server-clients)) | 827 (let ((rest server-clients)) |
836 (while (and rest (not next-buffer)) | 828 (while (and rest (not next-buffer)) |
837 (let ((client (car rest))) | 829 (let ((client (car rest))) |
917 (if (null env) | 909 (if (null env) |
918 (getenv variable) | 910 (getenv variable) |
919 (cdr (assoc variable env)))))) | 911 (cdr (assoc variable env)))))) |
920 | 912 |
921 (defun server-unload-hook () | 913 (defun server-unload-hook () |
914 "Unload the server library." | |
922 (server-start t) | 915 (server-start t) |
923 (remove-hook 'suspend-tty-functions 'server-handle-suspend-tty) | 916 (remove-hook 'suspend-tty-functions 'server-handle-suspend-tty) |
924 (remove-hook 'delete-frame-functions 'server-handle-delete-frame) | 917 (remove-hook 'delete-frame-functions 'server-handle-delete-frame) |
925 (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) | 918 (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) |
926 (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) | 919 (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) |