diff options
author | Pierre Neidhardt <ambrevar@gmail.com> | 2017-10-30 11:43:12 +0100 |
---|---|---|
committer | Pierre Neidhardt <ambrevar@gmail.com> | 2017-10-30 11:43:12 +0100 |
commit | 04b82532eebd47c01aa2e2ea4ce62c0e0716aa68 (patch) | |
tree | a20522a373942897733946aee788a136d5afeeb5 /helm-eshell.el | |
parent | ffd2abf5c4bdfc998c09730387b11d2bf9ac1032 (diff) |
Add helm-eshell-prompts
Diffstat (limited to 'helm-eshell.el')
-rw-r--r-- | helm-eshell.el | 112 |
1 files changed, 111 insertions, 1 deletions
diff --git a/helm-eshell.el b/helm-eshell.el index c01e3c04..18c89802 100644 --- a/helm-eshell.el +++ b/helm-eshell.el @@ -22,6 +22,7 @@ ;; (lambda () ;; (eshell-cmpl-initialize) ;; (define-key eshell-mode-map [remap eshell-pcomplete] 'helm-esh-pcomplete) +;; (define-key eshell-mode-map (kbd "M-s f") 'helm-eshell-prompts-all))) ;; (define-key eshell-mode-map (kbd "M-r") 'helm-eshell-history))) @@ -81,7 +82,7 @@ (filtered-candidate-transformer :initform (lambda (candidates _sources) - (cl-loop + (cl-loop for i in candidates collect (cond ((string-match "\\`~/?" helm-ec-target) @@ -334,6 +335,115 @@ The function that call this should set `helm-ec-target' to thing at point." (looking-back " " (1- (point)))) (delete-char -1))))) + + +(defface helm-eshell-prompts-promptidx + '((t (:foreground "cyan"))) + "Face used to highlight Eshell prompt index." + :group 'helm-eshell-faces) + +(defface helm-eshell-prompts-buffer-name + '((t (:foreground "green"))) + "Face used to highlight Eshell buffer name." + :group 'helm-eshell-faces) + +(defcustom helm-eshell-prompts-promptidx-p t + "Show prompt number." + :group 'helm-eshell + :type 'boolean) + +(defun helm-eshell-prompts-list (&optional buffer) + "List the prompts in Eshell BUFFER. + +Return a list of (\"prompt\" (point) (buffer-name) prompt-index)). +If BUFFER is nil, use current buffer." + (let ((buffer (or buffer (current-buffer))) + list) + (with-current-buffer buffer + (when (eq major-mode 'eshell-mode) + (save-excursion + (goto-char (point-min)) + (let ((promptno 1)) + (while (not (eobp)) + (eshell-next-prompt 1) + (setq list (cons (list (buffer-substring-no-properties (point) (line-end-position)) + (point) + (buffer-name) + (if helm-eshell-prompts-promptidx-p promptno)) + list) + promptno (1+ promptno))))))) + (nreverse list))) + +(defun helm-eshell-prompts-list-all () + "List the prompts of all Eshell buffers. +See `helm-eshell-prompts-list'." + (let (list) + (dolist (b (buffer-list)) + (setq list (append (helm-eshell-prompts-list b) list))) + list)) + +(defun helm-eshell-prompts-transformer (candidates &optional all) + (dolist (c candidates) + (setcar c + (concat + (when all + (concat (propertize (nth 2 c) 'face 'helm-eshell-prompts-buffer-name) ":")) + (when helm-eshell-prompts-promptidx-p + (concat (propertize (number-to-string (nth 3 c)) 'face 'helm-eshell-prompts-promptidx) ":")) + (car c)))) + candidates) + +(defun helm-eshell-prompts-all-transformer (candidates &optional all) + (helm-eshell-prompts-transformer candidates t)) + +(defun helm-eshell-prompts-goto (candidate) + (when (nth 1 candidate) + (switch-to-buffer (nth 1 candidate))) + (goto-char (car candidate))) + +(defun helm-eshell-prompts-goto-other-window (candidate) + (switch-to-buffer-other-window (cdr candidate)) + (goto-char (car candidate))) + +(defun helm-eshell-prompts-goto-other-frame (candidate) + (switch-to-buffer-other-frame (cdr candidate)) + (goto-char (car candidate))) + +(defvar helm-eshell-prompts-keymap + (let ((map (make-sparse-keymap))) + (set-keymap-parent map helm-map) + (define-key map (kbd "C-c o") 'helm-eshell-prompts-goto-other-window) + (define-key map (kbd "C-c C-o") 'helm-eshell-prompts-goto-other-frame) + map) + "Keymap for `helm-eshell-prompt-all'.") + +;;;###autoload +(defun helm-eshell-prompts () + "Pre-configured `helm' to browse the prompts of the current Eshell." + (interactive) + (if (eq major-mode 'eshell-mode) + (helm :sources + (helm-build-sync-source "Eshell prompts" + :candidates (helm-eshell-prompts-list) + :candidate-transformer 'helm-eshell-prompts-transformer + :action '(("Go to prompt" . helm-eshell-prompts-goto)) + ) + :buffer "*helm Eshell prompts*") + (message "Current buffer is not an Eshell buffer"))) + +;;;###autoload +(defun helm-eshell-prompts-all () + "Pre-configured `helm' to browse the prompts of all Eshell sessions." + (interactive) + (helm :sources + (helm-build-sync-source "All Eshell prompts" + :candidates (helm-eshell-prompts-list-all) + :candidate-transformer 'helm-eshell-prompts-all-transformer + :action '(("Go to prompt" . helm-eshell-prompts-goto) + ("Go to prompt in other window `C-c o`" . helm-eshell-prompts-goto-other-window) + ("Go to prompt in other frame `C-c C-o`" . helm-eshell-prompts-goto-other-frame))) + :buffer "*helm Eshell all prompts*")) + (provide 'helm-eshell) ;; Local Variables: |