From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#24389: [PATCH] Support completion of classes and IDs in CSS mode Date: Wed, 07 Sep 2016 16:01:04 -0400 Message-ID: References: <1473270025.21515.0@smtp.gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1473278360 23114 195.159.176.226 (7 Sep 2016 19:59:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 7 Sep 2016 19:59:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cc: 24389@debbugs.gnu.org, dgutov@yandex.ru To: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 07 21:59:16 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhj06-0005MZ-0V for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Sep 2016 21:59:14 +0200 Original-Received: from localhost ([::1]:42810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhj03-0006o3-Q3 for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Sep 2016 15:59:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhizy-0006nx-CG for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2016 15:59:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhizu-0002Mj-2v for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2016 15:59:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:55196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhizt-0002Mf-VE for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2016 15:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bhizt-00015g-N3 for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2016 15:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Sep 2016 19:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24389 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: bug-gnu-emacs@gnu.org, Dmitry Gutov Original-Received: via spool by submit@debbugs.gnu.org id=B.14732782884126 (code B ref -1); Wed, 07 Sep 2016 19:59:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Sep 2016 19:58:08 +0000 Original-Received: from localhost ([127.0.0.1]:52908 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhiz2-00014U-6i for submit@debbugs.gnu.org; Wed, 07 Sep 2016 15:58:08 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38450) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhiz0-000143-Ns for submit@debbugs.gnu.org; Wed, 07 Sep 2016 15:58:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhiyu-0002GB-H3 for submit@debbugs.gnu.org; Wed, 07 Sep 2016 15:58:01 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:49071) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhiyu-0002G3-Dd for submit@debbugs.gnu.org; Wed, 07 Sep 2016 15:58:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhiys-0005ov-8a for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2016 15:57:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhiyo-0002FO-35 for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2016 15:57:57 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:56784) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhiyn-0002FI-Ta for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2016 15:57:54 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id u87JvoVW031391; Wed, 7 Sep 2016 15:57:50 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 6142B662A6; Wed, 7 Sep 2016 16:01:04 -0400 (EDT) In-Reply-To: <1473270025.21515.0@smtp.gmail.com> ("Simen =?UTF-8?Q?Heggest=C3=B8yl?="'s message of "Wed, 07 Sep 2016 19:40:25 +0200") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV5790=0 X-NAI-Spam-Version: 2.3.0.9418 : core <5790> : inlines <5194> : streams <1696882> : uri <2284154> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:123070 Archived-At: > What do you think? I like the general idea, but have some nitpicks below. > +(defun css--complete-html-tag () > + "Complete HTML tag at point." > + (save-excursion > + (let ((end (point))) > + (skip-chars-backward "-[:alnum:]") > + (list (point) end css--html-tags)))) I don't see where this is used. > +(defvar css--foreign-completion-cache > + (list 'html-class-extractor-function (make-hash-table :test 'equal) > + 'html-id-extractor-function (make-hash-table :test 'equal)) I urge you to use alists rather than plist whenever you can. I only recommend plists for those rare cases where they're likely to often be written down by end-users who'd be bothered by the need to add dots and parentheses. > +(defun css--foreign-completions (extractor) > + "Return a list of completions provided by other buffers. > +EXTRACTOR should be the name of a function that may be defined in > +one or more buffers. In each of the buffers where EXTRACTOR is > +defined, EXTRACTOR is called and the results are accumulated into > +a list." > + (seq-uniq > + (seq-mapcat > + (lambda (buf) > + (with-current-buffer buf > + (when (boundp extractor) > + (let ((cache > + (plist-get css--foreign-completion-cache extractor))) > + (if cache > + (let ((hash (buffer-hash buf))) > + (or (gethash hash cache) > + (puthash hash (funcall (symbol-value extractor)) > + cache))) > + (funcall (symbol-value extractor))))))) > + (buffer-list)))) I think this design won't work well. How 'bout instead just always calling the function and let the other side handle the caching? This way the cache can work correctly even in case the list of completions depends on sources other than the buffer's content (a case which even your costly buffer-hash won't catch). Also, it means that depending on the cost of the extraction itself, the cache may be flushed more or less eagerly. > +(defvar html-class-extractor-function) > +(defvar html-id-extractor-function) The definition of those global variables seems to be missing. IIUC they should be in css-mode.el, so their name should start with "css-" I think (tho I agree that it's debatable). In any case I think it's important that their global value be a valid function rather than nil (it should probably be #'ignore). Also, if the caching is moved to those functions, then their name should not say "extractor" but should simply indicate that those functions should return the list of classes/ids. E.g. css-class-list-function. Stefan