Mercurial > emacs
comparison lisp/server.el @ 91085:880960b70474
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-283
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 11 Nov 2007 00:56:44 +0000 |
parents | 1251cabc40b7 e83e0513df1b |
children | 53108e6cea98 |
comparison
equal
deleted
inserted
replaced
91084:a4347a111894 | 91085:880960b70474 |
---|---|
237 (concat ,var "=" ,value)) | 237 (concat ,var "=" ,value)) |
238 process-environment))) | 238 process-environment))) |
239 (progn ,@body)))) | 239 (progn ,@body)))) |
240 | 240 |
241 (defun server-delete-client (proc &optional noframe) | 241 (defun server-delete-client (proc &optional noframe) |
242 "Delete CLIENT, including its buffers, terminals and frames. | 242 "Delete PROC, including its buffers, terminals and frames. |
243 If NOFRAME is non-nil, let the frames live. (To be used from | 243 If NOFRAME is non-nil, let the frames live. (To be used from |
244 `delete-frame-functions'.)" | 244 `delete-frame-functions'.)" |
245 (server-log (concat "server-delete-client" (if noframe " noframe")) | 245 (server-log (concat "server-delete-client" (if noframe " noframe")) |
246 proc) | 246 proc) |
247 ;; Force a new lookup of client (prevents infinite recursion). | 247 ;; Force a new lookup of client (prevents infinite recursion). |
292 | 292 |
293 (server-log "Deleted" proc)))) | 293 (server-log "Deleted" proc)))) |
294 | 294 |
295 (defun server-log (string &optional client) | 295 (defun server-log (string &optional client) |
296 "If a *server* buffer exists, write STRING to it for logging purposes. | 296 "If a *server* buffer exists, write STRING to it for logging purposes. |
297 If CLIENT is non-nil, add a description of it to the logged | 297 If CLIENT is non-nil, add a description of it to the logged message." |
298 message." | |
299 (when (get-buffer "*server*") | 298 (when (get-buffer "*server*") |
300 (with-current-buffer "*server*" | 299 (with-current-buffer "*server*" |
301 (goto-char (point-max)) | 300 (goto-char (point-max)) |
302 (insert (current-time-string) | 301 (insert (current-time-string) |
303 (cond | 302 (cond |
482 (letf (((default-file-modes) ?\700)) | 481 (letf (((default-file-modes) ?\700)) |
483 (add-hook 'suspend-tty-functions 'server-handle-suspend-tty) | 482 (add-hook 'suspend-tty-functions 'server-handle-suspend-tty) |
484 (add-hook 'delete-frame-functions 'server-handle-delete-frame) | 483 (add-hook 'delete-frame-functions 'server-handle-delete-frame) |
485 (add-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) | 484 (add-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) |
486 (add-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) | 485 (add-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) |
486 (add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit. | |
487 (setq server-process | 487 (setq server-process |
488 (apply #'make-network-process | 488 (apply #'make-network-process |
489 :name server-name | 489 :name server-name |
490 :server t | 490 :server t |
491 :noquery t | 491 :noquery t |
570 '("LANG" "LC_CTYPE" "LC_ALL" | 570 '("LANG" "LC_CTYPE" "LC_ALL" |
571 ;; For tgetent(3); list according to ncurses(3). | 571 ;; For tgetent(3); list according to ncurses(3). |
572 "BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES" | 572 "BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES" |
573 "NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING" | 573 "NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING" |
574 "NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO" | 574 "NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO" |
575 "TERMINFO_DIRS" "TERMPATH" | 575 "TERMINFO_DIRS" "TERMPATH" |
576 ;; rxvt wants these | 576 ;; rxvt wants these |
577 "COLORFGBG" "COLORTERM") | 577 "COLORFGBG" "COLORTERM") |
578 (make-frame-on-tty tty type | 578 (make-frame-on-tty tty type |
579 ;; Ignore nowait here; we always need to | 579 ;; Ignore nowait here; we always need to |
580 ;; clean up opened ttys when the client dies. | 580 ;; clean up opened ttys when the client dies. |
588 ;; process-environment interact with client | 588 ;; process-environment interact with client |
589 ;; envvars, and then to change the | 589 ;; envvars, and then to change the |
590 ;; C functions `child_setup' and | 590 ;; C functions `child_setup' and |
591 ;; `getenv_internal' accordingly. | 591 ;; `getenv_internal' accordingly. |
592 (environment . ,(process-get proc 'env))))))) | 592 (environment . ,(process-get proc 'env))))))) |
593 | 593 |
594 ;; ttys don't use the `display' parameter, but callproc.c does to set | 594 ;; ttys don't use the `display' parameter, but callproc.c does to set |
595 ;; the DISPLAY environment on subprocesses. | 595 ;; the DISPLAY environment on subprocesses. |
596 (set-frame-parameter frame 'display | 596 (set-frame-parameter frame 'display |
597 (getenv-internal "DISPLAY" (process-get proc 'env))) | 597 (getenv-internal "DISPLAY" (process-get proc 'env))) |
598 (select-frame frame) | 598 (select-frame frame) |
735 Suspend this tty frame. The client sends this string in | 735 Suspend this tty frame. The client sends this string in |
736 response to SIGTSTP and SIGTTOU. The server must cease all I/O | 736 response to SIGTSTP and SIGTTOU. The server must cease all I/O |
737 on this tty until it gets a -resume command. | 737 on this tty until it gets a -resume command. |
738 | 738 |
739 `-resume' | 739 `-resume' |
740 Resume this tty frame. The client sends this string when it | 740 Resume this tty frame. The client sends this string when it |
741 gets the SIGCONT signal and it is the foreground process on its | 741 gets the SIGCONT signal and it is the foreground process on its |
742 controlling tty. | 742 controlling tty. |
743 | 743 |
744 `-ignore COMMENT' | 744 `-ignore COMMENT' |
745 Do nothing, but put the comment in the server | 745 Do nothing, but put the comment in the server |
751 `-emacs-pid PID' | 751 `-emacs-pid PID' |
752 Describes the process id of the Emacs process; | 752 Describes the process id of the Emacs process; |
753 used to forward window change signals to it. | 753 used to forward window change signals to it. |
754 | 754 |
755 `-window-system-unsupported' | 755 `-window-system-unsupported' |
756 Signals that the server does not | 756 Signals that the server does not support creating X frames; |
757 support creating X frames; the client must try again with a tty | 757 the client must try again with a tty frame. |
758 frame. | |
759 | 758 |
760 `-print STRING' | 759 `-print STRING' |
761 Print STRING on stdout. Used to send values | 760 Print STRING on stdout. Used to send values |
762 returned by -eval. | 761 returned by -eval. |
763 | 762 |
764 `-error DESCRIPTION' | 763 `-error DESCRIPTION' |
765 Signal an error (but continue processing). | 764 Signal an error (but continue processing). |
766 | 765 |
767 `-suspend' | 766 `-suspend' |
768 Suspend this terminal, i.e., stop the client process. Sent | 767 Suspend this terminal, i.e., stop the client process. |
769 when the user presses C-z." | 768 Sent when the user presses C-z." |
770 (server-log (concat "Received " string) proc) | 769 (server-log (concat "Received " string) proc) |
771 ;; First things first: let's check the authentication | 770 ;; First things first: let's check the authentication |
772 (unless (process-get proc :authenticated) | 771 (unless (process-get proc :authenticated) |
773 (if (and (string-match "-auth \\(.*?\\)\n" string) | 772 (if (and (string-match "-auth \\(.*?\\)\n" string) |
774 (equal (match-string 1 string) (process-get proc :auth-key))) | 773 (equal (match-string 1 string) (process-get proc :auth-key))) |
791 (server-add-client proc) | 790 (server-add-client proc) |
792 (if (not (string-match "\n" string)) | 791 (if (not (string-match "\n" string)) |
793 ;; Save for later any partial line that remains. | 792 ;; Save for later any partial line that remains. |
794 (when (> (length string) 0) | 793 (when (> (length string) 0) |
795 (process-put proc 'previous-string string)) | 794 (process-put proc 'previous-string string)) |
796 | 795 |
797 ;; In earlier versions of server.el (where we used an `emacsserver' | 796 ;; In earlier versions of server.el (where we used an `emacsserver' |
798 ;; process), there could be multiple lines. Nowadays this is not | 797 ;; process), there could be multiple lines. Nowadays this is not |
799 ;; supported any more. | 798 ;; supported any more. |
800 (assert (eq (match-end 0) (length string))) | 799 (assert (eq (match-end 0) (length string))) |
801 (let ((request (substring string 0 (match-beginning 0))) | 800 (let ((request (substring string 0 (match-beginning 0))) |
929 (setq dir (decode-coding-string dir coding-system))) | 928 (setq dir (decode-coding-string dir coding-system))) |
930 (setq dir (command-line-normalize-file-name dir))) | 929 (setq dir (command-line-normalize-file-name dir))) |
931 | 930 |
932 ;; Unknown command. | 931 ;; Unknown command. |
933 (t (error "Unknown command: %s" arg))))) | 932 (t (error "Unknown command: %s" arg))))) |
934 | 933 |
935 (setq frame | 934 (setq frame |
936 (case tty-name | 935 (case tty-name |
937 ((nil) (if display (server-select-display display))) | 936 ((nil) (if display (server-select-display display))) |
938 ((window-system) | 937 ((window-system) |
939 (server-create-window-system-frame display nowait proc)) | 938 (server-create-window-system-frame display nowait proc)) |
965 (run-hooks 'pre-command-hook) | 964 (run-hooks 'pre-command-hook) |
966 (prog1 (server-visit-files files proc nowait) | 965 (prog1 (server-visit-files files proc nowait) |
967 (run-hooks 'post-command-hook))))) | 966 (run-hooks 'post-command-hook))))) |
968 | 967 |
969 (mapc 'funcall (nreverse commands)) | 968 (mapc 'funcall (nreverse commands)) |
970 | 969 |
971 ;; Delete the client if necessary. | 970 ;; Delete the client if necessary. |
972 (cond | 971 (cond |
973 (nowait | 972 (nowait |
974 ;; Client requested nowait; return immediately. | 973 ;; Client requested nowait; return immediately. |
975 (server-log "Close nowait client" proc) | 974 (server-log "Close nowait client" proc) |
1006 "Move point to the position indicated in FILE-LINE-COL. | 1005 "Move point to the position indicated in FILE-LINE-COL. |
1007 FILE-LINE-COL should be a three-element list as described in | 1006 FILE-LINE-COL should be a three-element list as described in |
1008 `server-visit-files'." | 1007 `server-visit-files'." |
1009 (goto-line (nth 1 file-line-col)) | 1008 (goto-line (nth 1 file-line-col)) |
1010 (let ((column-number (nth 2 file-line-col))) | 1009 (let ((column-number (nth 2 file-line-col))) |
1011 (if (> column-number 0) | 1010 (when (> column-number 0) |
1012 (move-to-column (1- column-number))))) | 1011 (move-to-column (1- column-number))))) |
1013 | 1012 |
1014 (defun server-visit-files (files proc &optional nowait) | 1013 (defun server-visit-files (files proc &optional nowait) |
1015 "Find FILES and return a list of buffers created. | 1014 "Find FILES and return a list of buffers created. |
1016 FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER). | 1015 FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER). |
1017 PROC is the client that requested this operation. | 1016 PROC is the client that requested this operation. |
1157 (setq res nil)))) | 1156 (setq res nil)))) |
1158 (yes-or-no-p (format "Buffer `%s' still has clients; kill it? " | 1157 (yes-or-no-p (format "Buffer `%s' still has clients; kill it? " |
1159 (buffer-name (current-buffer)))))) | 1158 (buffer-name (current-buffer)))))) |
1160 | 1159 |
1161 (defun server-kill-emacs-query-function () | 1160 (defun server-kill-emacs-query-function () |
1162 "Ask before exiting Emacs it has live clients." | 1161 "Ask before exiting Emacs if it has live clients." |
1163 (or (not server-clients) | 1162 (or (not server-clients) |
1164 (let (live-client) | 1163 (let (live-client) |
1165 (dolist (proc server-clients live-client) | 1164 (dolist (proc server-clients live-client) |
1166 (when (memq t (mapcar 'buffer-live-p (process-get | 1165 (when (memq t (mapcar 'buffer-live-p (process-get |
1167 proc 'buffers))) | 1166 proc 'buffers))) |
1283 t)) | 1282 t)) |
1284 (server-delete-client proc))) | 1283 (server-delete-client proc))) |
1285 | 1284 |
1286 (define-key ctl-x-map "#" 'server-edit) | 1285 (define-key ctl-x-map "#" 'server-edit) |
1287 | 1286 |
1288 (defun server-unload-hook () | 1287 (defun server-unload-function () |
1289 "Unload the server library." | 1288 "Unload the server library." |
1290 (server-mode -1) | 1289 (server-mode -1) |
1291 (remove-hook 'suspend-tty-functions 'server-handle-suspend-tty) | 1290 (substitute-key-definition 'server-edit nil ctl-x-map) |
1292 (remove-hook 'delete-frame-functions 'server-handle-delete-frame) | 1291 (save-current-buffer |
1293 (remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function) | 1292 (dolist (buffer (buffer-list)) |
1294 (remove-hook 'kill-emacs-query-functions 'server-kill-emacs-query-function) | 1293 (set-buffer buffer) |
1295 (remove-hook 'kill-buffer-hook 'server-kill-buffer)) | 1294 (remove-hook 'kill-buffer-hook 'server-kill-buffer t))) |
1296 | 1295 ;; continue standard unloading |
1297 (add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit. | 1296 nil) |
1298 (add-hook 'server-unload-hook 'server-unload-hook) | 1297 |
1299 | 1298 |
1300 (provide 'server) | 1299 (provide 'server) |
1301 | 1300 |
1302 ;; arch-tag: 1f7ecb42-f00a-49f8-906d-61995d84c8d6 | 1301 ;; arch-tag: 1f7ecb42-f00a-49f8-906d-61995d84c8d6 |
1303 ;;; server.el ends here | 1302 ;;; server.el ends here |