summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2022-03-27 20:29:22 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2022-03-27 20:29:22 +0200
commit25591ef5a2bd0acefb2ca82a610c24909ae7a2ba (patch)
tree0761f103f4a2eb92954b6f3eb4be5c4fe3ce0ebd
parent6c02a8ed24d0f4a8b0200d0846c53340654afb9c (diff)
Add cape-capf-prefix-length (Fix #33)
-rw-r--r--README.org1
-rw-r--r--cape.el16
2 files changed, 15 insertions, 2 deletions
diff --git a/README.org b/README.org
index 6c50dd1..15383d7 100644
--- a/README.org
+++ b/README.org
@@ -222,6 +222,7 @@ achieve a similarly refreshing strategy.
- ~cape-wrap-case-fold~, ~cape-capf-case-fold~: Create a Capf which is case insensitive.
- ~cape-wrap-properties~, ~cape-capf-properties~: Add completion properties to a Capf.
- ~cape-wrap-predicate~, ~cape-capf-predicate~: Add candidate predicate to a Capf.
+- ~cape-wrap-prefix-length~, ~cape-capf-prefix-length~: Enforce a minimal prefix length.
* Contributions
diff --git a/cape.el b/cape.el
index a016b62..2946580 100644
--- a/cape.el
+++ b/cape.el
@@ -74,8 +74,8 @@ If t, check all other buffers (subject to dabbrev ignore rules).
Any other non-nil value only checks some other buffers, as per
`dabbrev-select-buffers-function'."
:type '(choice (const :tag "off" nil)
- (const :tag "some" 'some)
- (other :tag "all" t)))
+ (const :tag "some" 'some)
+ (other :tag "all" t)))
(defcustom cape-file-directory-must-exist t
"The parent directory must exist for file completion."
@@ -1067,6 +1067,17 @@ If DONT-FOLD is non-nil return a case sensitive table instead."
`(,beg ,end ,(cape--noninterruptible-table table) ,@plist))))
;;;###autoload
+(defun cape-wrap-prefix-length (capf length)
+ "Call CAPF and ensure that prefix length is greater or equal than LENGTH.
+If the prefix is long enough, enforce auto completion."
+ (pcase (funcall capf)
+ (`(,beg ,end ,table . ,plist)
+ (when (>= (- end beg) length)
+ `(,beg ,end ,table
+ :company-prefix-length t
+ ,@plist)))))
+
+;;;###autoload
(defun cape-wrap-purify (capf)
"Call CAPF and ensure that it does not modify the buffer."
;; bug#50470: Fix Capfs which illegally modify the buffer or which
@@ -1102,6 +1113,7 @@ If DONT-FOLD is non-nil return a case sensitive table instead."
(cape--capf-wrapper properties)
(cape--capf-wrapper buster)
(cape--capf-wrapper purify)
+(cape--capf-wrapper prefix-length)
(provide 'cape)
;;; cape.el ends here