From: "Simen Heggestøyl" <simenheg@gmail.com>
To: 23458@debbugs.gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
Dmitry Gutov <dgutov@yandex.ru>
Subject: bug#23458: [PATCH] Support completion of HTML tags in CSS selectors
Date: Thu, 05 May 2016 14:32:45 +0200 [thread overview]
Message-ID: <1462451565.2892.0@smtp.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 111 bytes --]
The attached patch adds support for completion of HTML tags in CSS
selectors for CSS- and SCSS mode.
-- Simen
[-- Attachment #1.2: Type: text/html, Size: 155 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-completion-of-HTML-tags-in-CSS-selectors.patch --]
[-- Type: text/x-patch, Size: 4791 bytes --]
From 4af469d4a67c020eef90e3c19ca9094bf7b59696 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Sun, 1 May 2016 14:59:11 +0200
Subject: [PATCH] Support completion of HTML tags in CSS selectors
* lisp/textmodes/css-mode.el (css--complete-property): Make completion
non-exclusive to allow mixing with selector completions.
(css--html-tags): New variable holding a list of HTML tags for
completion.
(css--nested-selectors-allowed): New variable for determining whether
nested selectors are allowed in the current mode.
(css--complete-selector): New function for completing part of a CSS
selector.
(css-completion-at-point): Removed in favor of adding several
completion functions to `completion-at-point-functions'.
(css-mode): Add each completion function to
`completion-at-point-functions' instead of using
`css-completion-at-point'.
(scss-mode): Allow nested selectors.
---
etc/NEWS | 4 ++--
lisp/textmodes/css-mode.el | 41 +++++++++++++++++++++++++++++------------
2 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 21602ff..e202612 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -282,8 +282,8 @@ different group ID.
** CSS mode
---
-*** Support for completing attribute values and bang-rules using the
-'completion-at-point' command.
+*** Support for completing attribute values, at-rules, bang-rules, and
+HTML tags using the 'completion-at-point' command.
+++
** Emacs now supports character name escape sequences in character and
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index e30fb3e..77e2e77 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -30,10 +30,12 @@
;; - electric ; and }
;; - filling code with auto-fill-mode
;; - fix font-lock errors with multi-line selectors
+;; - support completion of user-defined classes names and IDs
;;; Code:
(require 'seq)
+(require 'sgml-mode)
(require 'smie)
(defgroup css nil
@@ -747,7 +749,7 @@ css--complete-property
(let ((start (point)))
(skip-chars-backward " \t\r\n")
(when (memq (char-before) '(?\{ ?\;))
- (list start pos css-property-ids))))))
+ (list start pos css-property-ids :exclusive 'no))))))
(defun css--complete-bang-rule ()
"Complete bang-rule at point."
@@ -824,15 +826,24 @@ css--complete-property-value
(list (point) end
(cons "inherit" (css--property-values property))))))))
-(defun css-completion-at-point ()
- "Complete current symbol at point.
-Currently supports completion of CSS properties, property values,
-pseudo-elements, pseudo-classes, at-rules, and bang-rules."
- (or (css--complete-property)
- (css--complete-bang-rule)
- (css--complete-property-value)
- (css--complete-pseudo-element-or-class)
- (css--complete-at-rule)))
+(defvar css--html-tags (mapcar #'car html-tag-alist)
+ "List of HTML tags.
+Used to provide completion of HTML tags in selectors.")
+
+(defvar css--nested-selectors-allowed nil
+ "Non-nil if nested selectors are allowed in the current mode.")
+(make-variable-buffer-local 'css--nested-selectors-allowed)
+
+;; TODO: Currently only supports completion of HTML tags. By looking
+;; at open HTML mode buffers we should be able to provide completion
+;; of user-defined classes and IDs too.
+(defun css--complete-selector ()
+ "Complete part of a CSS selector at point."
+ (when (or (= (nth 0 (syntax-ppss)) 0) css--nested-selectors-allowed)
+ (save-excursion
+ (let ((end (point)))
+ (skip-chars-backward "-[:alnum:]")
+ (list (point) end css--html-tags)))))
;;;###autoload
(define-derived-mode css-mode prog-mode "CSS"
@@ -852,8 +863,13 @@ css-mode
:backward-token #'css-smie--backward-token)
(setq-local electric-indent-chars
(append css-electric-keys electric-indent-chars))
- (add-hook 'completion-at-point-functions
- #'css-completion-at-point nil 'local))
+ (dolist (func (list #'css--complete-bang-rule
+ #'css--complete-property-value
+ #'css--complete-pseudo-element-or-class
+ #'css--complete-at-rule
+ #'css--complete-property
+ #'css--complete-selector))
+ (add-hook 'completion-at-point-functions func t 'local)))
(defvar comment-continue)
@@ -990,6 +1006,7 @@ scss-mode
(setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)")
(setq-local css--at-ids (append css-at-ids scss-at-ids))
(setq-local css--bang-ids (append css-bang-ids scss-bang-ids))
+ (setq-local css--nested-selectors-allowed t)
(setq-local font-lock-defaults
(list (scss-font-lock-keywords) nil t)))
--
2.8.1
next reply other threads:[~2016-05-05 12:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-05 12:32 Simen Heggestøyl [this message]
2016-05-05 15:02 ` bug#23458: [PATCH] Support completion of HTML tags in CSS selectors Stefan Monnier
2016-05-05 16:44 ` Simen Heggestøyl
2016-05-05 16:59 ` Stefan Monnier
2016-05-05 19:24 ` Simen Heggestøyl
2016-05-05 21:52 ` Stefan Monnier
2016-05-07 23:37 ` Dmitry Gutov
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=1462451565.2892.0@smtp.gmail.com \
--to=simenheg@gmail.com \
--cc=23458@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=monnier@iro.umontreal.ca \
/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.