aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2015-05-03 23:57:38 +0300
committerDmitry Gutov2015-05-03 23:57:38 +0300
commitac5586a1037bae49738607d19fd008cd93f49ae2 (patch)
treefc8ef96d6faafdbf79749f46bd7f2fc06455ffd5
parent2703629711f29f6a46e2766c10df5df5863d2ab9 (diff)
downloademacs-ac5586a1037bae49738607d19fd008cd93f49ae2.tar.gz
emacs-ac5586a1037bae49738607d19fd008cd93f49ae2.zip
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.
-rw-r--r--lisp/progmodes/elisp-mode.el7
-rw-r--r--test/automated/elisp-mode-tests.el88
2 files changed, 92 insertions, 3 deletions
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."
475 (point))) 475 (point)))
476 (scan-error pos)))) 476 (scan-error pos))))
477 ;; t if in function position. 477 ;; t if in function position.
478 (funpos (eq (char-before beg) ?\())) 478 (funpos (eq (char-before beg) ?\())
479 (quoted (elisp--form-quoted-p beg)))
479 (when (and end (or (not (nth 8 (syntax-ppss))) 480 (when (and end (or (not (nth 8 (syntax-ppss)))
480 (eq (char-before beg) ?`))) 481 (eq (char-before beg) ?`)))
481 (let ((table-etc 482 (let ((table-etc
482 (if (not funpos) 483 (if (or (not funpos) quoted)
483 ;; FIXME: We could look at the first element of the list and 484 ;; FIXME: We could look at the first element of the list and
484 ;; use it to provide a more specific completion table in some 485 ;; use it to provide a more specific completion table in some
485 ;; cases. E.g. filter out keywords that are not understood by 486 ;; 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."
491 :company-doc-buffer #'elisp--company-doc-buffer 492 :company-doc-buffer #'elisp--company-doc-buffer
492 :company-docsig #'elisp--company-doc-string 493 :company-docsig #'elisp--company-doc-string
493 :company-location #'elisp--company-location)) 494 :company-location #'elisp--company-location))
494 ((elisp--form-quoted-p beg) 495 (quoted
495 (list nil obarray 496 (list nil obarray
496 ;; Don't include all symbols (bug#16646). 497 ;; Don't include all symbols (bug#16646).
497 :predicate (lambda (sym) 498 :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 @@
1;;; elisp-mode-tests.el --- Tests for emacs-lisp-mode -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5;; Author: Dmitry Gutov <dgutov@yandex.ru>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22;;; Code:
23
24(require 'ert)
25
26(defun elisp--test-completions ()
27 (let ((data (elisp-completion-at-point)))
28 (all-completions (buffer-substring (nth 0 data) (nth 1 data))
29 (nth 2 data)
30 (plist-get (nthcdr 3 data) :predicate))))
31
32(ert-deftest elisp-completes-functions ()
33 (with-temp-buffer
34 (emacs-lisp-mode)
35 (insert "(ba")
36 (let ((comps (elisp--test-completions)))
37 (should (member "backup-buffer" comps))
38 (should-not (member "backup-inhibited" comps)))))
39
40(ert-deftest elisp-completes-variables ()
41 (with-temp-buffer
42 (emacs-lisp-mode)
43 (insert "(foo ba")
44 (let ((comps (elisp--test-completions)))
45 (should (member "backup-inhibited" comps))
46 (should-not (member "backup-buffer" comps)))))
47
48(ert-deftest elisp-completes-anything-quoted ()
49 (dolist (text '("`(foo ba" "(foo 'ba"
50 "`(,foo ba" "`,(foo `ba"
51 "'(foo (ba"))
52 (with-temp-buffer
53 (emacs-lisp-mode)
54 (insert text)
55 (let ((comps (elisp--test-completions)))
56 (should (member "backup-inhibited" comps))
57 (should (member "backup-buffer" comps))
58 (should (member "backup" comps))))))
59
60(ert-deftest elisp-completes-variables-unquoted ()
61 (dolist (text '("`(foo ,ba" "`(,(foo ba" "`(,ba"))
62 (with-temp-buffer
63 (emacs-lisp-mode)
64 (insert text)
65 (let ((comps (elisp--test-completions)))
66 (should (member "backup-inhibited" comps))
67 (should-not (member "backup-buffer" comps))))))
68
69(ert-deftest elisp-completes-functions-in-special-macros ()
70 (dolist (text '("(declare-function ba" "(cl-callf2 ba"))
71 (with-temp-buffer
72 (emacs-lisp-mode)
73 (insert text)
74 (let ((comps (elisp--test-completions)))
75 (should (member "backup-buffer" comps))
76 (should-not (member "backup-inhibited" comps))))))
77
78(ert-deftest elisp-completes-local-variables ()
79 (with-temp-buffer
80 (emacs-lisp-mode)
81 (insert "(let ((bar 1) baz) (foo ba")
82 (let ((comps (elisp--test-completions)))
83 (should (member "backup-inhibited" comps))
84 (should (member "bar" comps))
85 (should (member "baz" comps)))))
86
87(provide 'elisp-mode-tests)
88;;; elisp-mode-tests.el ends here