mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-04 15:41:37 -05:00
jupyter-repl-available-repl-buffers: Refactor
Also give an option to return the first found REPL buffer that can be used for a major mode.
This commit is contained in:
parent
6c836bd3d8
commit
4a7e95eb18
1 changed files with 13 additions and 11 deletions
|
@ -2473,19 +2473,21 @@ it."
|
|||
(pop-to-buffer (current-buffer)))
|
||||
(error "Buffer not associated with a REPL, see `jupyter-repl-associate-buffer'")))
|
||||
|
||||
(defun jupyter-repl-available-repl-buffers (&optional mode)
|
||||
(defun jupyter-repl-available-repl-buffers (&optional mode first)
|
||||
"Return a list of REPL buffers that are connected to live kernels.
|
||||
If MODE is non-nil, return all REPL buffers whose
|
||||
`jupyter-repl-lang-mode' is MODE."
|
||||
(delq
|
||||
nil
|
||||
(mapcar (lambda (b)
|
||||
(with-current-buffer b
|
||||
(and (eq major-mode 'jupyter-repl-mode)
|
||||
(if mode (eq mode jupyter-repl-lang-mode) t)
|
||||
(jupyter-repl-connected-p)
|
||||
(buffer-name b))))
|
||||
(buffer-list))))
|
||||
`jupyter-repl-lang-mode' is MODE.
|
||||
|
||||
If FIRST is non-nil, only return the first REPL buffer that matches."
|
||||
(cl-loop
|
||||
for buf in (buffer-list)
|
||||
for match = (with-current-buffer buf
|
||||
(and (eq major-mode 'jupyter-repl-mode)
|
||||
(if mode (eq mode jupyter-repl-lang-mode) t)
|
||||
(jupyter-repl-connected-p)
|
||||
(buffer-name)))
|
||||
if (and match first) return buf
|
||||
else if match collect buf))
|
||||
|
||||
;;;###autoload
|
||||
(defun jupyter-repl-associate-buffer (client)
|
||||
|
|
Loading…
Add table
Reference in a new issue