(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)
(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)