diff options
| author | João Távora | 2020-05-01 13:24:56 +0100 |
|---|---|---|
| committer | João Távora | 2020-05-01 16:59:05 +0100 |
| commit | b23daca20788ab6b54362c5bdb0470887de106fb (patch) | |
| tree | 672edf2f68b801f7b4ea585d1a8f772e7e83415c | |
| parent | 2a8784129daf270d0a20ce3531e488de51de7520 (diff) | |
| download | emacs-b23daca20788ab6b54362c5bdb0470887de106fb.tar.gz emacs-b23daca20788ab6b54362c5bdb0470887de106fb.zip | |
Consolidate lisp/jsonrpc.el logging in single events buffer
For inferior processes having useful stderr, it is no longer
cumbersome to switch between different buffers to correlate error
messages with transport-level JSONRPC messages.
The existing stderr and stdout buffers can still be found hidden away
from the normal buffer list.
An original idea of Tobias Rittweiler <trittweiler@gmail.com>.
* lisp/jsonrpc.el (initialize-instance jsonrpc-process-connection):
Setup after-change functions stderr buffer. Hide stderr and stdout
buffers.
(jsonrpc--log-event): Don't output extra newline. Tweak log format.
(Version): Bump to 1.0.10
| -rw-r--r-- | lisp/jsonrpc.el | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el index 65c0df8f57c..69ee94159d7 100644 --- a/lisp/jsonrpc.el +++ b/lisp/jsonrpc.el | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | ;; Author: João Távora <joaotavora@gmail.com> | 5 | ;; Author: João Távora <joaotavora@gmail.com> |
| 6 | ;; Keywords: processes, languages, extensions | 6 | ;; Keywords: processes, languages, extensions |
| 7 | ;; Package-Requires: ((emacs "25.2")) | 7 | ;; Package-Requires: ((emacs "25.2")) |
| 8 | ;; Version: 1.0.9 | 8 | ;; Version: 1.0.10 |
| 9 | 9 | ||
| 10 | ;; This is an Elpa :core package. Don't use functionality that is not | 10 | ;; This is an Elpa :core package. Don't use functionality that is not |
| 11 | ;; compatible with Emacs 25.2. | 11 | ;; compatible with Emacs 25.2. |
| @@ -364,21 +364,49 @@ connection object, called when the process dies .") | |||
| 364 | 364 | ||
| 365 | (cl-defmethod initialize-instance ((conn jsonrpc-process-connection) slots) | 365 | (cl-defmethod initialize-instance ((conn jsonrpc-process-connection) slots) |
| 366 | (cl-call-next-method) | 366 | (cl-call-next-method) |
| 367 | (let* ((proc (plist-get slots :process)) | 367 | (cl-destructuring-bind (&key ((:process proc)) name &allow-other-keys) slots |
| 368 | (proc (if (functionp proc) (funcall proc) proc)) | 368 | ;; FIXME: notice the undocumented bad coupling in the buffer name. |
| 369 | (buffer (get-buffer-create (format "*%s output*" (process-name proc)))) | 369 | ;; The client making the process _must_ use a buffer named exactly |
| 370 | (stderr (get-buffer-create (format "*%s stderr*" (process-name proc))))) | 370 | ;; like this property when calling `make-process'. If there were |
| 371 | ;; a `set-process-stderr' like there is `set-process-buffer' we | ||
| 372 | ;; wouldn't need this and could use a pipe with a process filter | ||
| 373 | ;; instead of `after-change-functions'. Alternatively, we need a | ||
| 374 | ;; new initarg (but maybe not a slot). | ||
| 375 | (with-current-buffer (get-buffer-create (format "*%s stderr*" name)) | ||
| 376 | (let ((inhibit-read-only t) | ||
| 377 | (hidden-name (concat " " (buffer-name)))) | ||
| 378 | (erase-buffer) | ||
| 379 | (buffer-disable-undo) | ||
| 380 | (add-hook | ||
| 381 | 'after-change-functions | ||
| 382 | (lambda (beg _end _pre-change-len) | ||
| 383 | (cl-loop initially (goto-char beg) | ||
| 384 | do (forward-line) | ||
| 385 | when (bolp) | ||
| 386 | for line = (buffer-substring | ||
| 387 | (line-beginning-position 0) | ||
| 388 | (line-end-position 0)) | ||
| 389 | do (with-current-buffer (jsonrpc-events-buffer conn) | ||
| 390 | (goto-char (point-max)) | ||
| 391 | (let ((inhibit-read-only t)) | ||
| 392 | (insert (format "[stderr] %s\n" line)))) | ||
| 393 | until (eobp))) | ||
| 394 | nil t) | ||
| 395 | ;; If we are correctly coupled to the client, it should pick up | ||
| 396 | ;; the current buffer immediately. | ||
| 397 | (setq proc (if (functionp proc) (funcall proc) proc)) | ||
| 398 | (ignore-errors (kill-buffer hidden-name)) | ||
| 399 | (rename-buffer hidden-name) | ||
| 400 | (process-put proc 'jsonrpc-stderr (current-buffer)) | ||
| 401 | (read-only-mode t)) | ||
| 371 | (setf (jsonrpc--process conn) proc) | 402 | (setf (jsonrpc--process conn) proc) |
| 372 | (set-process-buffer proc buffer) | 403 | (set-process-buffer proc (get-buffer-create (format " *%s output*" name))) |
| 373 | (process-put proc 'jsonrpc-stderr stderr) | ||
| 374 | (set-process-filter proc #'jsonrpc--process-filter) | 404 | (set-process-filter proc #'jsonrpc--process-filter) |
| 375 | (set-process-sentinel proc #'jsonrpc--process-sentinel) | 405 | (set-process-sentinel proc #'jsonrpc--process-sentinel) |
| 376 | (with-current-buffer (process-buffer proc) | 406 | (with-current-buffer (process-buffer proc) |
| 377 | (buffer-disable-undo) | 407 | (buffer-disable-undo) |
| 378 | (set-marker (process-mark proc) (point-min)) | 408 | (set-marker (process-mark proc) (point-min)) |
| 379 | (let ((inhibit-read-only t)) (erase-buffer) (read-only-mode t) proc)) | 409 | (let ((inhibit-read-only t)) (erase-buffer) (read-only-mode t))) |
| 380 | (with-current-buffer stderr | ||
| 381 | (buffer-disable-undo)) | ||
| 382 | (process-put proc 'jsonrpc-connection conn))) | 410 | (process-put proc 'jsonrpc-connection conn))) |
| 383 | 411 | ||
| 384 | (cl-defmethod jsonrpc-connection-send ((connection jsonrpc-process-connection) | 412 | (cl-defmethod jsonrpc-connection-send ((connection jsonrpc-process-connection) |
| @@ -682,7 +710,7 @@ originated." | |||
| 682 | (format "-%s" subtype))))) | 710 | (format "-%s" subtype))))) |
| 683 | (goto-char (point-max)) | 711 | (goto-char (point-max)) |
| 684 | (prog1 | 712 | (prog1 |
| 685 | (let ((msg (format "%s%s%s %s:\n%s\n" | 713 | (let ((msg (format "[%s]%s%s %s:\n%s" |
| 686 | type | 714 | type |
| 687 | (if id (format " (id:%s)" id) "") | 715 | (if id (format " (id:%s)" id) "") |
| 688 | (if error " ERROR" "") | 716 | (if error " ERROR" "") |