[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point):
From: |
Dmitry Gutov |
Subject: |
Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start |
Date: |
Thu, 13 Feb 2014 07:21:50 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
> Let's keep it for after 24.4. It's clearly a new feature, and I don't
> see any hurry to implement it.
Ok, you're the boss. I'd consider it mostly a bugfix, though. At least
the initial version.
> I think we'd want to use (nth 9 (syntax-ppss)) rather than up-list (it's
> got the start pos of all enclosing lists in ). Using syntax-ppss should
> also help us handle the case we're inside a comment/string.
Done. I'm assuming you mean that when we're inside non-code area, we're
always "quoted".
>> `defadvice', ideally, would have to be handled specially anyway, to limit
>> completions to functions.
>
> Yes. And `function' (aka #') should only complete functions as well.
And done.
=== modified file 'lisp/emacs-lisp/lisp.el'
--- lisp/emacs-lisp/lisp.el 2014-02-10 05:50:16 +0000
+++ lisp/emacs-lisp/lisp.el 2014-02-13 05:21:15 +0000
@@ -762,6 +762,46 @@
(mapcar #'symbol-name (lisp--local-variables))))))
lastvars)))))
+(defun lisp--expect-function-p (pos)
+ "Return non-nil if the symbol at point is expected to be a function."
+ (or
+ (and (eq (char-before pos) ?')
+ (eq (char-before (1- pos)) ?#))
+ (save-excursion
+ (let ((parent (nth 1 (syntax-ppss pos))))
+ (when parent
+ (goto-char parent)
+ (and
+ (looking-at (concat "(\\(cl-\\)?"
+ (regexp-opt '("function" "defadvice"
+ "callf" "callf2"
+ "defsetf"))
+ "[ \t\r\n]+"))
+ (eq (match-end 0) pos)))))))
+
+(defun lisp--form-quoted-p (pos)
+ "Return non-nil if the form at POS is not evaluated.
+It can be quoted, or be inside a quoted form.
+This function moves point."
+ ;; FIXME: Do some macro expansion maybe.
+ (save-excursion
+ (let ((state (syntax-ppss pos)))
+ (or (nth 8 state) ; Code inside strings usually isn't evaluated.
+ ;; FIXME: The 9th element is undocumented.
+ (let ((nesting (cons (point) (reverse (nth 9 state))))
+ res)
+ (while (and nesting (not res))
+ (goto-char (pop nesting))
+ (cond
+ ((or (eq (char-after) ?\[)
+ (progn
+ (skip-chars-backward " ")
+ (memq (char-before) '(?' ?`))))
+ (setq res t))
+ ((eq (char-before) ?,)
+ (setq nesting nil))))
+ res)))))
+
;; FIXME: Support for Company brings in features which straddle eldoc.
;; We should consolidate this, so that major modes can provide all that
;; data all at once:
@@ -841,22 +881,41 @@
;; use it to provide a more specific completion table in some
;; cases. E.g. filter out keywords that are not understood by
;; the macro/function being called.
- (list nil (completion-table-merge
- lisp--local-variables-completion-table
- (apply-partially #'completion-table-with-predicate
- obarray
- ;; Don't include all symbols
- ;; (bug#16646).
- (lambda (sym)
- (or (boundp sym)
- (fboundp sym)
- (symbol-plist sym)))
- 'strict))
+ (cond
+ ((lisp--expect-function-p beg)
+ (list nil obarray
+ :predicate #'fboundp
+ :company-doc-buffer #'lisp--company-doc-buffer
+ :company-docsig #'lisp--company-doc-string
+ :company-location #'lisp--company-location))
+ ((lisp--form-quoted-p beg)
+ (list nil (completion-table-merge
+ ;; FIXME: Is this table useful for this case?
+ lisp--local-variables-completion-table
+ (apply-partially #'completion-table-with-predicate
+ obarray
+ ;; Don't include all symbols
+ ;; (bug#16646).
+ (lambda (sym)
+ (or (boundp sym)
+ (fboundp sym)
+ (symbol-plist sym)))
+ 'strict))
:annotation-function
(lambda (str) (if (fboundp (intern-soft str)) " <f>"))
:company-doc-buffer #'lisp--company-doc-buffer
:company-docsig #'lisp--company-doc-string
- :company-location #'lisp--company-location)
+ :company-location #'lisp--company-location))
+ (t
+ (list nil (completion-table-merge
+ lisp--local-variables-completion-table
+ (apply-partially #'completion-table-with-predicate
+ obarray
+ #'boundp
+ 'strict))
+ :company-doc-buffer #'lisp--company-doc-buffer
+ :company-docsig #'lisp--company-doc-string
+ :company-location #'lisp--company-location)))
;; Looks like a funcall position. Let's double check.
(save-excursion
(goto-char (1- beg))
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, (continued)
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Dmitry Gutov, 2014/02/10
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Michael Heerdegen, 2014/02/11
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Dmitry Gutov, 2014/02/11
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Michael Heerdegen, 2014/02/12
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Dmitry Gutov, 2014/02/13
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Michael Heerdegen, 2014/02/13
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Stefan Monnier, 2014/02/13
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Dmitry Gutov, 2014/02/13
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Stefan Monnier, 2014/02/11
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start,
Dmitry Gutov <=
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Michael Heerdegen, 2014/02/13
- Re: trunk r116285: * lisp/emacs-lisp/lisp.el (lisp-completion-at-point): Symbols don't start, Dmitry Gutov, 2014/02/13