]> code.delx.au - gnu-emacs/commitdiff
Support completion of bang-rules in CSS mode
authorSimen Heggestøyl <simenheg@gmail.com>
Thu, 31 Mar 2016 19:18:00 +0000 (21:18 +0200)
committerSimen Heggestøyl <simenheg@gmail.com>
Thu, 31 Mar 2016 19:21:34 +0000 (21:21 +0200)
lisp/textmodes/css-mode.el (css--bang-ids): New buffer-local variable
holding the list of bang-rules for the current mode.
(css--font-lock-keywords): Retrieve bang-rules from `css--bang-ids'
instead of computing them.
(css--complete-bang-rule): New function for completing a bang-rule.
(css-completion-at-point): Add support for completing bang-rules.
(scss-font-lock-keywords): Change from a variable to a function in
order to recompute `css--font-lock-keywords' when `css--bang-ids' has
changed.
(scss-mode): Set `css--bang-ids' and recompute font-lock keywords.

etc/NEWS
lisp/textmodes/css-mode.el

index 66777e9f93148a8f1b2df3f63ade72e5fb27730b..726b4b9b7118fd94966bdc547dbc58289e7455d3 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -144,8 +144,8 @@ different group ID.
 ** CSS mode
 
 ---
-*** Support for completing attribute values using the 'completion-at-point'
-command.
+*** Support for completing attribute values and bang-rules using the
+'completion-at-point' command.
 
 \f
 * New Modes and Packages in Emacs 25.2
index fd3459efe7849a43a593a3da5ec2cd063ee8460c..cbef3d4026a240f361055bb073f20c03c83cfa30 100644 (file)
   '("default" "global" "optional")
   "Additional identifiers that appear in the form !foo in SCSS.")
 
+(defvar css--bang-ids css-bang-ids
+  "List of bang-rules for the current mode.")
+(make-variable-buffer-local 'css--bang-ids)
+
 (defconst css-descriptor-ids
   '("ascent" "baseline" "bbox" "cap-height" "centerline" "definition-src"
     "descent" "font-family" "font-size" "font-stretch" "font-style"
@@ -600,9 +604,7 @@ cannot be completed sensibly: `angle', `element-reference',
   "Face to use for vendor-specific properties.")
 
 (defun css--font-lock-keywords (&optional sassy)
-  `((,(concat "!\\s-*"
-              (regexp-opt (append (if sassy scss-bang-ids)
-                                  css-bang-ids)))
+  `((,(concat "!\\s-*" (regexp-opt css--bang-ids))
      (0 font-lock-builtin-face))
     ;; Atrules keywords.  IDs not in css-at-ids are valid (ignored).
     ;; In fact the regexp should probably be
@@ -732,6 +734,14 @@ cannot be completed sensibly: `angle', `element-reference',
         (when (memq (char-before) '(?\{ ?\;))
           (list start pos css-property-ids))))))
 
+(defun css--complete-bang-rule ()
+  "Complete bang-rule at point."
+  (save-excursion
+    (let ((pos (point)))
+      (skip-chars-backward "-[:alnum:]")
+      (when (eq (char-before) ?\!)
+        (list (point) pos css--bang-ids)))))
+
 (defun css--complete-pseudo-element-or-class ()
   "Complete pseudo-element or pseudo-class at point."
   (save-excursion
@@ -798,8 +808,9 @@ the string PROPERTY."
 (defun css-completion-at-point ()
   "Complete current symbol at point.
 Currently supports completion of CSS properties, property values,
-pseudo-elements, pseudo-classes, and at-rules."
+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)))
@@ -937,7 +948,7 @@ pseudo-elements, pseudo-classes, and at-rules."
     (modify-syntax-entry ?$ "'" st)
     st))
 
-(defvar scss-font-lock-keywords
+(defun scss-font-lock-keywords ()
   (append `((,(concat "$" css-ident-re) (0 font-lock-variable-name-face)))
           (css--font-lock-keywords 'sassy)
           `((,(concat "@mixin[ \t]+\\(" css-ident-re "\\)[ \t]*(")
@@ -958,7 +969,9 @@ pseudo-elements, pseudo-classes, and at-rules."
   (setq-local comment-continue " *")
   (setq-local comment-start-skip "/[*/]+[ \t]*")
   (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)")
-  (setq-local font-lock-defaults '(scss-font-lock-keywords nil t)))
+  (setq-local css--bang-ids (append css-bang-ids scss-bang-ids))
+  (setq-local font-lock-defaults
+              (list (scss-font-lock-keywords) nil t)))
 
 (provide 'css-mode)
 ;;; css-mode.el ends here