diff options
| author | okamsn <28612288+okamsn@users.noreply.github.com> | 2022-10-22 18:01:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-22 20:01:51 +0200 |
| commit | 75755849f40fd9ed561b0efa1f6cd80890c3a981 (patch) | |
| tree | 933d8980f31d22ef19852a909cdf968a3d971bcb | |
| parent | b98c2ea11da135d9c8982ade5328900451bd24f4 (diff) | |
Fix `cape-history` for Eshell and Comint. (#64)
- Use `comint-input-ring` instead of non-existent `comint-history-ring`.
- Switch from `line-beginning-position` to `eshell-bol` and `comint-bol`
for Eshell and Comint, respectively. Otherwise, the prompt is included
when trying to find matching candidates.
Co-authored-by: okamsn <okamsn@users.noreply.github.com>
| -rw-r--r-- | cape.el | 28 |
1 files changed, 17 insertions, 11 deletions
@@ -208,6 +208,8 @@ VALID is the input comparator, see `cape--input-valid-p'." ;;;;; cape-history (declare-function ring-elements "ring") +(declare-function eshell-bol "eshell") +(declare-function comint-bol "comint") (defvar cape--history-properties (list :company-kind (lambda (_) 'text) @@ -222,20 +224,24 @@ See also `consult-history' for a more flexible variant based on (interactive (list t)) (if interactive (cape--interactive #'cape-history) - (let ((history - (cond - ((derived-mode-p 'eshell-mode) - (bound-and-true-p eshell-history-ring)) - ((derived-mode-p 'comint-mode) - (bound-and-true-p comint-history-ring)) - ((and (minibufferp) (not (eq minibuffer-history-variable t))) - (symbol-value minibuffer-history-variable))))) + (let ((history) + (start-pos)) + (cond + ((derived-mode-p 'eshell-mode) + (setq history (bound-and-true-p eshell-history-ring) + start-pos (save-excursion (eshell-bol) (point)))) + ((derived-mode-p 'comint-mode) + (setq history (bound-and-true-p comint-input-ring) + start-pos (save-excursion (comint-bol) (point)))) + ((and (minibufferp) (not (eq minibuffer-history-variable t))) + (setq history (symbol-value minibuffer-history-variable) + start-pos (line-beginning-position)))) (when (ring-p history) (setq history (ring-elements history))) (when history - `(,(line-beginning-position) ,(point) - ,(cape--table-with-properties history :sort nil) - ,@cape--history-properties))))) + `( ,start-pos ,(point) + ,(cape--table-with-properties history :sort nil) + ,@cape--history-properties))))) ;;;;; cape-file |
