Skip to content

Commit

Permalink
cape-dabbrev-check-other-buffers: Support function customization value
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Apr 6, 2024
1 parent e01e443 commit 28ba1f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- ~cape-capf-super~: If the resulting Capf is non-exclusive, one of the main Capfs
must have returned candidates, in order for the resulting Capf to return
candidates.
- ~cape-dabbrev-check-other-buffers~: Support function as customization value. The
function should return the exact list of buffers to search.

* Version 1.4 (2024-03-08)

Expand Down
35 changes: 21 additions & 14 deletions cape.el
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ auto completion does not pop up too aggressively."
(defcustom cape-dabbrev-check-other-buffers t
"Buffers to check for Dabbrev.
If t, check all other buffers (subject to Dabbrev ignore rules).
If t, check all other buffers, subject to Dabbrev ignore rules.
If a function, only search the buffers returned by this function.
Any other non-nil value only checks some other buffers, as per
`dabbrev-select-buffers-function'."
:type '(choice (const :tag "off" nil)
:type `(choice (const :tag "off" nil)
(const :tag "same-mode buffers" ,#'cape--buffers-major-mode)
(function :tag "function")
(const :tag "some" some)
(other :tag "all" t)))

Expand Down Expand Up @@ -542,8 +545,6 @@ If INTERACTIVE is nil the function acts like a Capf."
:exclusive 'no)
"Completion extra properties for `cape-dabbrev'.")

(defvar dabbrev-check-all-buffers)
(defvar dabbrev-check-other-buffers)
(defvar dabbrev-case-replace)
(defvar dabbrev-case-fold-search)
(defvar dabbrev-abbrev-char-regexp)
Expand All @@ -554,16 +555,22 @@ If INTERACTIVE is nil the function acts like a Capf."
(defun cape--dabbrev-list (input)
"Find all Dabbrev expansions for INPUT."
(cape--silent
(let ((dabbrev-check-other-buffers (not (null cape-dabbrev-check-other-buffers)))
(dabbrev-check-all-buffers (eq cape-dabbrev-check-other-buffers t)))
(dabbrev--reset-global-variables))
(cons
(apply-partially #'string-prefix-p input)
(cl-loop with min-len = (+ cape-dabbrev-min-length (length input))
with ic = (cape--case-fold-p dabbrev-case-fold-search)
for w in (dabbrev--find-all-expansions input ic)
if (>= (length w) min-len) collect
(cape--case-replace (and ic dabbrev-case-replace) input w)))))
(dlet ((dabbrev-check-other-buffers
(and cape-dabbrev-check-other-buffers
(not (functionp cape-dabbrev-check-other-buffers))))
(dabbrev-check-all-buffers
(eq cape-dabbrev-check-other-buffers t))
(dabbrev-search-these-buffers-only
(and (functionp cape-dabbrev-check-other-buffers)
(funcall cape-dabbrev-check-other-buffers))))
(dabbrev--reset-global-variables)
(cons
(apply-partially #'string-prefix-p input)
(cl-loop with min-len = (+ cape-dabbrev-min-length (length input))
with ic = (cape--case-fold-p dabbrev-case-fold-search)
for w in (dabbrev--find-all-expansions input ic)
if (>= (length w) min-len) collect
(cape--case-replace (and ic dabbrev-case-replace) input w))))))

(defun cape--dabbrev-bounds ()
"Return bounds of abbreviation."
Expand Down

0 comments on commit 28ba1f1

Please sign in to comment.