summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Neidhardt <mail@ambrevar.xyz>2019-02-14 14:26:28 +0100
committerPierre Neidhardt <mail@ambrevar.xyz>2019-02-15 19:16:42 +0100
commit802b9c6910317ef834d5544c39748f71c7dcc162 (patch)
tree8b799531d26040e870fbd45710a45691980dda49
parent164b06aa0cc2f63baa4fb243d89a01585258bf5d (diff)
Enable helm-shell-prompts in all comint-based modes (SLIME, Geiser, etc.)
-rw-r--r--helm-shell.el47
1 files changed, 26 insertions, 21 deletions
diff --git a/helm-shell.el b/helm-shell.el
index 1b6326ab..92bdf8f4 100644
--- a/helm-shell.el
+++ b/helm-shell.el
@@ -46,6 +46,12 @@
:group 'helm-shell
:type 'boolean)
+(defcustom helm-shell-comint-mode-list '(comint-mode slime-repl-mode)
+ "Supported modes for prompt navigation.
+Derived modes (e.g. Geiser's REPL) are automatically supported."
+ :group 'helm-shell
+ :type '(repeat (choice symbol)))
+
(defvar helm-shell-prompts-keymap
(let ((map (make-sparse-keymap)))
(set-keymap-parent map helm-map)
@@ -54,16 +60,14 @@
map)
"Keymap for `helm-shell-prompt-all'.")
-(defvar shell-prompt-pattern)
-
-(defun helm-shell-prompts-list (&optional buffer)
- "List the prompts in Shell BUFFER.
+(defun helm-shell-prompts-list (mode &optional buffer)
+ "List the prompts in BUFFER in mode MODE.
Return a list of (\"prompt\" (point) (buffer-name) prompt-index))
e.g. (\"ls\" 162 \"*shell*\" 3).
If BUFFER is nil, use current buffer."
(with-current-buffer (or buffer (current-buffer))
- (when (eq major-mode 'shell-mode)
+ (when (derived-mode-p mode)
(save-excursion
(goto-char (point-min))
(let (result (count 1))
@@ -76,11 +80,11 @@ If BUFFER is nil, use current buffer."
(setq count (1+ count))))
(nreverse result))))))
-(defun helm-shell-prompts-list-all ()
- "List the prompts of all Shell buffers.
+(defun helm-shell-prompts-list-all (mode)
+ "List the prompts of all buffers in mode MODE.
See `helm-shell-prompts-list'."
(cl-loop for b in (buffer-list)
- append (helm-shell-prompts-list b)))
+ append (helm-shell-prompts-list mode b)))
(defun helm-shell-prompts-transformer (candidates &optional all)
;; ("ls" 162 "*shell*" 3) => ("*shell*:3:ls" . ("ls" 162 "*shell*" 3))
@@ -133,10 +137,10 @@ See `helm-shell-prompts-list'."
(defun helm-shell-prompts ()
"Pre-configured `helm' to browse the prompts of the current Shell."
(interactive)
- (if (eq major-mode 'shell-mode)
+ (if (cl-member-if 'derived-mode-p helm-shell-comint-mode-list)
(helm :sources
(helm-build-sync-source "Shell prompts"
- :candidates (helm-shell-prompts-list)
+ :candidates (helm-shell-prompts-list major-mode)
:candidate-transformer 'helm-shell-prompts-transformer
:action '(("Go to prompt" . helm-shell-prompts-goto)))
:buffer "*helm Shell prompts*")
@@ -146,17 +150,18 @@ See `helm-shell-prompts-list'."
(defun helm-shell-prompts-all ()
"Pre-configured `helm' to browse the prompts of all Shell sessions."
(interactive)
- (helm :sources
- (helm-build-sync-source "All Shell prompts"
- :candidates (helm-shell-prompts-list-all)
- :candidate-transformer 'helm-shell-prompts-all-transformer
- :action '(("Go to prompt" . helm-shell-prompts-goto)
- ("Go to prompt in other window `C-c o`" .
- helm-shell-prompts-goto-other-window)
- ("Go to prompt in other frame `C-c C-o`" .
- helm-shell-prompts-goto-other-frame))
- :keymap helm-shell-prompts-keymap)
- :buffer "*helm Shell all prompts*"))
+ (when (cl-member-if 'derived-mode-p helm-shell-comint-mode-list)
+ (helm :sources
+ (helm-build-sync-source "All Shell prompts"
+ :candidates (helm-shell-prompts-list-all major-mode)
+ :candidate-transformer 'helm-shell-prompts-all-transformer
+ :action '(("Go to prompt" . helm-shell-prompts-goto)
+ ("Go to prompt in other window `C-c o`" .
+ helm-shell-prompts-goto-other-window)
+ ("Go to prompt in other frame `C-c C-o`" .
+ helm-shell-prompts-goto-other-frame))
+ :keymap helm-shell-prompts-keymap)
+ :buffer "*helm Shell all prompts*")))
(provide 'helm-shell)