]> code.delx.au - gnu-emacs-elpa/commitdiff
Allow company-dabbrev-ignore-buffers to be a function
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 29 Apr 2016 20:39:08 +0000 (23:39 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 29 Apr 2016 20:39:08 +0000 (23:39 +0300)
Closes #504

NEWS.md
company-dabbrev.el

diff --git a/NEWS.md b/NEWS.md
index 841a62be34a29071fe387a89bf7f10cbf63c5b64..6612ca28e38f87d982413538e54411dacb09e3e1 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* The value of `company-dabbrev-ignore-buffers` can also be a function.
 * `company-files` has been moved to right after `company-capf` in
   `company-backends`
   ([#463](https://github.com/company-mode/company-mode/issues/463)).
index 3a533d5b6c70f47b6a30412f90bc683f875ed70e..1ece897871567555c43659b5c7c465bbf908fa44 100644 (file)
@@ -41,8 +41,10 @@ buffers with the same major mode.  See also `company-dabbrev-time-limit'."
                  (const :tag "All" all)))
 
 (defcustom company-dabbrev-ignore-buffers "\\`[ *]"
-  "Regexp matching the names of buffers to ignore."
-  :type 'regexp)
+  "Regexp matching the names of buffers to ignore.
+Or a function that returns non-nil for such buffers."
+  :type '(choice (regexp :tag "Regexp")
+                 (function :tag "Predicate")))
 
 (defcustom company-dabbrev-time-limit .1
   "Determines how many seconds `company-dabbrev' should look for matches."
@@ -137,14 +139,16 @@ This variable affects both `company-dabbrev' and `company-dabbrev-code'."
                                                   ignore-comments)))
     (when other-buffer-modes
       (cl-dolist (buffer (delq (current-buffer) (buffer-list)))
-        (with-current-buffer buffer
-          (when (if (eq other-buffer-modes 'all)
-                    (not (string-match-p company-dabbrev-ignore-buffers
-                                         (buffer-name)))
-                  (apply #'derived-mode-p other-buffer-modes))
-            (setq symbols
-                  (company-dabbrev--search-buffer regexp nil symbols start
-                                                  limit ignore-comments))))
+        (unless (if (stringp company-dabbrev-ignore-buffers)
+                    (string-match-p company-dabbrev-ignore-buffers
+                                    (buffer-name buffer))
+                  (funcall company-dabbrev-ignore-buffers buffer))
+          (with-current-buffer buffer
+            (when (or (eq other-buffer-modes 'all)
+                      (apply #'derived-mode-p other-buffer-modes))
+              (setq symbols
+                    (company-dabbrev--search-buffer regexp nil symbols start
+                                                    limit ignore-comments)))))
         (and limit
              (> (float-time (time-since start)) limit)
              (cl-return))))