]> code.delx.au - gnu-emacs-elpa/commitdiff
company-elisp--candidates-predicate: Consider bindings without values
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 4 Apr 2013 20:02:43 +0000 (00:02 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 4 Apr 2013 20:02:43 +0000 (00:02 +0400)
* company-elisp-with-buffer: Bind company-elisp-detect-function-context to t.
* Release 0.6.7.

NEWS.md
company-elisp.el
company-tests.el

diff --git a/NEWS.md b/NEWS.md
index b6000b72f787057d76fa76b12089dec7cf07f481..9a8fc7d610c169e4e8fea920bfc05d81df0dd5e8 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,9 @@
 # History of user-visible changes
 
+## 2013-04-01 (0.6.7)
+
+* Two `company-elisp` tweaks.
+
 ## 2013-04-01 (0.6.6)
 
 * `company-elisp` doesn't offer completions when typing the name and the
index 000f30c7f43a9bd48e7b4be8966550e290b61d3d..338acc544e24068ccbaa3b977833df647aff2f5b 100644 (file)
@@ -157,24 +157,29 @@ first in the candidates list."
 
 (defun company-elisp--candidates-predicate (prefix)
   (let* ((completion-ignore-case nil)
-         (before (char-before (- (point) (length prefix)))))
+         (beg (- (point) (length prefix)))
+         (before (char-before beg)))
     (if (and company-elisp-detect-function-context
              (not (memq before '(?' ?`))))
         (if (and (eq before ?\()
                  (not
                   (save-excursion
                     (ignore-errors
-                      (up-list -2)
-                      (and (save-excursion
-                             (forward-char 1)
-                             (looking-at "[ \t\n]*("))
-                           (prog1 (search-backward "(")
-                             (forward-char 1))
-                           (looking-at company-elisp-var-binding-regexp))))))
+                      (goto-char (1- beg))
+                      (or (company-elisp--before-binding-varlist-p)
+                          (progn
+                            (up-list -1)
+                            (company-elisp--before-binding-varlist-p)))))))
             'fboundp
           'boundp)
       'company-elisp--predicate)))
 
+(defun company-elisp--before-binding-varlist-p ()
+  (save-excursion
+    (and (prog1 (search-backward "(")
+           (forward-char 1))
+         (looking-at company-elisp-var-binding-regexp))))
+
 (defun company-elisp--doc (symbol)
   (let* ((symbol (intern symbol))
          (doc (if (fboundp symbol)
index fdc218952d4808a193fdc62169d5479bb45f7c2c..d4ab0b733bd37cb58bb98ceae6eb3c5229ed6c02 100644 (file)
      (setq major-mode 'emacs-lisp-mode)
      (re-search-backward "|")
      (replace-match "")
-     ,@body))
+     (let ((company-elisp-detect-function-context t))
+       ,@body)))
 
 (ert-deftest company-elisp-candidates-predicate ()
   (company-elisp-with-buffer
     "(foo ba|)"
-    (should (eq (let ((company-elisp-detect-function-context t))
-                  (company-elisp--candidates-predicate "ba"))
+    (should (eq (company-elisp--candidates-predicate "ba")
                 'boundp))
     (should (eq (let (company-elisp-detect-function-context)
                   (company-elisp--candidates-predicate "ba"))
                 'company-elisp--predicate)))
   (company-elisp-with-buffer
     "(foo| )"
-    (should (eq (let ((company-elisp-detect-function-context t))
-                  (company-elisp--candidates-predicate "foo"))
+    (should (eq (company-elisp--candidates-predicate "foo")
                 'fboundp))
     (should (eq (let (company-elisp-detect-function-context)
                   (company-elisp--candidates-predicate "foo"))
                 'company-elisp--predicate)))
   (company-elisp-with-buffer
     "(foo 'b|)"
-    (should (eq (let ((company-elisp-detect-function-context t))
-                  (company-elisp--candidates-predicate "b"))
+    (should (eq (company-elisp--candidates-predicate "b")
                 'company-elisp--predicate))))
 
 (ert-deftest company-elisp-candidates-predicate-in-docstring ()
   (company-elisp-with-buffer
    "(def foo () \"Doo be doo `ide|"
    (should (eq 'company-elisp--predicate
-               (let ((company-elisp-detect-function-context t))
-                 (company-elisp--candidates-predicate "ide"))))))
+               (company-elisp--candidates-predicate "ide")))))
 
 ;; This one's also an integration test.
 (ert-deftest company-elisp-candidates-recognizes-binding-form ()
       (should (equal '("when")
                      (company-elisp-candidates "wh"))))))
 
+(ert-deftest company-elisp-candidates-predicate-binding-without-value ()
+  (loop for (text prefix predicate) in '(("(let (foo|" "foo" boundp)
+                                         ("(let (foo (bar|" "bar" boundp)
+                                         ("(let (foo) (bar|" "bar" fboundp))
+        do
+        (eval `(company-elisp-with-buffer
+                 ,text
+                 (should (eq ',predicate
+                             (company-elisp--candidates-predicate ,prefix)))))))
+
 (ert-deftest company-elisp-finds-vars ()
   (let ((obarray [boo bar baz backquote])
         (boo t)