aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2014-09-19 07:10:29 +0400
committerDmitry Gutov2014-09-19 07:10:29 +0400
commit48453e00a39cf10f77183e7cd19546c1d43ab1f4 (patch)
tree9fffeda11d963f13ab4cdbf01b98d77fd0d0336b
parent212b4d631b7604f5e9000de467b1001084a2751f (diff)
downloademacs-48453e00a39cf10f77183e7cd19546c1d43ab1f4.tar.gz
emacs-48453e00a39cf10f77183e7cd19546c1d43ab1f4.zip
Make lisp-completion-at-point more discerning
* lisp/emacs-lisp/lisp.el (lisp--expect-function-p) (lisp--form-quoted-p): New functions. (lisp-completion-at-point): Use them to see if we're completing a variable reference, a function name, or just any symbol. http://lists.gnu.org/archive/html/emacs-devel/2014-02/msg00229.html
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/emacs-lisp/lisp.el83
2 files changed, 79 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6f5e70ab6cb..2bdc45bfa50 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12014-09-19 Dmitry Gutov <dgutov@yandex.ru>
2
3 * emacs-lisp/lisp.el (lisp--expect-function-p)
4 (lisp--form-quoted-p): New functions.
5 (lisp-completion-at-point): Use them to see if we're completing a
6 variable reference, a function name, or just any symbol.
7 http://lists.gnu.org/archive/html/emacs-devel/2014-02/msg00229.html
8
12014-09-18 Ivan Kanis <ivan@kanis.fr> 92014-09-18 Ivan Kanis <ivan@kanis.fr>
2 10
3 * net/shr.el, net/eww.el: Don't override `shr-width', but 11 * net/shr.el, net/eww.el: Don't override `shr-width', but
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 30fee64635c..ae2d62e9baf 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -848,6 +848,46 @@ considered."
848 (mapcar #'symbol-name (lisp--local-variables)))))) 848 (mapcar #'symbol-name (lisp--local-variables))))))
849 lastvars))))) 849 lastvars)))))
850 850
851(defun lisp--expect-function-p (pos)
852 "Return non-nil if the symbol at point is expected to be a function."
853 (or
854 (and (eq (char-before pos) ?')
855 (eq (char-before (1- pos)) ?#))
856 (save-excursion
857 (let ((parent (nth 1 (syntax-ppss pos))))
858 (when parent
859 (goto-char parent)
860 (and
861 (looking-at (concat "(\\(cl-\\)?"
862 (regexp-opt '("declare-function"
863 "function" "defadvice"
864 "callf" "callf2"
865 "defsetf"))
866 "[ \t\r\n]+"))
867 (eq (match-end 0) pos)))))))
868
869(defun lisp--form-quoted-p (pos)
870 "Return non-nil if the form at POS is not evaluated.
871It can be quoted, or be inside a quoted form."
872 ;; FIXME: Do some macro expansion maybe.
873 (save-excursion
874 (let ((state (syntax-ppss pos)))
875 (or (nth 8 state) ; Code inside strings usually isn't evaluated.
876 ;; FIXME: The 9th element is undocumented.
877 (let ((nesting (cons (point) (reverse (nth 9 state))))
878 res)
879 (while (and nesting (not res))
880 (goto-char (pop nesting))
881 (cond
882 ((or (eq (char-after) ?\[)
883 (progn
884 (skip-chars-backward " ")
885 (memq (char-before) '(?' ?`))))
886 (setq res t))
887 ((eq (char-before) ?,)
888 (setq nesting nil))))
889 res)))))
890
851;; FIXME: Support for Company brings in features which straddle eldoc. 891;; FIXME: Support for Company brings in features which straddle eldoc.
852;; We should consolidate this, so that major modes can provide all that 892;; We should consolidate this, so that major modes can provide all that
853;; data all at once: 893;; data all at once:
@@ -927,22 +967,41 @@ considered."
927 ;; use it to provide a more specific completion table in some 967 ;; use it to provide a more specific completion table in some
928 ;; cases. E.g. filter out keywords that are not understood by 968 ;; cases. E.g. filter out keywords that are not understood by
929 ;; the macro/function being called. 969 ;; the macro/function being called.
930 (list nil (completion-table-merge 970 (cond
931 lisp--local-variables-completion-table 971 ((lisp--expect-function-p beg)
932 (apply-partially #'completion-table-with-predicate 972 (list nil obarray
933 obarray 973 :predicate #'fboundp
934 ;; Don't include all symbols 974 :company-doc-buffer #'lisp--company-doc-buffer
935 ;; (bug#16646). 975 :company-docsig #'lisp--company-doc-string
936 (lambda (sym) 976 :company-location #'lisp--company-location))
937 (or (boundp sym) 977 ((lisp--form-quoted-p beg)
938 (fboundp sym) 978 (list nil (completion-table-merge
939 (symbol-plist sym))) 979 ;; FIXME: Is this table useful for this case?
940 'strict)) 980 lisp--local-variables-completion-table
981 (apply-partially #'completion-table-with-predicate
982 obarray
983 ;; Don't include all symbols
984 ;; (bug#16646).
985 (lambda (sym)
986 (or (boundp sym)
987 (fboundp sym)
988 (symbol-plist sym)))
989 'strict))
941 :annotation-function 990 :annotation-function
942 (lambda (str) (if (fboundp (intern-soft str)) " <f>")) 991 (lambda (str) (if (fboundp (intern-soft str)) " <f>"))
943 :company-doc-buffer #'lisp--company-doc-buffer 992 :company-doc-buffer #'lisp--company-doc-buffer
944 :company-docsig #'lisp--company-doc-string 993 :company-docsig #'lisp--company-doc-string
945 :company-location #'lisp--company-location) 994 :company-location #'lisp--company-location))
995 (t
996 (list nil (completion-table-merge
997 lisp--local-variables-completion-table
998 (apply-partially #'completion-table-with-predicate
999 obarray
1000 #'boundp
1001 'strict))
1002 :company-doc-buffer #'lisp--company-doc-buffer
1003 :company-docsig #'lisp--company-doc-string
1004 :company-location #'lisp--company-location)))
946 ;; Looks like a funcall position. Let's double check. 1005 ;; Looks like a funcall position. Let's double check.
947 (save-excursion 1006 (save-excursion
948 (goto-char (1- beg)) 1007 (goto-char (1- beg))