From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: /srv/bzr/emacs/elpa r395: * company.el (company-capf): Add support for `sorted' and `post-completion'. Date: Sun, 05 May 2013 02:32:36 -0400 Message-ID: References: <87vc6yz9r4.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1367735569 3636 80.91.229.3 (5 May 2013 06:32:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 5 May 2013 06:32:49 +0000 (UTC) Cc: emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 05 08:32:45 2013 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 1UYsV1-00068j-5W for ged-emacs-devel@m.gmane.org; Sun, 05 May 2013 08:32:43 +0200 Original-Received: from localhost ([::1]:56903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYsV0-0003Q6-HO for ged-emacs-devel@m.gmane.org; Sun, 05 May 2013 02:32:42 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYsUx-0003Pz-KR for emacs-devel@gnu.org; Sun, 05 May 2013 02:32:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYsUw-0005zb-LH for emacs-devel@gnu.org; Sun, 05 May 2013 02:32:39 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:43548) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYsUw-0005zV-Gy for emacs-devel@gnu.org; Sun, 05 May 2013 02:32:38 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFFMCqRF/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLDiYHCxQYDSSIHgbBLZEKA6R6gV6DEw X-IPAS-Result: Av4EABK/CFFMCqRF/2dsb2JhbABEvw4Xc4IeAQEEAVYjBQsLDiYHCxQYDSSIHgbBLZEKA6R6gV6DEw X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="11067026" Original-Received: from 76-10-164-69.dsl.teksavvy.com (HELO pastel.home) ([76.10.164.69]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 05 May 2013 02:32:33 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 098F667917; Sun, 5 May 2013 02:32:37 -0400 (EDT) In-Reply-To: <87vc6yz9r4.fsf@yandex.ru> (Dmitry Gutov's message of "Sun, 05 May 2013 01:59:59 +0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 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:159319 Archived-At: >> ;; (defun company-my-backend (command &optional arg &rest ignored) >> -;; (case command >> -;; (prefix (when (looking-back "foo\\>") >> +;; (pcase command >> +;; (`prefix (when (looking-back "foo\\>") >> ;; (match-string 0))) >> -;; (candidates (list "foobar" "foobaz" "foobarbaz")) >> -;; (meta (format "This value is named %s" arg)))) >> +;; (`candidates (list "foobar" "foobaz" "foobarbaz")) >> +;; (`meta (format "This value is named %s" arg)))) > Like the header in company.el says, we still try to support Emacs 22 and > 23. `pcase' was only added in 23.3, I believe. But this is in a comment, so it's not a problem. >> +(defun company-capf (command &optional arg &rest _args) > ... >> + (duplicates nil) ;Don't bother. >> + (no-cache t) ;FIXME: Improve! >> + (meta nil) ;FIXME: Return one-line docstring for `arg'. >> + (doc-buffer nil) ;FIXME: Return help buffer for `arg'. >> + (location nil) ;FIXME: Return (BUF . POS) or (FILE . LINENB) of `arg'. >> + (init nil) ;Don't bother: plenty of other ways to initialize >> the code. > a) There's no need to return nils explicitly, other backends don't. Indeed, I only need them to have a place where to put the FIXMEs. > b) Who are these FIXMEs for? Whoever takes on the challenge. > I guess `meta' can be implemented by > calling `:annotation-function' (don't know if it's appropriate), but > `doc-buffer' and `location' don't have anything corresponding in > `completion-extra-properties'. `completion-extra-properties' can have anything you want in it. Same for `completion-metadata'. Of course, new entries in these alists/plists won't be understood by other users of completion-at-point-functions, but that's not a problem in itself. >> + (require-match nil) ;This should be a property of the >> front-end! > Should it really? Hmm... after writing an answer and throwing it away a few times, I think you're right: this definitely makes sense for a backend and basically means "I, as a backend, know that only those elements make sense here". But in most cases the front-end can't use it to *prevent* the user from writing something else (Emacs likes to let the user shoot himself in the foot, on the assumption that the user knows better). It could use it to highlight a non-matching entry, OTOH. >> +(defvar company-backend) > This variable is declared about ~30 lines below that. Is it appropriate > to have both declarations in the same file? No, it was a quick fix. Moving the declaration is probably a better option. > It probably should, but, again, lexical-binding is not available in > Emacs < 24. ATM I'm only using it to improve some logic that uses > `boundp' in `company-elisp'. I work under the assumption that my time is better spent if I concentrate on users of Emacs-24 (users who want the newer features of company can upgrade to Emacs-24). Stefan