SLY: Add ambrevar/helm-selector-sly-non-ambrevar.

master
Pierre Neidhardt 2021-04-12 11:26:23 +02:00
parent 9b9763c737
commit 20cae7a49a
1 changed files with 55 additions and 7 deletions

View File

@ -1,6 +1,7 @@
(require 'sly-mrepl) ; For `sly-mrepl--find-buffer'.
(defvar ambrevar/sly-connection-name "sbcl-ambrevar")
(defun ambrevar/helm-sly-buffer-p (buffer)
"Return non-nil if BUFFER has a SLY connection matching
`ambrevar/sly-connection-name'."
@ -11,17 +12,41 @@
(string-prefix-p ambrevar/sly-connection-name
(sly-connection-name sly-buffer-connection)))))
(defun ambrevar/helm-sly-buffer-non-ambrevar-p (buffer)
"Return non-nil if BUFFER has a SLY connection not matching
`ambrevar/sly-connection-name'."
(with-current-buffer buffer
(and (derived-mode-p 'sly-mrepl-mode)
sly-buffer-connection
(sly-process sly-buffer-connection)
(not (string-prefix-p ambrevar/sly-connection-name
(sly-connection-name sly-buffer-connection))))))
(defun ambrevar/helm-sly-mini-sources (name predicate)
(list (helm-sly--c-source-connection
(helm-sly--repl-buffer-candidates
nil predicate)
name)
helm-sly-new
(helm-sly-lisp-buffer-source)
(helm-sly-build-buffers-source)))
(defun ambrevar/helm-sly-mini ()
"Helm for Lisp connections and buffers using the
`ambrevar/sly-connection-name' connection."
(interactive)
(helm :sources (list (helm-sly--c-source-connection
(helm-sly--repl-buffer-candidates
nil #'ambrevar/helm-sly-buffer-p)
"Ambrevar's Lisp connections")
helm-sly-new
(helm-sly-lisp-buffer-source)
(helm-sly-build-buffers-source))
(helm :sources (ambrevar/helm-sly-mini-sources
"Ambrevar's Lisp connections"
#'ambrevar/helm-sly-buffer-p)
:buffer "*ambrevar/helm-sly-mini*"))
(defun ambrevar/helm-sly-mini-non-ambrevar ()
"Helm for Lisp connections and buffers not using the
`ambrevar/sly-connection-name' connection."
(interactive)
(helm :sources (ambrevar/helm-sly-mini-sources
"Other Lisp connections"
#'ambrevar/helm-sly-buffer-non-ambrevar-p)
:buffer "*ambrevar/helm-sly-mini*"))
(defun ambrevar/helm-selector-sly ()
@ -51,4 +76,27 @@
(let ((current-prefix-arg t))
(call-interactively #'helm-selector-sly)))
(defun ambrevar/helm-selector-sly-non-ambrevar ()
"Helm for `sly' buffers not using the `ambrevar/sly-connection-name' connection."
(interactive)
(helm-selector
"SLY-REPL for all but Ambrevar's shells."
:predicate #'ambrevar/helm-sly-buffer-non-ambrevar-p
:make-buffer-fn (lambda () ; Copied from helm-selector-sly.el.
(interactive)
(if (and (null sly-net-processes)
(< 1 (length sly-lisp-implementations)))
(let ((current-prefix-arg '-))
(call-interactively #'sly))
;; Make sure to call interactively so that last
;; connection is reused.
(call-interactively #'sly)))
:helm-sources #'ambrevar/helm-sly-mini-non-ambrevar))
(defun ambrevar/helm-selector-sly-non-ambrevar-other-window ()
"Like `ambrevar/helm-selector-sly-non-ambrevar' but raise buffer in other window."
(interactive)
(let ((current-prefix-arg t))
(call-interactively #'helm-selector-sly)))
(provide 'init-sly-selector)