From: Dmitry Gutov Date: Sun, 3 May 2015 20:57:38 +0000 (+0300) Subject: elisp-completion-at-point: Prioritize being quoted over funpos X-Git-Tag: emacs-25.0.90~2226 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ac5586a1037bae49738607d19fd008cd93f49ae2;p=emacs.git elisp-completion-at-point: Prioritize being quoted over funpos * lisp/progmodes/elisp-mode.el (elisp-completion-at-point): Only consider function position when not inside quoted form (bug#20425). * test/automated/elisp-mode-tests.el: New file. --- diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 2bb661a59c8..7c9a2d7c422 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -475,11 +475,12 @@ It can be quoted, or be inside a quoted form." (point))) (scan-error pos)))) ;; t if in function position. - (funpos (eq (char-before beg) ?\())) + (funpos (eq (char-before beg) ?\()) + (quoted (elisp--form-quoted-p beg))) (when (and end (or (not (nth 8 (syntax-ppss))) (eq (char-before beg) ?`))) (let ((table-etc - (if (not funpos) + (if (or (not funpos) quoted) ;; FIXME: We could look at the first element of the list and ;; use it to provide a more specific completion table in some ;; cases. E.g. filter out keywords that are not understood by @@ -491,7 +492,7 @@ It can be quoted, or be inside a quoted form." :company-doc-buffer #'elisp--company-doc-buffer :company-docsig #'elisp--company-doc-string :company-location #'elisp--company-location)) - ((elisp--form-quoted-p beg) + (quoted (list nil obarray ;; Don't include all symbols (bug#16646). :predicate (lambda (sym) diff --git a/test/automated/elisp-mode-tests.el b/test/automated/elisp-mode-tests.el new file mode 100644 index 00000000000..a4148e9e5ff --- /dev/null +++ b/test/automated/elisp-mode-tests.el @@ -0,0 +1,88 @@ +;;; elisp-mode-tests.el --- Tests for emacs-lisp-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2015 Free Software Foundation, Inc. + +;; Author: Dmitry Gutov + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) + +(defun elisp--test-completions () + (let ((data (elisp-completion-at-point))) + (all-completions (buffer-substring (nth 0 data) (nth 1 data)) + (nth 2 data) + (plist-get (nthcdr 3 data) :predicate)))) + +(ert-deftest elisp-completes-functions () + (with-temp-buffer + (emacs-lisp-mode) + (insert "(ba") + (let ((comps (elisp--test-completions))) + (should (member "backup-buffer" comps)) + (should-not (member "backup-inhibited" comps))))) + +(ert-deftest elisp-completes-variables () + (with-temp-buffer + (emacs-lisp-mode) + (insert "(foo ba") + (let ((comps (elisp--test-completions))) + (should (member "backup-inhibited" comps)) + (should-not (member "backup-buffer" comps))))) + +(ert-deftest elisp-completes-anything-quoted () + (dolist (text '("`(foo ba" "(foo 'ba" + "`(,foo ba" "`,(foo `ba" + "'(foo (ba")) + (with-temp-buffer + (emacs-lisp-mode) + (insert text) + (let ((comps (elisp--test-completions))) + (should (member "backup-inhibited" comps)) + (should (member "backup-buffer" comps)) + (should (member "backup" comps)))))) + +(ert-deftest elisp-completes-variables-unquoted () + (dolist (text '("`(foo ,ba" "`(,(foo ba" "`(,ba")) + (with-temp-buffer + (emacs-lisp-mode) + (insert text) + (let ((comps (elisp--test-completions))) + (should (member "backup-inhibited" comps)) + (should-not (member "backup-buffer" comps)))))) + +(ert-deftest elisp-completes-functions-in-special-macros () + (dolist (text '("(declare-function ba" "(cl-callf2 ba")) + (with-temp-buffer + (emacs-lisp-mode) + (insert text) + (let ((comps (elisp--test-completions))) + (should (member "backup-buffer" comps)) + (should-not (member "backup-inhibited" comps)))))) + +(ert-deftest elisp-completes-local-variables () + (with-temp-buffer + (emacs-lisp-mode) + (insert "(let ((bar 1) baz) (foo ba") + (let ((comps (elisp--test-completions))) + (should (member "backup-inhibited" comps)) + (should (member "bar" comps)) + (should (member "baz" comps))))) + +(provide 'elisp-mode-tests) +;;; elisp-mode-tests.el ends here