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: /srv/bzr/emacs/elpa r395: * company.el (company-capf): Add support for `sorted' and `post-completion'. Date: Sun, 05 May 2013 12:50:53 +0400 Message-ID: <51861D6D.8030709@yandex.ru> References: <87vc6yz9r4.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1367743872 3552 80.91.229.3 (5 May 2013 08:51:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 5 May 2013 08:51:12 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 05 10:51:10 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 1UYuey-0007nY-9T for ged-emacs-devel@m.gmane.org; Sun, 05 May 2013 10:51:08 +0200 Original-Received: from localhost ([::1]:49320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYuex-0007SC-TR for ged-emacs-devel@m.gmane.org; Sun, 05 May 2013 04:51:07 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYueq-0007PZ-3C for emacs-devel@gnu.org; Sun, 05 May 2013 04:51:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYuel-00026b-OY for emacs-devel@gnu.org; Sun, 05 May 2013 04:51:00 -0400 Original-Received: from mail-la0-x235.google.com ([2a00:1450:4010:c03::235]:49881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYuel-00026S-BW for emacs-devel@gnu.org; Sun, 05 May 2013 04:50:55 -0400 Original-Received: by mail-la0-f53.google.com with SMTP id eo20so2580945lab.12 for ; Sun, 05 May 2013 01:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding:x-antivirus:x-antivirus-status; bh=/X1oLFDYjXIcGsx38JtaE+nUmNlrZ4KQRpK9SyoQqqo=; b=g7cFeVxAbYH0egyaMqWCLwZLBhopCS/axEvxJvZR9lhJfEpQyI4cmeHaVkZXmzrLgc h9vf08RqgHGATkXRcAo0BLLT4beDR3QblG5EzR01YbeD3GGEShLfg9b3/r7IJYI2Zybv d0Y7uroEVgbrlsJ/bSU4IGcYyEj6tEbPZBcJJL462IOldcdMyIjwywD+5i/MYKHSuZWG qOxKqGZqU8ioCUXNp2qN8UW4rcUWviwKzxl+8DBfmChAGm0U18VXiXWL4U0WCjnAkZdH AhYTtRhqegD93RgOkfqcuIiWjt/Rq8A68g987zxIHCE7wK7BIf/0upQZ0StV2MWSyLbC N4ug== X-Received: by 10.112.161.6 with SMTP id xo6mr1736408lbb.124.1367743854164; Sun, 05 May 2013 01:50:54 -0700 (PDT) Original-Received: from [127.0.0.1] ([178.252.98.87]) by mx.google.com with ESMTPSA id y3sm6709132lby.12.2013.05.05.01.50.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 May 2013 01:50:53 -0700 (PDT) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: X-Antivirus: avast! (VPS 130504-1, 04.05.2013), Outbound message X-Antivirus-Status: Clean X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::235 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:159324 Archived-At: On 05.05.2013 10:32, Stefan Monnier wrote: >>> ;; (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. I'm not sure recommending to users to write new backends in a way incompatible with older Emacs is good. They may wish to remain compatible, yet be unaware that `pcase' is a new feature. That might make them sad upon discovery, and doubly so if they don't know about cl's `case'. By the way, is there a reason to use backquotes here? I remember you removing quotes from all backends' `case' forms, and using unquoted symbols in `pcase' seems to work just as well: (pcase 'boo (boo 'bah)) => 'bah >>> +(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. I guess I'll remove `(init nil)', then. By the way, if you think that `init' is useless for all backends, I don't believe that's true for `ropemacs' and `clang'. Retrying initialization once per buffer is fairly useful. >> 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. Ah okay, so I guess that section has everything to do with moving some company backends to completion-at-point functions. >>> + (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. Yes, so different completion UIs can interpret that return value differently. `completion-at-point' will ignore it. `company' front-ends can't highlight the non-matching input, though, because it effectively restarts completion after each character the user inputs (with some caching, to speed up the process), and so non-matching input aborts the completion and hides the candidates. This is somewhat difficult to change. But anyway, it follows the model set by IDEs which usually require matching input during completion, because the completion dropdown is often used for API discovery by the programmer, and it's often not big enough to show all candidates at the same time. The foot-shooting restriction is alleviated by the fact the the user can disable it (unless the backend returned `t', but, to my knowledge, none of them do that, and I might eventually remove that possibility), and that it only comes into play after the user has interacted with the completion interface, i.e. not when completion was just initiated by the timer. >> 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). This is totally fine for `company-capf', but `company-begin-with' is an old function/feature. I wonder if anyone's actually using it, though.