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

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

[elpa] master 4a6eea9 089/173: Use company-dabbrev-char-regexp more cons


From: Dmitry Gutov
Subject: [elpa] master 4a6eea9 089/173: Use company-dabbrev-char-regexp more consistently (#433)
Date: Thu, 23 Jun 2016 00:28:40 +0000 (UTC)

branch: master
commit 4a6eea94edb138a3ea73e7a50553b69dedc5c3ad
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Use company-dabbrev-char-regexp more consistently (#433)
    
    * company-dabbrev--make-regexp: Wrap in parens.
    * company-dabbrev--prefix: New function, using it.
---
 company-dabbrev.el |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/company-dabbrev.el b/company-dabbrev.el
index ab53251..34acffe 100644
--- a/company-dabbrev.el
+++ b/company-dabbrev.el
@@ -93,9 +93,9 @@ This variable affects both `company-dabbrev' and 
`company-dabbrev-code'."
 
 (defun company-dabbrev--make-regexp (prefix)
   (concat "\\<" (if (equal prefix "")
-              company-dabbrev-char-regexp
-            (regexp-quote prefix))
-          "\\(" company-dabbrev-char-regexp "\\)*\\>"))
+                    (concat "\\(?:" company-dabbrev-char-regexp "\\)")
+                  (regexp-quote prefix))
+          "\\(?:" company-dabbrev-char-regexp "\\)*\\>"))
 
 (defun company-dabbrev--search-buffer (regexp pos symbols start limit
                                        ignore-comments)
@@ -143,13 +143,21 @@ This variable affects both `company-dabbrev' and 
`company-dabbrev-code'."
              (cl-return))))
     symbols))
 
+(defun company-dabbrev--prefix ()
+  ;; Not in the middle of a word.
+  (unless (looking-at company-dabbrev-char-regexp)
+    ;; Emacs can't do greedy backward-search.
+    (company-grab-line (format "\\(?:^\\| \\)[^ ]*?\\(\\(?:%s\\)*\\)"
+                               company-dabbrev-char-regexp)
+                       1)))
+
 ;;;###autoload
 (defun company-dabbrev (command &optional arg &rest ignored)
   "dabbrev-like `company-mode' completion backend."
   (interactive (list 'interactive))
   (cl-case command
     (interactive (company-begin-backend 'company-dabbrev))
-    (prefix (company-grab-word))
+    (prefix (company-dabbrev--prefix))
     (candidates
      (let* ((case-fold-search company-dabbrev-ignore-case)
             (words (company-dabbrev--search (company-dabbrev--make-regexp arg)



reply via email to

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