From bcae310be39553776055e0d8bc6289555f6ed736 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Fri, 29 Mar 2013 12:08:43 +0400 Subject: [PATCH] company-elisp-locals: Skip current varlist --- company-elisp.el | 47 +++++++++++++++++++++++------------------------ company-tests.el | 6 ++++++ 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/company-elisp.el b/company-elisp.el index 42e3fef84..52126bd43 100644 --- a/company-elisp.el +++ b/company-elisp.el @@ -80,30 +80,29 @@ Functions are offered for completion only after ' and \(." (save-excursion (when (eq (char-after) ?\() (forward-char 1) - (skip-chars-forward " \t\n") - (cond - ((looking-at (if functions-p - company-elisp-fun-binding-regexp - company-elisp-var-binding-regexp)) - (down-list 1) - (condition-case nil - (dotimes (i company-elisp-parse-limit) - (save-excursion - (when (looking-at "[ \t\n]*(") - (down-list 1)) - (and (looking-at regexp) - ;; Don't add incomplete text as candidate. - (not (eq (match-end 0) pos)) - (pushnew (match-string-no-properties 1) res))) - (forward-sexp)) - (scan-error nil))) - ((unless functions-p - (looking-at company-elisp-var-binding-regexp-1)) - (down-list 1) - (and (looking-at regexp) - ;; Don't add incomplete text as candidate. - (not (eq (match-end 0) pos)) - (pushnew (match-string-no-properties 1) res)))))))) + (when (ignore-errors + (save-excursion (forward-list) + (<= (point) pos))) + (skip-chars-forward " \t\n") + (cond + ((looking-at (if functions-p + company-elisp-fun-binding-regexp + company-elisp-var-binding-regexp)) + (down-list 1) + (condition-case nil + (dotimes (i company-elisp-parse-limit) + (save-excursion + (when (looking-at "[ \t\n]*(") + (down-list 1)) + (when (looking-at regexp) + (pushnew (match-string-no-properties 1) res))) + (forward-sexp)) + (scan-error nil))) + ((unless functions-p + (looking-at company-elisp-var-binding-regexp-1)) + (down-list 1) + (when (looking-at regexp) + (pushnew (match-string-no-properties 1) res))))))))) (scan-error nil)) res)) diff --git a/company-tests.el b/company-tests.el index 77ccee7e7..c9e52cbdc 100644 --- a/company-tests.el +++ b/company-tests.el @@ -300,3 +300,9 @@ (f| )))" (should (equal '("fee" "foo") (sort (company-elisp-locals "f" t) 'string<))))) + +(ert-deftest company-elisp-locals-skips-current-varlist () + (company-elisp-with-buffer + "(let ((foo 1) + (f| )))" + (should (null (company-elisp-locals "f" nil))))) -- 2.39.2