[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/capf-autosuggest 8507236 20/63: Generalize capf-autosug
From: |
ELPA Syncer |
Subject: |
[elpa] externals/capf-autosuggest 8507236 20/63: Generalize capf-autosuggest-capf-functions |
Date: |
Wed, 27 Oct 2021 14:57:56 -0400 (EDT) |
branch: externals/capf-autosuggest
commit 8507236eab1a57969fa28a9858a7ade5e6de0eff
Author: jakanakaevangeli <jakanakaevangeli@chiru.no>
Commit: jakanakaevangeli <jakanakaevangeli@chiru.no>
Generalize capf-autosuggest-capf-functions
Also, by default, only consider auto-suggestions if at eol.
---
capf-autosuggest.el | 32 +++++++++++++++++++++++---------
history-capf.el | 6 +++---
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/capf-autosuggest.el b/capf-autosuggest.el
index 4a2c275..a61d976 100644
--- a/capf-autosuggest.el
+++ b/capf-autosuggest.el
@@ -39,11 +39,12 @@
"Face used for auto suggestions."
:group 'completion)
-(defvar-local capf-autosuggest-capf nil
+(defvar capf-autosuggest-capf-functions '(capf-autosuggest-orig-if-at-eol-capf)
"`completion-at-point-functions', used by capf-autossugest.
-If nil, capf-autosuggest will use
-`completion-at-point-functions', otherwise it will use this hook
-variable.")
+It is used instead of the standard
+`completion-at-point-functions', but the default value contains
+`capf-autosuggest-orig-if-at-eol-capf' which searches the
+standard capf functions, if point is at the end of line.")
(defvar capf-autosuggest-all-completions-only-one nil
"Non-nil if only the first result of `all-completions' is of interest.
@@ -58,6 +59,22 @@ hint to only return a list of one element for optimization.")
(defvar capf-autosuggest-active-mode)
+(defun capf-autosuggest-orig-capf (&optional capf-functions)
+ "A capf that chooses from hook variable CAPF-FUNCTIONS.
+CAPF-FUNCTIONS defaults to `completion-at-point-functions'.
+Don't add this function to `completion-at-point-functions', as
+this will result in an infinite loop. Useful for adding to
+`capf-autosuggest-capf-functions', making it search the standard
+capf functions."
+ (cdr (run-hook-wrapped (or capf-functions 'completion-at-point-functions)
+ #'completion--capf-wrapper 'all)))
+
+(defun capf-autosuggest-orig-if-at-eol-capf ()
+ "`capf-autosuggest-orig-capf' if at the end of buffer.
+Otherwise, return nil."
+ (when (eolp)
+ (capf-autosuggest-orig-capf)))
+
(defun capf-autosuggest--post-h ()
"Create an auto-suggest overlay."
(if completion-in-region-mode
@@ -69,11 +86,8 @@ hint to only return a list of one element for optimization.")
(capf-autosuggest-active-mode -1))))
(unless capf-autosuggest-active-mode
- (pcase (run-hook-wrapped (if capf-autosuggest-capf
- 'capf-autosuggest-capf
- 'completion-at-point-functions)
- #'completion--capf-wrapper 'all)
- (`(,_fun ,beg ,end ,table . ,plist)
+ (pcase (capf-autosuggest-orig-capf 'capf-autosuggest-capf-functions)
+ (`(,beg ,end ,table . ,plist)
(let* ((pred (plist-get plist :predicate))
(string (buffer-substring-no-properties beg end))
;; See `completion-emacs21-all-completions'
diff --git a/history-capf.el b/history-capf.el
index df4a71b..f86a299 100644
--- a/history-capf.el
+++ b/history-capf.el
@@ -36,7 +36,7 @@
(defvar comint-use-prompt-regexp)
(defvar eshell-history-ring)
(defvar eshell-last-output-end)
-(declare-function capf-autosuggest-mode "capf-autosuggest")
+(autoload 'capf-autosuggest-mode "capf-autosuggest")
(declare-function eshell-bol "esh-mode")
(declare-function comint-previous-matching-input-from-input "comint")
(declare-function eshell-previous-matching-input-from-input "em-hist")
@@ -111,13 +111,13 @@ Is only applicable if point is after the last prompt."
(defun history-capf-setup-autosuggest-comint ()
"Setup capf-autosuggest for history suggestion in comint."
(capf-autosuggest-mode)
- (add-hook 'capf-autosuggest-capf #'history-capf-comint))
+ (add-hook 'capf-autosuggest-capf-functions #'history-capf-comint nil t))
;;;###autoload
(defun history-capf-setup-autosuggest-eshell ()
"Setup capf-autosuggest for history suggestion in eshell."
(capf-autosuggest-mode)
- (add-hook 'capf-autosuggest-capf #'history-capf-eshell))
+ (add-hook 'capf-autosuggest-capf-functions #'history-capf-eshell nil t))
(with-eval-after-load 'capf-autosuggest
(define-key capf-autosuggest-active-mode-map
- [elpa] branch externals/capf-autosuggest created (now 2821a6a), ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 531b04c 07/63: Take completion boundaries/base into account, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest dd21f4b 08/63: Fix capf-autosuggest-accept, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest cad5308 01/63: Initial commit, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 3fd798f 12/63: Make capf-autosuggest-capf nil by default, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 3c346b7 13/63: Added history-capf.el, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest c6a38f3 17/63: Sentence end double space, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 0ef9e94 16/63: Add documentation to capf functions, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 03004ef 18/63: Begin commentary to capf-autosuggest, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 8507236 20/63: Generalize capf-autosuggest-capf-functions,
ELPA Syncer <=
- [elpa] externals/capf-autosuggest d53b499 24/63: insert -> insert-and-inherit, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 2163c64 27/63: after-change-functions -> buffer-modified-tick, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 5455064 22/63: Allow forward-sexp to enter overlay, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest b836fcc 33/63: Prevent misbehaving capf functions from modifying buffer, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest abd71ab 29/63: Don't leak overlays when killing all local variables, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 8f091ce 26/63: Extend description, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 024d438 28/63: Don't exclude completion-in-region-mode, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 40336d0 38/63: Adjust short description, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest 76b643a 34/63: Doc fixes and additions, ELPA Syncer, 2021/10/27
- [elpa] externals/capf-autosuggest b16a9d8 36/63: Silence compiler warnings, ELPA Syncer, 2021/10/27