Eshell: Add company-eshell-autosuggest to selected packages
parent
8caf0dbc7a
commit
a42915f37f
|
@ -127,6 +127,7 @@
|
|||
;;; Extend completion.
|
||||
(nconc package-selected-packages '(fish-completion bash-completion
|
||||
pcomplete-extension pcmpl-args pcmpl-git))
|
||||
(nconc package-selected-packages '(company-eshell-autosuggest))
|
||||
(when (and (executable-find "fish")
|
||||
(require 'fish-completion nil t))
|
||||
(global-fish-completion-mode))
|
||||
|
|
|
@ -232,7 +232,11 @@ See `eshell' for the numeric prefix ARG."
|
|||
(eshell (or arg t))))))
|
||||
|
||||
;;; Auto-suggestion
|
||||
(when (require 'package-eshell-autosuggest)
|
||||
(when (require 'company-eshell-autosuggest nil t)
|
||||
(defun eshell-setup-autosuggest ()
|
||||
(setq-local company-idle-delay 0.5)
|
||||
(setq-local company-backends '(company-eshell-autosuggest))
|
||||
(setq-local company-frontends '(company-preview-frontend)))
|
||||
(add-hook 'eshell-mode-hook 'company-mode)
|
||||
(when (require 'helm-config nil t)
|
||||
(define-key company-active-map (kbd "M-p") 'helm-eshell-history))
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
;;; REVIEW: Delete this once on MELPA.
|
||||
;;; See https://github.com/melpa/melpa/pull/5094.
|
||||
(require 'company)
|
||||
|
||||
(defun company-eshell-autosuggest-candidates (prefix)
|
||||
(let* ((history
|
||||
(cl-remove-duplicates
|
||||
(mapcar (lambda (str)
|
||||
(string-trim (substring-no-properties str)))
|
||||
(ring-elements eshell-history-ring))
|
||||
:from-end t
|
||||
:test #'string=))
|
||||
(most-similar (cl-find-if
|
||||
(lambda (str)
|
||||
(string-prefix-p prefix str))
|
||||
history)))
|
||||
(when most-similar
|
||||
`(,most-similar))))
|
||||
|
||||
(defun company-eshell-autosuggest--prefix ()
|
||||
(let ((prefix
|
||||
(string-trim-left
|
||||
(buffer-substring-no-properties
|
||||
(save-excursion
|
||||
(eshell-bol))
|
||||
(save-excursion (end-of-line) (point))))))
|
||||
(if (not (string-empty-p prefix))
|
||||
prefix
|
||||
'stop)))
|
||||
|
||||
(defun company-eshell-autosuggest (command &optional arg &rest ignored)
|
||||
(interactive (list 'interactive))
|
||||
(cl-case command
|
||||
(interactive (company-begin-backend 'company-eshell))
|
||||
(prefix (and (eq major-mode 'eshell-mode)
|
||||
(company-eshell-autosuggest--prefix)))
|
||||
(candidates (company-eshell-autosuggest-candidates arg))))
|
||||
|
||||
(defun eshell-setup-autosuggest ()
|
||||
(setq-local company-idle-delay 0.5)
|
||||
(setq-local company-backends '(company-eshell-autosuggest))
|
||||
(setq-local company-frontends '(company-preview-frontend)))
|
||||
|
||||
(provide 'package-eshell-autosuggest)
|
Loading…
Reference in New Issue