summaryrefslogtreecommitdiff
path: root/helm-eshell.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2014-12-12 07:58:49 +0100
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2014-12-12 07:58:49 +0100
commitaa504dda60a348ae64229ff6d9e6d4dbdb913617 (patch)
treefc86685c27abfa0f83f928e160920a28d2c06d0c /helm-eshell.el
parentf058bf40ff55c96810f4f110c23f619ec361d2d8 (diff)
Sort candidates at end of loop (#748).
* helm-eshell.el: Use classes for completion and history.
Diffstat (limited to 'helm-eshell.el')
-rw-r--r--helm-eshell.el92
1 files changed, 47 insertions, 45 deletions
diff --git a/helm-eshell.el b/helm-eshell.el
index 12106583..ef265587 100644
--- a/helm-eshell.el
+++ b/helm-eshell.el
@@ -47,28 +47,31 @@
map)
"Keymap for `helm-esh-pcomplete'.")
-(defvar helm-source-esh
- '((name . "Eshell completions")
- (init . (lambda ()
- (setq pcomplete-current-completions nil
- pcomplete-last-completion-raw nil)
- ;; Eshell-command add this hook in all minibuffers
- ;; Remove it for the helm one. (Fixed in Emacs24)
- (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
- (candidates . helm-esh-get-candidates)
- (nomark)
- (persistent-action . ignore)
- (filtered-candidate-transformer
- (lambda (candidates _sources)
- (cl-loop for i in (sort candidates 'helm-generic-sort-fn)
- collect
- (cond ((string-match "\\`~/?" helm-ec-target)
- (abbreviate-file-name i))
- ((string-match "\\`/" helm-ec-target) i)
- (t
- (file-relative-name i))))))
- (action . helm-ec-insert))
- "Helm source for Eshell completion.")
+(defclass helm-esh-source (helm-source-sync)
+ ((init :initform (lambda ()
+ (setq pcomplete-current-completions nil
+ pcomplete-last-completion-raw nil)
+ ;; Eshell-command add this hook in all minibuffers
+ ;; Remove it for the helm one. (Fixed in Emacs24)
+ (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
+ (candidates :initform 'helm-esh-get-candidates)
+ (nomark :initform t)
+ (persistent-action :initform 'ignore)
+ (filtered-candidate-transformer
+ :initform
+ (lambda (candidates _sources)
+ (cl-loop
+ for i in candidates
+ collect
+ (cond ((string-match "\\`~/?" helm-ec-target)
+ (abbreviate-file-name i))
+ ((string-match "\\`/" helm-ec-target) i)
+ (t
+ (file-relative-name i)))
+ into lst
+ finally return (sort lst 'helm-generic-sort-fn))))
+ (action :initform 'helm-ec-insert))
+ "Helm class to define source for Eshell completion.")
;; Internal.
(defvar helm-ec-target "")
@@ -145,25 +148,23 @@ The function that call this should set `helm-ec-target' to thing at point."
;;; Eshell history.
;;
;;
-(defvar helm-source-eshell-history
- `((name . "Eshell history")
- (init . (lambda ()
- (let (eshell-hist-ignoredups)
- (eshell-write-history eshell-history-file-name t)
- (with-current-buffer (helm-candidate-buffer 'global)
- (insert-file-contents eshell-history-file-name)))
- ;; Same comment as in `helm-source-esh'
- (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
- (candidates-in-buffer)
- (nomark)
- (keymap . ,helm-eshell-history-map)
- (filtered-candidate-transformer . (lambda (candidates sources)
- (reverse candidates)))
- (candidate-number-limit . 9999)
- (action . (lambda (candidate)
- (eshell-kill-input)
- (insert candidate))))
- "Helm source for Eshell history.")
+(defclass helm-eshell-history-source (helm-source-in-buffer)
+ ((init :initform (lambda ()
+ (let (eshell-hist-ignoredups)
+ (eshell-write-history eshell-history-file-name t)
+ (with-current-buffer (helm-candidate-buffer 'global)
+ (insert-file-contents eshell-history-file-name)))
+ ;; Same comment as in `helm-source-esh'
+ (remove-hook 'minibuffer-setup-hook 'eshell-mode)))
+ (nomark :initform t)
+ (keymap :initform helm-eshell-history-map)
+ (filtered-candidate-transformer :initform (lambda (candidates sources)
+ (reverse candidates)))
+ (candidate-number-limit :initform 9999)
+ (action :initform (lambda (candidate)
+ (eshell-kill-input)
+ (insert candidate))))
+ "Helm class to define source for Eshell history.")
;;;###autoload
(defun helm-esh-pcomplete ()
@@ -199,7 +200,7 @@ The function that call this should set `helm-ec-target' to thing at point."
(car (last (ignore-errors
(pcomplete-parse-arguments))))))
(with-helm-show-completion beg end
- (helm :sources 'helm-source-esh
+ (helm :sources (helm-make-source "Eshell completions" 'helm-esh-source)
:buffer "*helm pcomplete*"
:keymap helm-esh-completion-map
:resume 'noresume
@@ -210,8 +211,8 @@ The function that call this should set `helm-ec-target' to thing at point."
(defun helm-eshell-history ()
"Preconfigured helm for eshell history."
(interactive)
- (let* ((end (point))
- (beg (save-excursion (eshell-bol) (point)))
+ (let* ((end (point))
+ (beg (save-excursion (eshell-bol) (point)))
(input (buffer-substring beg end))
flag-empty)
(when (eq beg end)
@@ -220,7 +221,8 @@ The function that call this should set `helm-ec-target' to thing at point."
(setq end (point)))
(unwind-protect
(with-helm-show-completion beg end
- (helm :sources 'helm-source-eshell-history
+ (helm :sources (helm-make-source "Eshell history"
+ helm-eshell-history-source)
:buffer "*helm eshell history*"
:resume 'noresume
:input input))