From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: "Simen Heggestøyl" <simenheg@gmail.com>
Cc: 24389@debbugs.gnu.org, dgutov@yandex.ru
Subject: bug#24389: [PATCH] Support completion of classes and IDs in CSS mode
Date: Wed, 07 Sep 2016 16:01:04 -0400 [thread overview]
Message-ID: <jwvlgz3a47d.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <1473270025.21515.0@smtp.gmail.com> ("Simen Heggestøyl"'s message of "Wed, 07 Sep 2016 19:40:25 +0200")
> 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
next prev parent reply other threads:[~2016-09-07 20:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-07 17:40 bug#24389: [PATCH] Support completion of classes and IDs in CSS mode Simen Heggestøyl
2016-09-07 20:01 ` Stefan Monnier [this message]
2016-09-10 12:13 ` Simen Heggestøyl
2016-09-10 19:55 ` Stefan Monnier
2016-09-17 7:10 ` Simen Heggestøyl
2016-09-17 12:35 ` Stefan Monnier
2016-09-24 11:58 ` Simen Heggestøyl
2016-09-24 15:00 ` Nicolas Petton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvlgz3a47d.fsf-monnier+emacsbugs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=24389@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=simenheg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.