aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2020-06-03 20:53:35 +0100
committerJoão Távora2020-06-03 20:54:39 +0100
commitbd20af2d41f24c9e59acb867a1a4485284cb2a65 (patch)
tree263aaf231a7e0c859f32ab4b66967e909d162656
parent7e8c1a671872ef8e45057f25912594cf548639ab (diff)
downloademacs-bd20af2d41f24c9e59acb867a1a4485284cb2a65.tar.gz
emacs-bd20af2d41f24c9e59acb867a1a4485284cb2a65.zip
Ensure Jsonrpc processes are created in correct buffer
Report and original implementation by Steve Purcell <steve@sanityinc.com>. See also See https://github.com/joaotavora/eglot/pull/493 for details * lisp/jsonrpc.el (initialize-instance): Make process in original buffer. (Version): Bump to 1.0.12
-rw-r--r--lisp/jsonrpc.el74
1 files changed, 39 insertions, 35 deletions
diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el
index 42e7701af18..ff8f250a22e 100644
--- a/lisp/jsonrpc.el
+++ b/lisp/jsonrpc.el
@@ -4,7 +4,7 @@
4 4
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;; Version: 1.0.11 7;; Version: 1.0.12
8;; Package-Requires: ((emacs "25.2")) 8;; Package-Requires: ((emacs "25.2"))
9 9
10;; This is a GNU ELPA :core package. Avoid functionality that is not 10;; This is a GNU ELPA :core package. Avoid functionality that is not
@@ -364,40 +364,44 @@ connection object, called when the process dies .")
364(cl-defmethod initialize-instance ((conn jsonrpc-process-connection) slots) 364(cl-defmethod initialize-instance ((conn jsonrpc-process-connection) slots)
365 (cl-call-next-method) 365 (cl-call-next-method)
366 (cl-destructuring-bind (&key ((:process proc)) name &allow-other-keys) slots 366 (cl-destructuring-bind (&key ((:process proc)) name &allow-other-keys) slots
367 ;; FIXME: notice the undocumented bad coupling in the buffer name. 367 ;; FIXME: notice the undocumented bad coupling in the stderr
368 ;; The client making the process _must_ use a buffer named exactly 368 ;; buffer name, it must be named exactly like this we expect when
369 ;; like this property when calling `make-process'. If there were 369 ;; calling `make-process'. If there were a `set-process-stderr'
370 ;; a `set-process-stderr' like there is `set-process-buffer' we 370 ;; like there is `set-process-buffer' we wouldn't need this and
371 ;; wouldn't need this and could use a pipe with a process filter 371 ;; could use a pipe with a process filter instead of
372 ;; instead of `after-change-functions'. Alternatively, we need a 372 ;; `after-change-functions'. Alternatively, we need a new initarg
373 ;; new initarg (but maybe not a slot). 373 ;; (but maybe not a slot).
374 (with-current-buffer (get-buffer-create (format "*%s stderr*" name)) 374 (let ((calling-buffer (current-buffer)))
375 (let ((inhibit-read-only t) 375 (with-current-buffer (get-buffer-create (format "*%s stderr*" name))
376 (hidden-name (concat " " (buffer-name)))) 376 (let ((inhibit-read-only t)
377 (erase-buffer) 377 (hidden-name (concat " " (buffer-name))))
378 (buffer-disable-undo) 378 (erase-buffer)
379 (add-hook 379 (buffer-disable-undo)
380 'after-change-functions 380 (add-hook
381 (lambda (beg _end _pre-change-len) 381 'after-change-functions
382 (cl-loop initially (goto-char beg) 382 (lambda (beg _end _pre-change-len)
383 do (forward-line) 383 (cl-loop initially (goto-char beg)
384 when (bolp) 384 do (forward-line)
385 for line = (buffer-substring 385 when (bolp)
386 (line-beginning-position 0) 386 for line = (buffer-substring
387 (line-end-position 0)) 387 (line-beginning-position 0)
388 do (with-current-buffer (jsonrpc-events-buffer conn) 388 (line-end-position 0))
389 (goto-char (point-max)) 389 do (with-current-buffer (jsonrpc-events-buffer conn)
390 (let ((inhibit-read-only t)) 390 (goto-char (point-max))
391 (insert (format "[stderr] %s\n" line)))) 391 (let ((inhibit-read-only t))
392 until (eobp))) 392 (insert (format "[stderr] %s\n" line))))
393 nil t) 393 until (eobp)))
394 ;; If we are correctly coupled to the client, it should pick up 394 nil t)
395 ;; the current buffer immediately. 395 ;; If we are correctly coupled to the client, the process
396 (setq proc (if (functionp proc) (funcall proc) proc)) 396 ;; now created should pick up the current stderr buffer,
397 (ignore-errors (kill-buffer hidden-name)) 397 ;; which we immediately rename
398 (rename-buffer hidden-name) 398 (setq proc (if (functionp proc)
399 (process-put proc 'jsonrpc-stderr (current-buffer)) 399 (with-current-buffer calling-buffer (funcall proc))
400 (read-only-mode t))) 400 proc))
401 (ignore-errors (kill-buffer hidden-name))
402 (rename-buffer hidden-name)
403 (process-put proc 'jsonrpc-stderr (current-buffer))
404 (read-only-mode t))))
401 (setf (jsonrpc--process conn) proc) 405 (setf (jsonrpc--process conn) proc)
402 (set-process-buffer proc (get-buffer-create (format " *%s output*" name))) 406 (set-process-buffer proc (get-buffer-create (format " *%s output*" name)))
403 (set-process-filter proc #'jsonrpc--process-filter) 407 (set-process-filter proc #'jsonrpc--process-filter)