diff options
| author | Stefan Monnier | 2002-09-18 02:10:18 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2002-09-18 02:10:18 +0000 |
| commit | 8b3e840e9511d2bfe98282a35896fe6c7bebc174 (patch) | |
| tree | a8069f57f5057755e560f8a591e90a817ea34e20 | |
| parent | 3cf8c6aa0170bc33d95e6ae67f9155b04a7dd285 (diff) | |
| download | emacs-8b3e840e9511d2bfe98282a35896fe6c7bebc174.tar.gz emacs-8b3e840e9511d2bfe98282a35896fe6c7bebc174.zip | |
(server-log): Add `client' arg.
(server-start): Don't bother canceling the sentinel.
(server-process-filter): Use replace-regexp-in-string and
handle the new &n quoting. Use push. Use server-log's new arg.
Don't output the C-x # message if `nowait'.
(server-buffer-done): Use server-log's new arg.
| -rw-r--r-- | lisp/server.el | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/lisp/server.el b/lisp/server.el index 743a9c66734..bfebf2fcb92 100644 --- a/lisp/server.el +++ b/lisp/server.el | |||
| @@ -75,7 +75,9 @@ | |||
| 75 | ;; and which files are yet to be edited for each. | 75 | ;; and which files are yet to be edited for each. |
| 76 | 76 | ||
| 77 | ;;; Code: | 77 | ;;; Code: |
| 78 | 78 | ||
| 79 | (eval-when-compile (require 'cl)) | ||
| 80 | |||
| 79 | (defgroup server nil | 81 | (defgroup server nil |
| 80 | "Emacs running as a server process." | 82 | "Emacs running as a server process." |
| 81 | :group 'external) | 83 | :group 'external) |
| @@ -153,12 +155,13 @@ where it is set.") | |||
| 153 | 155 | ||
| 154 | ;; If a *server* buffer exists, | 156 | ;; If a *server* buffer exists, |
| 155 | ;; write STRING to it for logging purposes. | 157 | ;; write STRING to it for logging purposes. |
| 156 | (defun server-log (string) | 158 | (defun server-log (string &optional client) |
| 157 | (if (get-buffer "*server*") | 159 | (if (get-buffer "*server*") |
| 158 | (save-excursion | 160 | (with-current-buffer "*server*" |
| 159 | (set-buffer "*server*") | ||
| 160 | (goto-char (point-max)) | 161 | (goto-char (point-max)) |
| 161 | (insert (current-time-string) " " string) | 162 | (insert (current-time-string) |
| 163 | (if client (format " <%s>: " client) " ") | ||
| 164 | string) | ||
| 162 | (or (bolp) (newline))))) | 165 | (or (bolp) (newline))))) |
| 163 | 166 | ||
| 164 | (defun server-sentinel (proc msg) | 167 | (defun server-sentinel (proc msg) |
| @@ -178,10 +181,7 @@ Emacs distribution as your standard \"editor\". | |||
| 178 | Prefix arg means just kill any existing server communications subprocess." | 181 | Prefix arg means just kill any existing server communications subprocess." |
| 179 | (interactive "P") | 182 | (interactive "P") |
| 180 | ;; kill it dead! | 183 | ;; kill it dead! |
| 181 | (if server-process | 184 | (condition-case () (delete-process server-process) (error nil)) |
| 182 | (progn | ||
| 183 | (set-process-sentinel server-process nil) | ||
| 184 | (condition-case () (delete-process server-process) (error nil)))) | ||
| 185 | ;; Delete the socket files made by previous server invocations. | 185 | ;; Delete the socket files made by previous server invocations. |
| 186 | (let* ((sysname (system-name)) | 186 | (let* ((sysname (system-name)) |
| 187 | (dot-index (string-match "\\." sysname))) | 187 | (dot-index (string-match "\\." sysname))) |
| @@ -205,8 +205,7 @@ Prefix arg means just kill any existing server communications subprocess." | |||
| 205 | (while server-clients | 205 | (while server-clients |
| 206 | (let ((buffer (nth 1 (car server-clients)))) | 206 | (let ((buffer (nth 1 (car server-clients)))) |
| 207 | (server-buffer-done buffer))) | 207 | (server-buffer-done buffer))) |
| 208 | (if leave-dead | 208 | (unless leave-dead |
| 209 | nil | ||
| 210 | (if server-process | 209 | (if server-process |
| 211 | (server-log (message "Restarting server"))) | 210 | (server-log (message "Restarting server"))) |
| 212 | ;; Using a pty is wasteful, and the separate session causes | 211 | ;; Using a pty is wasteful, and the separate session causes |
| @@ -257,7 +256,7 @@ Prefix arg means just kill any existing server communications subprocess." | |||
| 257 | ;; ARG is a line number option. | 256 | ;; ARG is a line number option. |
| 258 | ((string-match "\\`\\+[0-9]+\\'" arg) | 257 | ((string-match "\\`\\+[0-9]+\\'" arg) |
| 259 | (setq lineno (string-to-int (substring arg 1)))) | 258 | (setq lineno (string-to-int (substring arg 1)))) |
| 260 | ;; ARG is line number:column option. | 259 | ;; ARG is line number:column option. |
| 261 | ((string-match "\\`+\\([0-9]+\\):\\([0-9]+\\)\\'" arg) | 260 | ((string-match "\\`+\\([0-9]+\\):\\([0-9]+\\)\\'" arg) |
| 262 | (setq lineno (string-to-int (match-string 1 arg)) | 261 | (setq lineno (string-to-int (match-string 1 arg)) |
| 263 | columnno (string-to-int (match-string 2 arg)))) | 262 | columnno (string-to-int (match-string 2 arg)))) |
| @@ -267,40 +266,39 @@ Prefix arg means just kill any existing server communications subprocess." | |||
| 267 | (setq arg (command-line-normalize-file-name arg)) | 266 | (setq arg (command-line-normalize-file-name arg)) |
| 268 | ;; Undo the quoting that emacsclient does | 267 | ;; Undo the quoting that emacsclient does |
| 269 | ;; for certain special characters. | 268 | ;; for certain special characters. |
| 270 | (while (string-match "&." arg pos) | 269 | (setq arg |
| 271 | (setq pos (1+ (match-beginning 0))) | 270 | (replace-regexp-in-string |
| 272 | (let ((nextchar (aref arg pos))) | 271 | "&." (lambda (s) |
| 273 | (cond ((= nextchar ?&) | 272 | (case (aref s 1) |
| 274 | (setq arg (replace-match "&" t t arg))) | 273 | (?& "&") |
| 275 | ((= nextchar ?-) | 274 | (?- "-") |
| 276 | (setq arg (replace-match "-" t t arg))) | 275 | (?n "\n") |
| 277 | (t | 276 | (t " "))) |
| 278 | (setq arg (replace-match " " t t arg)))))) | 277 | arg t t)) |
| 279 | ;; Now decode the file name if necessary. | 278 | ;; Now decode the file name if necessary. |
| 280 | (if coding-system | 279 | (if coding-system |
| 281 | (setq arg (decode-coding-string arg coding-system))) | 280 | (setq arg (decode-coding-string arg coding-system))) |
| 282 | (setq files | 281 | (push (list arg lineno columnno) files) |
| 283 | (cons (list arg lineno columnno) | ||
| 284 | files)) | ||
| 285 | (setq lineno 1) | 282 | (setq lineno 1) |
| 286 | (setq columnno 0))))) | 283 | (setq columnno 0))))) |
| 287 | (run-hooks 'pre-command-hook) | 284 | (when files |
| 288 | (server-visit-files files client nowait) | 285 | (run-hooks 'pre-command-hook) |
| 289 | (run-hooks 'post-command-hook) | 286 | (server-visit-files files client nowait) |
| 287 | (run-hooks 'post-command-hook)) | ||
| 290 | ;; CLIENT is now a list (CLIENTNUM BUFFERS...) | 288 | ;; CLIENT is now a list (CLIENTNUM BUFFERS...) |
| 291 | (if (null (cdr client)) | 289 | (if (null (cdr client)) |
| 292 | ;; This client is empty; get rid of it immediately. | 290 | ;; This client is empty; get rid of it immediately. |
| 293 | (progn | 291 | (progn |
| 294 | (send-string server-process | 292 | (send-string server-process |
| 295 | (format "Close: %s Done\n" (car client))) | 293 | (format "Close: %s Done\n" (car client))) |
| 296 | (server-log (format "Close empty client: %s Done\n" (car client)))) | 294 | (server-log "Close empty client" (car client))) |
| 297 | ;; We visited some buffer for this client. | 295 | ;; We visited some buffer for this client. |
| 298 | (or nowait | 296 | (or nowait (push client server-clients)) |
| 299 | (setq server-clients (cons client server-clients))) | ||
| 300 | (server-switch-buffer (nth 1 client)) | 297 | (server-switch-buffer (nth 1 client)) |
| 301 | (run-hooks 'server-switch-hook) | 298 | (run-hooks 'server-switch-hook) |
| 302 | (message (substitute-command-keys | 299 | (unless nowait |
| 303 | "When done with a buffer, type \\[server-edit]")))))))) | 300 | (message (substitute-command-keys |
| 301 | "When done with a buffer, type \\[server-edit]"))))))))) | ||
| 304 | ;; Save for later any partial line that remains. | 302 | ;; Save for later any partial line that remains. |
| 305 | (setq server-previous-string string)) | 303 | (setq server-previous-string string)) |
| 306 | 304 | ||
| @@ -356,8 +354,9 @@ so don't mark these buffers specially, just visit them normally." | |||
| 356 | "Mark BUFFER as \"done\" for its client(s). | 354 | "Mark BUFFER as \"done\" for its client(s). |
| 357 | This buries the buffer, then returns a list of the form (NEXT-BUFFER KILLED). | 355 | This buries the buffer, then returns a list of the form (NEXT-BUFFER KILLED). |
| 358 | NEXT-BUFFER is another server buffer, as a suggestion for what to select next, | 356 | NEXT-BUFFER is another server buffer, as a suggestion for what to select next, |
| 359 | or nil. KILLED is t if we killed BUFFER | 357 | or nil. KILLED is t if we killed BUFFER (typically, because it was visiting |
| 360 | \(typically, because it was visiting a temp file)." | 358 | a temp file). |
| 359 | FOR-KILLING if non-nil indicates that we are called from `kill-buffer'." | ||
| 361 | (let ((running (eq (process-status server-process) 'run)) | 360 | (let ((running (eq (process-status server-process) 'run)) |
| 362 | (next-buffer nil) | 361 | (next-buffer nil) |
| 363 | (killed nil) | 362 | (killed nil) |
| @@ -365,7 +364,7 @@ or nil. KILLED is t if we killed BUFFER | |||
| 365 | (old-clients server-clients)) | 364 | (old-clients server-clients)) |
| 366 | (while old-clients | 365 | (while old-clients |
| 367 | (let ((client (car old-clients))) | 366 | (let ((client (car old-clients))) |
| 368 | (or next-buffer | 367 | (or next-buffer |
| 369 | (setq next-buffer (nth 1 (memq buffer client)))) | 368 | (setq next-buffer (nth 1 (memq buffer client)))) |
| 370 | (delq buffer client) | 369 | (delq buffer client) |
| 371 | ;; Delete all dead buffers from CLIENT. | 370 | ;; Delete all dead buffers from CLIENT. |
| @@ -384,9 +383,9 @@ or nil. KILLED is t if we killed BUFFER | |||
| 384 | ;; It cannot handle that. | 383 | ;; It cannot handle that. |
| 385 | (or first (sit-for 1)) | 384 | (or first (sit-for 1)) |
| 386 | (setq first nil) | 385 | (setq first nil) |
| 387 | (send-string server-process | 386 | (send-string server-process |
| 388 | (format "Close: %s Done\n" (car client))) | 387 | (format "Close: %s Done\n" (car client))) |
| 389 | (server-log (format "Close: %s Done\n" (car client))))) | 388 | (server-log "Close" (car client)))) |
| 390 | (setq server-clients (delq client server-clients)))) | 389 | (setq server-clients (delq client server-clients)))) |
| 391 | (setq old-clients (cdr old-clients))) | 390 | (setq old-clients (cdr old-clients))) |
| 392 | (if (and (bufferp buffer) (buffer-name buffer)) | 391 | (if (and (bufferp buffer) (buffer-name buffer)) |