summaryrefslogtreecommitdiff
path: root/helm-eshell.el
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2018-04-07 09:22:30 -0700
committerSean Whitton <spwhitton@spwhitton.name>2018-04-07 09:22:30 -0700
commit5af6bb3b8772de37111d76602b6eef2daaedb07d (patch)
treee12345eb3ff34fd776b942b0e0f0e87250bd4a0d /helm-eshell.el
parent9d964b93b70693139a84e108312733291c05e6b8 (diff)
parentd5b9404176c41b16dffe522d45d08bdc7cb60e28 (diff)
Merge tag 'v2.9.2'
Version 2.9.2 # gpg: Signature made Sat 07 Apr 2018 01:23:15 AM MST # gpg: using DSA key 28D17F5359F29997 # gpg: Can't check signature: No public key
Diffstat (limited to 'helm-eshell.el')
-rw-r--r--helm-eshell.el124
1 files changed, 77 insertions, 47 deletions
diff --git a/helm-eshell.el b/helm-eshell.el
index 34e66dae..66e81d75 100644
--- a/helm-eshell.el
+++ b/helm-eshell.el
@@ -39,7 +39,7 @@
(declare-function eshell-parse-arguments "esh-arg" (beg end))
(declare-function eshell-backward-argument "esh-mode" (&optional arg))
(declare-function helm-quote-whitespace "helm-lib")
-(declare-function eshell-next-prompt "em-prompt")
+(declare-function eshell-skip-prompt "em-prompt")
(defvar eshell-special-chars-outside-quoting)
@@ -68,6 +68,8 @@
map)
"Keymap for `helm-esh-pcomplete'.")
+(defvar helm-eshell--quit-flag nil)
+
(defclass helm-esh-source (helm-source-sync)
((init :initform (lambda ()
@@ -150,6 +152,9 @@ The function that call this should set `helm-ec-target' to thing at point."
(expand-file-name entry default-directory)))
with comps = (all-completions pcomplete-stub table)
unless comps return (prog1 nil
+ ;; Don't add final space when
+ ;; there is no completion (issue #1990).
+ (setq helm-eshell--quit-flag t)
(message "No completions of %s" pcomplete-stub))
for i in comps
;; Transform the related names to abs names.
@@ -209,9 +214,6 @@ The function that call this should set `helm-ec-target' to thing at point."
"Helm class to define source for Eshell history.")
-
-(defvar helm-eshell--quit-flag nil)
-
;;;###autoload
(defun helm-esh-pcomplete ()
"Preconfigured helm to provide helm completion in eshell."
@@ -297,7 +299,9 @@ The function that call this should set `helm-ec-target' to thing at point."
(and del-space (looking-back "\\s-" (1- (point)))
(delete-char -1))
(if (and (null helm-eshell--quit-flag)
- (looking-back "[.]\\{1,2\\}\\'" (1- (point))))
+ (and (stringp last) (file-directory-p last))
+ (looking-back "\\([.]\\{1,2\\}\\|[^/]\\)\\'"
+ (1- (point))))
(prog1 t (insert "/"))
;; We need another flag for space here, but
;; global to pass it to `helm-quit-hook', this
@@ -306,7 +310,10 @@ The function that call this should set `helm-ec-target' to thing at point."
;; more completion, see issue #1832.
(unless (or helm-eshell--quit-flag
(looking-back "/\\'" (1- (point))))
- (prog1 t (insert " ")))))
+ (prog1 t (insert " ")))
+ (when (and helm-eshell--quit-flag
+ (string-match-p "[.]\\{2\\}\\'" last))
+ (insert "/"))))
(remove-hook 'helm-quit-hook 'helm-eshell--quit-hook-fn)
(setq helm-eshell--quit-flag nil)))))))
@@ -354,69 +361,91 @@ The function that call this should set `helm-ec-target' to thing at point."
:group 'helm-eshell
:type 'boolean)
+(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-other-window)
+ (define-key map (kbd "C-c C-o") 'helm-eshell-prompts-other-frame)
+ map)
+ "Keymap for `helm-eshell-prompt-all'.")
+
+(defvar eshell-prompt-regexp)
+(defvar eshell-highlight-prompt)
+
(defun helm-eshell-prompts-list (&optional buffer)
"List the prompts in Eshell BUFFER.
-Return a list of (\"prompt\" (point) (buffer-name) prompt-index)).
+Return a list of (\"prompt\" (point) (buffer-name) prompt-index))
+e.g. (\"ls\" 162 \"*eshell*\" 3).
If BUFFER is nil, use current buffer."
(with-current-buffer (or buffer (current-buffer))
(when (eq major-mode 'eshell-mode)
(save-excursion
(goto-char (point-min))
- (cl-loop while (not (eobp))
- for promptno from 1
- do (eshell-next-prompt 1)
- collect (list (buffer-substring-no-properties
- (point) (line-end-position))
- (point)
- (buffer-name)
- (and helm-eshell-prompts-promptidx-p
- promptno)))))))
+ (let (result (count 1))
+ (helm-awhile (re-search-forward eshell-prompt-regexp nil t)
+ (when (or (and eshell-highlight-prompt
+ (get-text-property (match-beginning 0) 'read-only))
+ (null eshell-highlight-prompt))
+ (push (list (buffer-substring-no-properties
+ it (point-at-eol))
+ it (buffer-name) count)
+ result)
+ (setq count (1+ count))))
+ (nreverse result))))))
(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))
+ (cl-loop for b in (buffer-list)
+ append (helm-eshell-prompts-list b)))
(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)
+ ;; ("ls" 162 "*eshell*" 3) => ("*eshell*:3:ls" . ("ls" 162 "*eshell*" 3))
+ (cl-loop for (prt pos buf id) in candidates
+ collect `(,(concat
+ (when all
+ (concat (propertize
+ buf
+ 'face 'helm-eshell-prompts-buffer-name)
+ ":"))
+ (when helm-eshell-prompts-promptidx-p
+ (concat (propertize
+ (number-to-string id)
+ 'face 'helm-eshell-prompts-promptidx)
+ ":"))
+ prt)
+ . ,(list prt pos buf id))))
(defun helm-eshell-prompts-all-transformer (candidates)
(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)))
+(cl-defun helm-eshell-prompts-goto (candidate &optional (action 'switch-to-buffer))
+ ;; Candidate format: ("ls" 162 "*eshell*" 3)
+ (let ((buf (nth 2 candidate)))
+ (unless (and (string= (buffer-name) buf)
+ (eq action 'switch-to-buffer))
+ (funcall action buf))
+ (goto-char (nth 1 candidate))
+ (recenter)))
(defun helm-eshell-prompts-goto-other-window (candidate)
- (switch-to-buffer-other-window (cdr candidate))
- (goto-char (car candidate)))
+ (helm-eshell-prompts-goto candidate 'switch-to-buffer-other-window))
(defun helm-eshell-prompts-goto-other-frame (candidate)
- (switch-to-buffer-other-frame (cdr candidate))
- (goto-char (car candidate)))
+ (helm-eshell-prompts-goto candidate 'switch-to-buffer-other-frame))
-(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'.")
+(defun helm-eshell-prompts-other-window ()
+ (interactive)
+ (with-helm-alive-p
+ (helm-exit-and-execute-action 'helm-eshell-prompts-goto-other-window)))
+(put 'helm-eshell-prompts-other-window 'helm-only t)
+
+(defun helm-eshell-prompts-other-frame ()
+ (interactive)
+ (with-helm-alive-p
+ (helm-exit-and-execute-action 'helm-eshell-prompts-goto-other-frame)))
+(put 'helm-eshell-prompts-other-frame 'helm-only t)
;;;###autoload
(defun helm-eshell-prompts ()
@@ -443,7 +472,8 @@ See `helm-eshell-prompts-list'."
("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)))
+ helm-eshell-prompts-goto-other-frame))
+ :keymap helm-eshell-prompts-keymap)
:buffer "*helm Eshell all prompts*"))
(provide 'helm-eshell)