Helm/Eshell: Change name space to helm-eshell-prompts
parent
a6b0884567
commit
c62e19811c
|
@ -1,37 +1,48 @@
|
||||||
;;; TODO: Commit upstream.
|
;;; TODO: Commit upstream.
|
||||||
|
;;; TODO: defvar for sources
|
||||||
;;; TODO: Support multiline prompts?
|
;;; TODO: Support multiline prompts?
|
||||||
;;; TODO: Use candidate transformer and factor list function.
|
;;; TODO: Use candidate transformer and factor list function.
|
||||||
;;; TODO: Add yanking prompt, output (prompt+output?)
|
;;; TODO: Add action to yank prompt, output (prompt+output?)
|
||||||
;;; TODO: Namespace: helm-eshell-prompt
|
|
||||||
;;; TODO: Reverse output.
|
;;; TODO: Reverse output.
|
||||||
|
|
||||||
(defface helm-eshell-promptno
|
(defface helm-eshell-prompts-promptno
|
||||||
'((t (:foreground "cyan")))
|
'((t (:foreground "cyan")))
|
||||||
"Face used to highlight Eshell prompt index."
|
"Face used to highlight Eshell prompt index."
|
||||||
:group 'helm-eshell-faces)
|
:group 'helm-eshell-faces)
|
||||||
|
|
||||||
(defface helm-eshell-buffer-name
|
(defface helm-eshell-prompts-buffer-name
|
||||||
'((t (:foreground "green")))
|
'((t (:foreground "green")))
|
||||||
"Face used to highlight Eshell buffer name."
|
"Face used to highlight Eshell buffer name."
|
||||||
:group 'helm-eshell-faces)
|
:group 'helm-eshell-faces)
|
||||||
|
|
||||||
(defcustom helm-eshell-prompt-show-no t
|
(defcustom helm-eshell-prompts-max-length 400
|
||||||
|
"Max number of chars displayed per candidate in the Eshell prompt browser.
|
||||||
|
When t, don't truncate candidate, show all.
|
||||||
|
By default it is approximatively the number of bytes contained in five lines
|
||||||
|
of 80 single-byte characters each i.e 80*5.
|
||||||
|
Note that if you set this to nil, multiline will be disabled, i.e. there
|
||||||
|
will not be separators between candidates anymore."
|
||||||
|
:type '(choice (const :tag "Disabled" t)
|
||||||
|
(integer :tag "Max candidate offset"))
|
||||||
|
:group 'helm-eshell)
|
||||||
|
|
||||||
|
(defcustom helm-eshell-prompts-promptno-p t
|
||||||
"Show prompt number."
|
"Show prompt number."
|
||||||
:group 'helm-eshell
|
:group 'helm-eshell
|
||||||
:type 'boolean)
|
:type 'boolean)
|
||||||
|
|
||||||
(defun helm-eshell-prompt-list ()
|
(defun helm-eshell-prompts-list ()
|
||||||
"Return an alist of (prompt . pos)."
|
"Return an alist of (prompt . pos)."
|
||||||
(let (list)
|
(let (list)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-buffer)
|
(goto-char (point-min))
|
||||||
(let ((promptno 1))
|
(let ((promptno 1))
|
||||||
(while (not (eobp))
|
(while (not (eobp))
|
||||||
(eshell-next-prompt 1)
|
(eshell-next-prompt 1)
|
||||||
(let ((prompt (buffer-substring-no-properties (point) (line-end-position))))
|
(let ((prompt (buffer-substring-no-properties (point) (line-end-position))))
|
||||||
(setq list (cons `(,(if helm-eshell-prompt-show-no
|
(setq list (cons `(,(if helm-eshell-prompts-promptno-p
|
||||||
(format "%s:%s"
|
(format "%s:%s"
|
||||||
(propertize (number-to-string promptno) 'face 'helm-eshell-promptno)
|
(propertize (number-to-string promptno) 'face 'helm-eshell-prompts-promptno)
|
||||||
prompt)
|
prompt)
|
||||||
prompt)
|
prompt)
|
||||||
. ,(point))
|
. ,(point))
|
||||||
|
@ -39,43 +50,45 @@
|
||||||
promptno (1+ promptno))))))
|
promptno (1+ promptno))))))
|
||||||
list))
|
list))
|
||||||
|
|
||||||
(defun helm-eshell-all-prompt-list ()
|
(defun helm-eshell-prompts-list-all ()
|
||||||
"Return an alist of (\"buffer-name:prompt\" . (buffer . pos))."
|
"Return an alist of (\"buffer-name:prompt\" . (buffer . pos))."
|
||||||
(let (list)
|
(let (list)
|
||||||
(dolist (b (buffer-list))
|
(dolist (b (buffer-list))
|
||||||
(with-current-buffer b
|
(with-current-buffer b
|
||||||
(when (eq major-mode 'eshell-mode)
|
(when (eq major-mode 'eshell-mode)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-buffer)
|
(goto-char (point-min))
|
||||||
(let ((buffer-name (propertize (buffer-name) 'face 'helm-eshell-buffer-name))
|
(let ((buffer-name (propertize (buffer-name) 'face 'helm-eshell-prompts-buffer-name))
|
||||||
(promptno 1))
|
(promptno 1))
|
||||||
(while (not (eobp))
|
(while (not (eobp))
|
||||||
(eshell-next-prompt 1)
|
(eshell-next-prompt 1)
|
||||||
(setq list (cons `(,(format "%s:%s:%s"
|
(setq list (cons `(,(format "%s:%s:%s"
|
||||||
buffer-name
|
buffer-name
|
||||||
(propertize (number-to-string promptno) 'face 'helm-eshell-promptno)
|
(propertize (number-to-string promptno) 'face 'helm-eshell-prompts-promptno)
|
||||||
(buffer-substring-no-properties (point) (line-end-position)))
|
(buffer-substring-no-properties (point) (line-end-position)))
|
||||||
. (,b . ,(point)))
|
. (,b . ,(point)))
|
||||||
list))
|
list))
|
||||||
(setq promptno (1+ promptno))))))))
|
(setq promptno (1+ promptno))))))))
|
||||||
list))
|
list))
|
||||||
|
|
||||||
(defun helm-eshell-goto-prompt (candidate)
|
(defun helm-eshell-prompts-goto (candidate)
|
||||||
(goto-char candidate))
|
(goto-char candidate))
|
||||||
|
|
||||||
(defun helm-eshell-goto-all-prompt (candidate)
|
;; TODO: Merge goto and goto-buffer, check for buffer existence in candidate.
|
||||||
|
(defun helm-eshell-prompts-goto-buffer (candidate)
|
||||||
|
;; (if (alist-get ...)...
|
||||||
(switch-to-buffer (car candidate))
|
(switch-to-buffer (car candidate))
|
||||||
(goto-char (cdr candidate)))
|
(goto-char (cdr candidate)))
|
||||||
|
|
||||||
(defun helm-eshell-goto-all-prompt-other-window (candidate)
|
(defun helm-eshell-prompts-goto-buffer-other-window (candidate)
|
||||||
(switch-to-buffer-other-window (car candidate))
|
(switch-to-buffer-other-window (car candidate))
|
||||||
(goto-char (cdr candidate)))
|
(goto-char (cdr candidate)))
|
||||||
|
|
||||||
(defun helm-eshell-goto-all-prompt-other-frame (candidate)
|
(defun helm-eshell-prompts-goto-buffer-other-window (candidate)
|
||||||
(switch-to-buffer-other-frame (car candidate))
|
(switch-to-buffer-other-frame (car candidate))
|
||||||
(goto-char (cdr candidate)))
|
(goto-char (cdr candidate)))
|
||||||
|
|
||||||
(defvar helm-eshell-goto-prompt-keymap
|
(defvar helm-eshell-prompts-keymap
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(set-keymap-parent map helm-map)
|
(set-keymap-parent map helm-map)
|
||||||
(define-key map (kbd "C-c o") 'helm-eshell-goto-all-prompt-other-window)
|
(define-key map (kbd "C-c o") 'helm-eshell-goto-all-prompt-other-window)
|
||||||
|
@ -83,31 +96,34 @@
|
||||||
map)
|
map)
|
||||||
"Keymap for `helm-eshell-prompt-all'.")
|
"Keymap for `helm-eshell-prompt-all'.")
|
||||||
|
|
||||||
(with-eval-after-load 'helm
|
;;;###autoload
|
||||||
;; TODO: Add autoloads
|
(defun helm-eshell-prompts ()
|
||||||
(defun helm-eshell-prompts ()
|
"Pre-configured `helm' to browse the prompts of the current Eshell."
|
||||||
"Preconfigured `helm' to browse the prompts of the current Eshell."
|
(interactive)
|
||||||
(interactive)
|
(if (eq major-mode 'eshell-mode)
|
||||||
(if (eq major-mode 'eshell-mode)
|
(helm :sources
|
||||||
(helm :sources
|
(helm-build-sync-source "Eshell prompts"
|
||||||
(helm-build-sync-source "Eshell prompts"
|
;; :init (lambda ()
|
||||||
:candidates (helm-eshell-prompt-list)
|
;; (helm-attrset 'multiline helm-eshell-prompts-max-length))
|
||||||
:action '(("Go to prompt" . helm-eshell-goto-prompt)))
|
:candidates (helm-eshell-prompts-list)
|
||||||
:buffer "*helm-eshell-prompts*")
|
:action '(("Go to prompt" . helm-eshell-prompts-goto))
|
||||||
(message "Current buffer is not an Eshell buffer")))
|
;; :multiline 'helm-eshell-prompts-max-length)
|
||||||
|
)
|
||||||
|
:buffer "*helm-eshell-prompts*")
|
||||||
|
(message "Current buffer is not an Eshell buffer")))
|
||||||
|
|
||||||
(defun helm-eshell-prompts-all ()
|
;;;###autoload
|
||||||
"Preconfigured `helm' to browse the prompts of all Eshell sessions."
|
(defun helm-eshell-prompts-all ()
|
||||||
(interactive)
|
"Pre-configured `helm' to browse the prompts of all Eshell sessions."
|
||||||
(helm :sources
|
(interactive)
|
||||||
(helm-build-sync-source "All Eshell prompts"
|
(helm :sources
|
||||||
:candidates (helm-eshell-all-prompt-list)
|
(helm-build-sync-source "All Eshell prompts"
|
||||||
:action '(("Go to prompt" . helm-eshell-goto-all-prompt)
|
:candidates (helm-eshell-prompts-list-all)
|
||||||
("Go to prompt in other window `C-c o`" . helm-eshell-goto-all-prompt-other-window)
|
:action '(("Go to prompt" . helm-eshell-prompts-goto-buffer)
|
||||||
("Go to prompt in other frame `C-c C-o`" . helm-eshell-goto-all-prompt-other-frame)
|
("Go to prompt in other window `C-c o`" . helm-eshell-prompts-goto-buffer-other-window)
|
||||||
:))
|
("Go to prompt in other frame `C-c C-o`" . helm-eshell-prompts-goto-buffer-other-frame)))
|
||||||
:buffer "*helm-eshell-all-prompts*"))
|
:buffer "*helm-eshell-all-prompts*"))
|
||||||
|
|
||||||
(add-to-list 'helm-source-names-using-follow "helm-eshell-prompts"))
|
(add-to-list 'helm-source-names-using-follow "helm-eshell-prompts")
|
||||||
|
|
||||||
(provide 'package-helm-eshell)
|
(provide 'package-helm-eshell)
|
||||||
|
|
Loading…
Reference in New Issue