emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/cape e503d9a6f8 1/3: cape-dabbrev: Respect dabbrev-abbr


From: ELPA Syncer
Subject: [elpa] externals/cape e503d9a6f8 1/3: cape-dabbrev: Respect dabbrev-abbrev-char-regexp
Date: Mon, 29 May 2023 06:57:41 -0400 (EDT)

branch: externals/cape
commit e503d9a6f86b05962fe4b638f49d8d0110891570
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    cape-dabbrev: Respect dabbrev-abbrev-char-regexp
---
 cape-char.el |  2 ++
 cape.el      | 43 ++++++++++++++++++++++++++++++-------------
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/cape-char.el b/cape-char.el
index 09b17097ac..b7eb3675b2 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.
diff --git a/cape.el b/cape.el
index 0183608638..ddb5808de8 100644
--- a/cape.el
+++ b/cape.el
@@ -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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]