diff options
| author | Miles Bader | 2008-01-30 07:57:28 +0000 |
|---|---|---|
| committer | Miles Bader | 2008-01-30 07:57:28 +0000 |
| commit | d235ca2ff8fab139ce797757fcb159d1e28fa7e0 (patch) | |
| tree | 96c5cd1a06a0d9dc26e8470c6eabfc032c0046f3 /lisp/server.el | |
| parent | 3709a060f679dba14df71ae64a0035fa2b5b3106 (diff) | |
| parent | 02cbe062bee38a6705bafb1699d77e3c44cfafcf (diff) | |
| download | emacs-d235ca2ff8fab139ce797757fcb159d1e28fa7e0.tar.gz emacs-d235ca2ff8fab139ce797757fcb159d1e28fa7e0.zip | |
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-324
Diffstat (limited to 'lisp/server.el')
| -rw-r--r-- | lisp/server.el | 131 |
1 files changed, 74 insertions, 57 deletions
diff --git a/lisp/server.el b/lisp/server.el index 63245135347..024df504779 100644 --- a/lisp/server.el +++ b/lisp/server.el | |||
| @@ -291,17 +291,29 @@ If NOFRAME is non-nil, let the frames live. (To be used from | |||
| 291 | 291 | ||
| 292 | (server-log "Deleted" proc)))) | 292 | (server-log "Deleted" proc)))) |
| 293 | 293 | ||
| 294 | (defvar server-log-time-function 'current-time-string | ||
| 295 | "Function to generate timestamps for `server-buffer'.") | ||
| 296 | |||
| 297 | (defconst server-buffer " *server*" | ||
| 298 | "Buffer used internally by Emacs's server. | ||
| 299 | One use is to log the I/O for debugging purposes (see `server-log'), | ||
| 300 | the other is to provide a current buffer in which the process filter can | ||
| 301 | safely let-bind buffer-local variables like `default-directory'.") | ||
| 302 | |||
| 303 | (defvar server-log nil | ||
| 304 | "If non-nil, log the server's inputs and outputs in the `server-buffer'.") | ||
| 305 | |||
| 294 | (defun server-log (string &optional client) | 306 | (defun server-log (string &optional client) |
| 295 | "If a *server* buffer exists, write STRING to it for logging purposes. | 307 | "If `server-log' is non-nil, log STRING to `server-buffer'. |
| 296 | If CLIENT is non-nil, add a description of it to the logged message." | 308 | If CLIENT is non-nil, add a description of it to the logged message." |
| 297 | (when (get-buffer "*server*") | 309 | (when server-log |
| 298 | (with-current-buffer "*server*" | 310 | (with-current-buffer (get-buffer-create server-buffer) |
| 299 | (goto-char (point-max)) | 311 | (goto-char (point-max)) |
| 300 | (insert (current-time-string) | 312 | (insert (funcall server-log-time-function) |
| 301 | (cond | 313 | (cond |
| 302 | ((null client) " ") | 314 | ((null client) " ") |
| 303 | ((listp client) (format " %s: " (car client))) | 315 | ((listp client) (format " %s: " (car client))) |
| 304 | (t (format " %s: " client))) | 316 | (t (format " %s: " client))) |
| 305 | string) | 317 | string) |
| 306 | (or (bolp) (newline))))) | 318 | (or (bolp) (newline))))) |
| 307 | 319 | ||
| @@ -494,7 +506,7 @@ kill any existing server communications subprocess." | |||
| 494 | ;; Those are decoded by server-process-filter according | 506 | ;; Those are decoded by server-process-filter according |
| 495 | ;; to file-name-coding-system. | 507 | ;; to file-name-coding-system. |
| 496 | :coding 'raw-text | 508 | :coding 'raw-text |
| 497 | ;; The rest of the args depends on the kind of socket used. | 509 | ;; The other args depend on the kind of socket used. |
| 498 | (if server-use-tcp | 510 | (if server-use-tcp |
| 499 | (list :family nil | 511 | (list :family nil |
| 500 | :service t | 512 | :service t |
| @@ -764,7 +776,7 @@ The following commands are accepted by the client: | |||
| 764 | (server-log (concat "Received " string) proc) | 776 | (server-log (concat "Received " string) proc) |
| 765 | ;; First things first: let's check the authentication | 777 | ;; First things first: let's check the authentication |
| 766 | (unless (process-get proc :authenticated) | 778 | (unless (process-get proc :authenticated) |
| 767 | (if (and (string-match "-auth \\(.*?\\)\n" string) | 779 | (if (and (string-match "-auth \\([!-~]+\\)\n?" string) |
| 768 | (equal (match-string 1 string) (process-get proc :auth-key))) | 780 | (equal (match-string 1 string) (process-get proc :auth-key))) |
| 769 | (progn | 781 | (progn |
| 770 | (setq string (substring string (match-end 0))) | 782 | (setq string (substring string (match-end 0))) |
| @@ -805,8 +817,7 @@ The following commands are accepted by the client: | |||
| 805 | (tty-name nil) ;nil, `window-system', or the tty name. | 817 | (tty-name nil) ;nil, `window-system', or the tty name. |
| 806 | tty-type ;string. | 818 | tty-type ;string. |
| 807 | (files nil) | 819 | (files nil) |
| 808 | (lineno 1) | 820 | (filepos nil) |
| 809 | (columnno 0) | ||
| 810 | command-line-args-left | 821 | command-line-args-left |
| 811 | arg) | 822 | arg) |
| 812 | ;; Remove this line from STRING. | 823 | ;; Remove this line from STRING. |
| @@ -876,9 +887,9 @@ The following commands are accepted by the client: | |||
| 876 | (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?" | 887 | (string-match "\\+\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?" |
| 877 | (car command-line-args-left))) | 888 | (car command-line-args-left))) |
| 878 | (setq arg (pop command-line-args-left)) | 889 | (setq arg (pop command-line-args-left)) |
| 879 | (setq lineno (string-to-number (match-string 1 arg)) | 890 | (setq filepos |
| 880 | columnno (if (null (match-end 2)) 0 | 891 | (cons (string-to-number (match-string 1 arg)) |
| 881 | (string-to-number (match-string 2 arg))))) | 892 | (string-to-number (or (match-string 2 arg) ""))))) |
| 882 | 893 | ||
| 883 | ;; -file FILENAME: Load the given file. | 894 | ;; -file FILENAME: Load the given file. |
| 884 | ((and (equal "-file" arg) | 895 | ((and (equal "-file" arg) |
| @@ -887,11 +898,10 @@ The following commands are accepted by the client: | |||
| 887 | (if coding-system | 898 | (if coding-system |
| 888 | (setq file (decode-coding-string file coding-system))) | 899 | (setq file (decode-coding-string file coding-system))) |
| 889 | (setq file (command-line-normalize-file-name file)) | 900 | (setq file (command-line-normalize-file-name file)) |
| 890 | (push (list file lineno columnno) files) | 901 | (push (cons file filepos) files) |
| 891 | (server-log (format "New file: %s (%d:%d)" | 902 | (server-log (format "New file: %s %s" |
| 892 | file lineno columnno) proc)) | 903 | file (or filepos "")) proc)) |
| 893 | (setq lineno 1 | 904 | (setq filepos nil)) |
| 894 | columnno 0)) | ||
| 895 | 905 | ||
| 896 | ;; -eval EXPR: Evaluate a Lisp expression. | 906 | ;; -eval EXPR: Evaluate a Lisp expression. |
| 897 | ((and (equal "-eval" arg) | 907 | ((and (equal "-eval" arg) |
| @@ -901,8 +911,7 @@ The following commands are accepted by the client: | |||
| 901 | (setq expr (decode-coding-string expr coding-system))) | 911 | (setq expr (decode-coding-string expr coding-system))) |
| 902 | (push (lambda () (server-eval-and-print expr proc)) | 912 | (push (lambda () (server-eval-and-print expr proc)) |
| 903 | commands) | 913 | commands) |
| 904 | (setq lineno 1 | 914 | (setq filepos nil))) |
| 905 | columnno 0))) | ||
| 906 | 915 | ||
| 907 | ;; -env NAME=VALUE: An environment variable. | 916 | ;; -env NAME=VALUE: An environment variable. |
| 908 | ((and (equal "-env" arg) command-line-args-left) | 917 | ((and (equal "-env" arg) command-line-args-left) |
| @@ -928,17 +937,25 @@ The following commands are accepted by the client: | |||
| 928 | (server-create-window-system-frame display nowait proc)) | 937 | (server-create-window-system-frame display nowait proc)) |
| 929 | (t (server-create-tty-frame tty-name tty-type proc)))) | 938 | (t (server-create-tty-frame tty-name tty-type proc)))) |
| 930 | 939 | ||
| 931 | (process-put proc 'continuation | 940 | (process-put |
| 932 | (lexical-let ((proc proc) | 941 | proc 'continuation |
| 933 | (files files) | 942 | (lexical-let ((proc proc) |
| 934 | (nowait nowait) | 943 | (files files) |
| 935 | (commands commands) | 944 | (nowait nowait) |
| 936 | (dontkill dontkill) | 945 | (commands commands) |
| 937 | (frame frame) | 946 | (dontkill dontkill) |
| 938 | (tty-name tty-name)) | 947 | (frame frame) |
| 939 | (lambda () | 948 | (dir dir) |
| 940 | (server-execute proc files nowait commands | 949 | (tty-name tty-name)) |
| 941 | dontkill frame tty-name)))) | 950 | (lambda () |
| 951 | (with-current-buffer (get-buffer-create server-buffer) | ||
| 952 | ;; Use the same cwd as the emacsclient, if possible, so | ||
| 953 | ;; relative file names work correctly, even in `eval'. | ||
| 954 | (let ((default-directory | ||
| 955 | (if (and dir (file-directory-p dir)) | ||
| 956 | dir default-directory))) | ||
| 957 | (server-execute proc files nowait commands | ||
| 958 | dontkill frame tty-name)))))) | ||
| 942 | 959 | ||
| 943 | (when (or frame files) | 960 | (when (or frame files) |
| 944 | (server-goto-toplevel proc)) | 961 | (server-goto-toplevel proc)) |
| @@ -991,18 +1008,19 @@ The following commands are accepted by the client: | |||
| 991 | (server-log (error-message-string err) proc) | 1008 | (server-log (error-message-string err) proc) |
| 992 | (delete-process proc))) | 1009 | (delete-process proc))) |
| 993 | 1010 | ||
| 994 | (defun server-goto-line-column (file-line-col) | 1011 | (defun server-goto-line-column (line-col) |
| 995 | "Move point to the position indicated in FILE-LINE-COL. | 1012 | "Move point to the position indicated in LINE-COL. |
| 996 | FILE-LINE-COL should be a three-element list as described in | 1013 | LINE-COL should be a pair (LINE . COL)." |
| 997 | `server-visit-files'." | 1014 | (when line-col |
| 998 | (goto-line (nth 1 file-line-col)) | 1015 | (goto-line (car line-col)) |
| 999 | (let ((column-number (nth 2 file-line-col))) | 1016 | (let ((column-number (cdr line-col))) |
| 1000 | (when (> column-number 0) | 1017 | (when (> column-number 0) |
| 1001 | (move-to-column (1- column-number))))) | 1018 | (move-to-column (1- column-number)))))) |
| 1002 | 1019 | ||
| 1003 | (defun server-visit-files (files proc &optional nowait) | 1020 | (defun server-visit-files (files proc &optional nowait) |
| 1004 | "Find FILES and return a list of buffers created. | 1021 | "Find FILES and return a list of buffers created. |
| 1005 | FILES is an alist whose elements are (FILENAME LINENUMBER COLUMNNUMBER). | 1022 | FILES is an alist whose elements are (FILENAME . FILEPOS) |
| 1023 | where FILEPOS can be nil or a pair (LINENUMBER . COLUMNNUMBER). | ||
| 1006 | PROC is the client that requested this operation. | 1024 | PROC is the client that requested this operation. |
| 1007 | NOWAIT non-nil means this client is not waiting for the results, | 1025 | NOWAIT non-nil means this client is not waiting for the results, |
| 1008 | so don't mark these buffers specially, just visit them normally." | 1026 | so don't mark these buffers specially, just visit them normally." |
| @@ -1021,22 +1039,21 @@ so don't mark these buffers specially, just visit them normally." | |||
| 1021 | (filen (car file)) | 1039 | (filen (car file)) |
| 1022 | (obuf (get-file-buffer filen))) | 1040 | (obuf (get-file-buffer filen))) |
| 1023 | (add-to-history 'file-name-history filen) | 1041 | (add-to-history 'file-name-history filen) |
| 1024 | (if (and obuf (set-buffer obuf)) | 1042 | (if (null obuf) |
| 1025 | (progn | 1043 | (set-buffer (find-file-noselect filen)) |
| 1026 | (cond ((file-exists-p filen) | 1044 | (set-buffer obuf) |
| 1027 | (when (not (verify-visited-file-modtime obuf)) | 1045 | (cond ((file-exists-p filen) |
| 1028 | (revert-buffer t nil))) | 1046 | (when (not (verify-visited-file-modtime obuf)) |
| 1029 | (t | 1047 | (revert-buffer t nil))) |
| 1030 | (when (y-or-n-p | 1048 | (t |
| 1031 | (concat "File no longer exists: " filen | 1049 | (when (y-or-n-p |
| 1032 | ", write buffer to file? ")) | 1050 | (concat "File no longer exists: " filen |
| 1033 | (write-file filen)))) | 1051 | ", write buffer to file? ")) |
| 1034 | (unless server-buffer-clients | 1052 | (write-file filen)))) |
| 1035 | (setq server-existing-buffer t)) | 1053 | (unless server-buffer-clients |
| 1036 | (server-goto-line-column file)) | 1054 | (setq server-existing-buffer t))) |
| 1037 | (set-buffer (find-file-noselect filen)) | 1055 | (server-goto-line-column (cdr file)) |
| 1038 | (server-goto-line-column file) | 1056 | (run-hooks 'server-visit-hook)) |
| 1039 | (run-hooks 'server-visit-hook))) | ||
| 1040 | (unless nowait | 1057 | (unless nowait |
| 1041 | ;; When the buffer is killed, inform the clients. | 1058 | ;; When the buffer is killed, inform the clients. |
| 1042 | (add-hook 'kill-buffer-hook 'server-kill-buffer nil t) | 1059 | (add-hook 'kill-buffer-hook 'server-kill-buffer nil t) |