From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel 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 Message-ID: <87k3czr3ip.fsf@yandex.ru> References: <87zjm4tl2b.fsf@yandex.ru> <52F99C65.5010007@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1392268924 2570 80.91.229.3 (13 Feb 2014 05:22:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Feb 2014 05:22:04 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 13 06:22:11 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WDokU-0004On-WF for ged-emacs-devel@m.gmane.org; Thu, 13 Feb 2014 06:22:11 +0100 Original-Received: from localhost ([::1]:44328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDokU-0006Ug-GV for ged-emacs-devel@m.gmane.org; Thu, 13 Feb 2014 00:22:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDokM-0006Tz-Td for emacs-devel@gnu.org; Thu, 13 Feb 2014 00:22:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WDokH-0001pR-Ii for emacs-devel@gnu.org; Thu, 13 Feb 2014 00:22:02 -0500 Original-Received: from mail-ea0-x234.google.com ([2a00:1450:4013:c01::234]:54675) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WDokH-0001pB-73 for emacs-devel@gnu.org; Thu, 13 Feb 2014 00:21:57 -0500 Original-Received: by mail-ea0-f180.google.com with SMTP id o10so4863525eaj.39 for ; Wed, 12 Feb 2014 21:21:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=gEACZNdnOf/GYdYHdeWN0Thi9//hc3lFm446pNUigjQ=; b=fLjy5cWykxXknB4O7m5sN+Y/P80fUcT5V7epBbwXu59VFtOV7mTKLI2+y5HGL9j7Q1 Ban6qm094nw0ndC1xgOWXeLlpaXbiwpH3m9pxd0MdSSX6ItIGXoYsoRxGe6VVI2QFBjW COXXU+kZW/itjG95EZiA2TOuDJoy2JDZif9Cg7LxsuZuY5Gct3+D8VkwtxUnWEVu6NL9 cp4pd4ObQynqW9C7nai6bQFdwzGcgiZ6L21NXcEq/BogSIsAXPD6ERaIKn2wIzsG+M3j sZj/K2u+yCHhbCFUcgrJBZdqT2W0wqUTSUf6b9oRGU9v9dDMFWemb8LSju5w9Kg5Z2Ao M3SA== X-Received: by 10.15.93.203 with SMTP id w51mr8854677eez.33.1392268916316; Wed, 12 Feb 2014 21:21:56 -0800 (PST) Original-Received: from axl (62-36-157.netrun.cytanet.com.cy. [62.228.36.157]) by mx.google.com with ESMTPSA id m1sm2453576een.7.2014.02.12.21.21.53 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 12 Feb 2014 21:21:55 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Tue, 11 Feb 2014 20:42:10 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::234 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:169577 Archived-At: Stefan Monnier 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)) " ")) :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))