diff options
| author | Dmitry Gutov | 2014-09-19 07:28:31 +0400 |
|---|---|---|
| committer | Dmitry Gutov | 2014-09-19 07:28:31 +0400 |
| commit | 30c17da5df63c49ac3f4d7fdf1a0d668d02516e3 (patch) | |
| tree | e0216b073a5240bb51782166b82b42d3eb2b1570 | |
| parent | 48453e00a39cf10f77183e7cd19546c1d43ab1f4 (diff) | |
| download | emacs-30c17da5df63c49ac3f4d7fdf1a0d668d02516e3.tar.gz emacs-30c17da5df63c49ac3f4d7fdf1a0d668d02516e3.zip | |
* lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Only calculate
`table-etc' when `end' is non-nil.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp.el | 197 |
2 files changed, 104 insertions, 98 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2bdc45bfa50..777322dc82c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2014-09-19 Dmitry Gutov <dgutov@yandex.ru> | 1 | 2014-09-19 Dmitry Gutov <dgutov@yandex.ru> |
| 2 | 2 | ||
| 3 | * emacs-lisp/lisp.el (lisp-completion-at-point): Only calculate | ||
| 4 | `table-etc' when `end' is non-nil. | ||
| 5 | |||
| 6 | 2014-09-19 Dmitry Gutov <dgutov@yandex.ru> | ||
| 7 | |||
| 3 | * emacs-lisp/lisp.el (lisp--expect-function-p) | 8 | * emacs-lisp/lisp.el (lisp--expect-function-p) |
| 4 | (lisp--form-quoted-p): New functions. | 9 | (lisp--form-quoted-p): New functions. |
| 5 | (lisp-completion-at-point): Use them to see if we're completing a | 10 | (lisp-completion-at-point): Use them to see if we're completing a |
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index ae2d62e9baf..581e9b9504b 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el | |||
| @@ -960,104 +960,105 @@ It can be quoted, or be inside a quoted form." | |||
| 960 | (when (>= (point) pos) | 960 | (when (>= (point) pos) |
| 961 | (point))) | 961 | (point))) |
| 962 | (scan-error pos)))) | 962 | (scan-error pos)))) |
| 963 | (funpos (eq (char-before beg) ?\()) ;t if in function position. | 963 | ;; t if in function position. |
| 964 | (table-etc | 964 | (funpos (eq (char-before beg) ?\())) |
| 965 | (if (not funpos) | ||
| 966 | ;; FIXME: We could look at the first element of the list and | ||
| 967 | ;; use it to provide a more specific completion table in some | ||
| 968 | ;; cases. E.g. filter out keywords that are not understood by | ||
| 969 | ;; the macro/function being called. | ||
| 970 | (cond | ||
| 971 | ((lisp--expect-function-p beg) | ||
| 972 | (list nil obarray | ||
| 973 | :predicate #'fboundp | ||
| 974 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 975 | :company-docsig #'lisp--company-doc-string | ||
| 976 | :company-location #'lisp--company-location)) | ||
| 977 | ((lisp--form-quoted-p beg) | ||
| 978 | (list nil (completion-table-merge | ||
| 979 | ;; FIXME: Is this table useful for this case? | ||
| 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)) | ||
| 990 | :annotation-function | ||
| 991 | (lambda (str) (if (fboundp (intern-soft str)) " <f>")) | ||
| 992 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 993 | :company-docsig #'lisp--company-doc-string | ||
| 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))) | ||
| 1005 | ;; Looks like a funcall position. Let's double check. | ||
| 1006 | (save-excursion | ||
| 1007 | (goto-char (1- beg)) | ||
| 1008 | (let ((parent | ||
| 1009 | (condition-case nil | ||
| 1010 | (progn (up-list -1) (forward-char 1) | ||
| 1011 | (let ((c (char-after))) | ||
| 1012 | (if (eq c ?\() ?\( | ||
| 1013 | (if (memq (char-syntax c) '(?w ?_)) | ||
| 1014 | (read (current-buffer)))))) | ||
| 1015 | (error nil)))) | ||
| 1016 | (pcase parent | ||
| 1017 | ;; FIXME: Rather than hardcode special cases here, | ||
| 1018 | ;; we should use something like a symbol-property. | ||
| 1019 | (`declare | ||
| 1020 | (list t (mapcar (lambda (x) (symbol-name (car x))) | ||
| 1021 | (delete-dups | ||
| 1022 | ;; FIXME: We should include some | ||
| 1023 | ;; docstring with each entry. | ||
| 1024 | (append | ||
| 1025 | macro-declarations-alist | ||
| 1026 | defun-declarations-alist))))) | ||
| 1027 | ((and (or `condition-case `condition-case-unless-debug) | ||
| 1028 | (guard (save-excursion | ||
| 1029 | (ignore-errors | ||
| 1030 | (forward-sexp 2) | ||
| 1031 | (< (point) beg))))) | ||
| 1032 | (list t obarray | ||
| 1033 | :predicate (lambda (sym) (get sym 'error-conditions)))) | ||
| 1034 | ((and ?\( | ||
| 1035 | (guard (save-excursion | ||
| 1036 | (goto-char (1- beg)) | ||
| 1037 | (up-list -1) | ||
| 1038 | (forward-symbol -1) | ||
| 1039 | (looking-at "\\_<let\\*?\\_>")))) | ||
| 1040 | (list t obarray | ||
| 1041 | :predicate #'boundp | ||
| 1042 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 1043 | :company-docsig #'lisp--company-doc-string | ||
| 1044 | :company-location #'lisp--company-location)) | ||
| 1045 | (_ (list nil obarray | ||
| 1046 | :predicate #'fboundp | ||
| 1047 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 1048 | :company-docsig #'lisp--company-doc-string | ||
| 1049 | :company-location #'lisp--company-location | ||
| 1050 | )))))))) | ||
| 1051 | (when end | 965 | (when end |
| 1052 | (let ((tail (if (null (car table-etc)) | 966 | (let ((table-etc |
| 1053 | (cdr table-etc) | 967 | (if (not funpos) |
| 1054 | (cons | 968 | ;; FIXME: We could look at the first element of the list and |
| 1055 | (if (memq (char-syntax (or (char-after end) ?\s)) | 969 | ;; use it to provide a more specific completion table in some |
| 1056 | '(?\s ?>)) | 970 | ;; cases. E.g. filter out keywords that are not understood by |
| 1057 | (cadr table-etc) | 971 | ;; the macro/function being called. |
| 1058 | (apply-partially 'completion-table-with-terminator | 972 | (cond |
| 1059 | " " (cadr table-etc))) | 973 | ((lisp--expect-function-p beg) |
| 1060 | (cddr table-etc))))) | 974 | (list nil obarray |
| 1061 | `(,beg ,end ,@tail)))))) | 975 | :predicate #'fboundp |
| 976 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 977 | :company-docsig #'lisp--company-doc-string | ||
| 978 | :company-location #'lisp--company-location)) | ||
| 979 | ((lisp--form-quoted-p beg) | ||
| 980 | (list nil (completion-table-merge | ||
| 981 | ;; FIXME: Is this table useful for this case? | ||
| 982 | lisp--local-variables-completion-table | ||
| 983 | (apply-partially #'completion-table-with-predicate | ||
| 984 | obarray | ||
| 985 | ;; Don't include all symbols | ||
| 986 | ;; (bug#16646). | ||
| 987 | (lambda (sym) | ||
| 988 | (or (boundp sym) | ||
| 989 | (fboundp sym) | ||
| 990 | (symbol-plist sym))) | ||
| 991 | 'strict)) | ||
| 992 | :annotation-function | ||
| 993 | (lambda (str) (if (fboundp (intern-soft str)) " <f>")) | ||
| 994 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 995 | :company-docsig #'lisp--company-doc-string | ||
| 996 | :company-location #'lisp--company-location)) | ||
| 997 | (t | ||
| 998 | (list nil (completion-table-merge | ||
| 999 | lisp--local-variables-completion-table | ||
| 1000 | (apply-partially #'completion-table-with-predicate | ||
| 1001 | obarray | ||
| 1002 | #'boundp | ||
| 1003 | 'strict)) | ||
| 1004 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 1005 | :company-docsig #'lisp--company-doc-string | ||
| 1006 | :company-location #'lisp--company-location))) | ||
| 1007 | ;; Looks like a funcall position. Let's double check. | ||
| 1008 | (save-excursion | ||
| 1009 | (goto-char (1- beg)) | ||
| 1010 | (let ((parent | ||
| 1011 | (condition-case nil | ||
| 1012 | (progn (up-list -1) (forward-char 1) | ||
| 1013 | (let ((c (char-after))) | ||
| 1014 | (if (eq c ?\() ?\( | ||
| 1015 | (if (memq (char-syntax c) '(?w ?_)) | ||
| 1016 | (read (current-buffer)))))) | ||
| 1017 | (error nil)))) | ||
| 1018 | (pcase parent | ||
| 1019 | ;; FIXME: Rather than hardcode special cases here, | ||
| 1020 | ;; we should use something like a symbol-property. | ||
| 1021 | (`declare | ||
| 1022 | (list t (mapcar (lambda (x) (symbol-name (car x))) | ||
| 1023 | (delete-dups | ||
| 1024 | ;; FIXME: We should include some | ||
| 1025 | ;; docstring with each entry. | ||
| 1026 | (append | ||
| 1027 | macro-declarations-alist | ||
| 1028 | defun-declarations-alist))))) | ||
| 1029 | ((and (or `condition-case `condition-case-unless-debug) | ||
| 1030 | (guard (save-excursion | ||
| 1031 | (ignore-errors | ||
| 1032 | (forward-sexp 2) | ||
| 1033 | (< (point) beg))))) | ||
| 1034 | (list t obarray | ||
| 1035 | :predicate (lambda (sym) (get sym 'error-conditions)))) | ||
| 1036 | ((and ?\( | ||
| 1037 | (guard (save-excursion | ||
| 1038 | (goto-char (1- beg)) | ||
| 1039 | (up-list -1) | ||
| 1040 | (forward-symbol -1) | ||
| 1041 | (looking-at "\\_<let\\*?\\_>")))) | ||
| 1042 | (list t obarray | ||
| 1043 | :predicate #'boundp | ||
| 1044 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 1045 | :company-docsig #'lisp--company-doc-string | ||
| 1046 | :company-location #'lisp--company-location)) | ||
| 1047 | (_ (list nil obarray | ||
| 1048 | :predicate #'fboundp | ||
| 1049 | :company-doc-buffer #'lisp--company-doc-buffer | ||
| 1050 | :company-docsig #'lisp--company-doc-string | ||
| 1051 | :company-location #'lisp--company-location | ||
| 1052 | )))))))) | ||
| 1053 | (nconc (list beg end) | ||
| 1054 | (if (null (car table-etc)) | ||
| 1055 | (cdr table-etc) | ||
| 1056 | (cons | ||
| 1057 | (if (memq (char-syntax (or (char-after end) ?\s)) | ||
| 1058 | '(?\s ?>)) | ||
| 1059 | (cadr table-etc) | ||
| 1060 | (apply-partially 'completion-table-with-terminator | ||
| 1061 | " " (cadr table-etc))) | ||
| 1062 | (cddr table-etc))))))))) | ||
| 1062 | 1063 | ||
| 1063 | ;;; lisp.el ends here | 1064 | ;;; lisp.el ends here |