diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-05-29 10:40:48 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-05-29 10:41:01 +0200 |
| commit | e503d9a6f86b05962fe4b638f49d8d0110891570 (patch) | |
| tree | 3759023f81d69aa985c4c59db8f27111c37956b1 | |
| parent | db3059af52718c7f55485ef183bdad3e40f58df9 (diff) | |
cape-dabbrev: Respect dabbrev-abbrev-char-regexp
| -rw-r--r-- | cape-char.el | 2 | ||||
| -rw-r--r-- | cape.el | 43 |
2 files changed, 32 insertions, 13 deletions
diff --git a/cape-char.el b/cape-char.el index 09b1709..b7eb367 100644 --- a/cape-char.el +++ b/cape-char.el @@ -26,6 +26,8 @@ (require 'cape) +(autoload 'thing-at-point-looking-at "thingatpt") + ;; Declare as pure function which is evaluated at compile time. We don't use a ;; macro for this computation since packages like `helpful' will ;; `macroexpand-all' the expensive `cape-char--define' macro calls. @@ -50,8 +50,6 @@ (require 'cl-lib) (require 'subr-x)) -(autoload 'thing-at-point-looking-at "thingatpt") - ;;;; Customization (defgroup cape nil @@ -429,6 +427,8 @@ If INTERACTIVE is nil the function acts like a Capf." (defvar dabbrev-check-other-buffers) (defvar dabbrev-case-replace) (defvar dabbrev-case-fold-search) +(defvar dabbrev-abbrev-char-regexp) +(defvar dabbrev-abbrev-skip-leading-regexp) (declare-function dabbrev--find-all-expansions "dabbrev") (declare-function dabbrev--reset-global-variables "dabbrev") @@ -444,6 +444,25 @@ If INTERACTIVE is nil the function acts like a Capf." if (>= (length w) min-len) collect (cape--case-replace (and ic dabbrev-case-replace) input w)))) +(defun cape--dabbrev-bounds () + "Return bounds of abbreviation." + (unless (boundp 'dabbrev-abbrev-char-regexp) + (require 'dabbrev)) + (let ((re (or dabbrev-abbrev-char-regexp "\\sw\\|\\s_"))) + (when (or (looking-at re) + (save-excursion (forward-char -1) (looking-at re))) + (cons (save-excursion + (while (save-excursion (forward-char -1) (looking-at re)) + (forward-char -1)) + (when dabbrev-abbrev-skip-leading-regexp + (while (looking-at dabbrev-abbrev-skip-leading-regexp) + (forward-char 1))) + (point)) + (save-excursion + (while (looking-at re) + (forward-char 1)) + (point)))))) + ;;;###autoload (defun cape-dabbrev (&optional interactive) "Complete with Dabbrev at point. @@ -457,17 +476,15 @@ See the user options `cape-dabbrev-min-length' and (if interactive (let ((cape-dabbrev-min-length 0)) (cape-interactive #'cape-dabbrev)) - (when (thing-at-point-looking-at "\\(?:\\sw\\|\\s_\\)+") - (require 'dabbrev) - (let ((beg (match-beginning 0)) - (end (match-end 0))) - `(,beg ,end - ,(cape--table-with-properties - (completion-table-case-fold - (cape--cached-table beg end #'cape--dabbrev-list #'string-prefix-p) - (not (cape--case-fold-p dabbrev-case-fold-search))) - :category 'cape-dabbrev) - ,@cape--dabbrev-properties))))) + (when-let ((bounds (cape--dabbrev-bounds))) + `(,(car bounds) ,(cdr bounds) + ,(cape--table-with-properties + (completion-table-case-fold + (cape--cached-table (car bounds) (cdr bounds) + #'cape--dabbrev-list #'string-prefix-p) + (not (cape--case-fold-p dabbrev-case-fold-search))) + :category 'cape-dabbrev) + ,@cape--dabbrev-properties)))) ;;;;; cape-dict |
