* bug#23135: [PATCH] Support completion of bang-rules in CSS mode
@ 2016-03-28 12:52 Simen Heggestøyl
2016-03-28 15:16 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Simen Heggestøyl @ 2016-03-28 12:52 UTC (permalink / raw)
To: 23135; +Cc: Stefan Monnier
[-- Attachment #1.1: Type: text/plain, Size: 120 bytes --]
The attached patch adds support for completing bang-rules (rules that
start with "!") in CSS and SCSS mode.
-- Simen
[-- Attachment #1.2: Type: text/html, Size: 177 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-completion-of-bang-rules-in-CSS-mode.patch --]
[-- Type: text/x-patch, Size: 3056 bytes --]
From f33af8dcfa5b46a50f8baef880c5cc52d2e64e54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Mon, 28 Mar 2016 14:31:49 +0200
Subject: [PATCH] Support completion of bang-rules in CSS mode
lisp/textmodes/css-mode.el (css--complete-bang-rule): New function for
completing a bang-rule.
(css-completion-at-point): Add support for completing bang-rules.
(scss-mode): Include Sass-specific completion rules.
---
etc/NEWS | 4 ++--
lisp/textmodes/css-mode.el | 21 ++++++++++++++++++---
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index ce21532..e4fdfa7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -136,8 +136,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
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index fd3459e..6c70759 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -732,6 +732,15 @@ css--complete-property
(when (memq (char-before) '(?\{ ?\;))
(list start pos css-property-ids))))))
+(defun css--complete-bang-rule (&optional sassy)
+ "Complete (optionally SASSY) CSS bang-rule at point."
+ (save-excursion
+ (let ((pos (point)))
+ (skip-chars-backward "-[:alnum:]")
+ (when (eq (char-before) ?\!)
+ (list (point) pos (append (if sassy scss-bang-ids)
+ css-bang-ids))))))
+
(defun css--complete-pseudo-element-or-class ()
"Complete pseudo-element or pseudo-class at point."
(save-excursion
@@ -795,11 +804,13 @@ css--complete-property-value
(list (point) end
(cons "inherit" (css--property-values property))))))))
-(defun css-completion-at-point ()
+(defun css-completion-at-point (&optional sassy)
"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.
+SCSS-specific completions are included when SASSY is non-nil."
(or (css--complete-property)
+ (css--complete-bang-rule sassy)
(css--complete-property-value)
(css--complete-pseudo-element-or-class)
(css--complete-at-rule)))
@@ -958,7 +969,11 @@ scss-mode
(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 font-lock-defaults '(scss-font-lock-keywords nil t))
+ (remove-hook 'completion-at-point-functions
+ #'css-completion-at-point t)
+ (add-hook 'completion-at-point-functions
+ (lambda () (css-completion-at-point 'sassy)) nil 'local))
(provide 'css-mode)
;;; css-mode.el ends here
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#23135: [PATCH] Support completion of bang-rules in CSS mode
2016-03-28 12:52 bug#23135: [PATCH] Support completion of bang-rules in CSS mode Simen Heggestøyl
@ 2016-03-28 15:16 ` Stefan Monnier
2016-03-30 16:33 ` Simen Heggestøyl
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2016-03-28 15:16 UTC (permalink / raw)
To: Simen Heggestøyl; +Cc: 23135
> The attached patch adds support for completing bang-rules (rules that
> start with "!") in CSS and SCSS mode.
Looks fine, thanks.
> + (list (point) pos (append (if sassy scss-bang-ids)
> + css-bang-ids))))))
This duplicates code that's already elsewhere. Maybe we should have
a new buffer-local var to keep the (s)css-bang-ids value appropriate for
the current mode.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#23135: [PATCH] Support completion of bang-rules in CSS mode
2016-03-28 15:16 ` Stefan Monnier
@ 2016-03-30 16:33 ` Simen Heggestøyl
2016-03-30 21:06 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Simen Heggestøyl @ 2016-03-30 16:33 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 23135
[-- Attachment #1.1: Type: text/plain, Size: 409 bytes --]
On Mon, Mar 28, 2016 at 5:16 PM, Stefan Monnier
<monnier@IRO.UMontreal.CA> wrote:
>> + (list (point) pos (append (if sassy scss-bang-ids)
>> + css-bang-ids))))))
>
> This duplicates code that's already elsewhere. Maybe we should have
> a new buffer-local var to keep the (s)css-bang-ids value appropriate
> for
> the current mode.
Something like this?
-- Simen
[-- Attachment #1.2: Type: text/html, Size: 558 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-completion-of-bang-rules-in-CSS-mode.patch --]
[-- Type: text/x-patch, Size: 4221 bytes --]
From 97b8d72f5fd8211d7244089c8fa1a1f2226ced0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Mon, 28 Mar 2016 14:31:49 +0200
Subject: [PATCH] Support completion of bang-rules in CSS mode
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): Include SCSS-specific completion rules.
---
etc/NEWS | 4 ++--
lisp/textmodes/css-mode.el | 25 +++++++++++++++++++------
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 66777e9..726b4b9 100644
--- 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
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index fd3459e..cbef3d4 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -64,6 +64,10 @@ scss-bang-ids
'("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 @@ css-proprietary-property
"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 @@ css--complete-property
(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 @@ css--complete-property-value
(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 @@ scss-mode-syntax-table
(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 @@ scss-mode
(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
--
2.8.0.rc3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#23135: [PATCH] Support completion of bang-rules in CSS mode
2016-03-30 16:33 ` Simen Heggestøyl
@ 2016-03-30 21:06 ` Stefan Monnier
2016-03-31 19:23 ` Simen Heggestøyl
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2016-03-30 21:06 UTC (permalink / raw)
To: Simen Heggestøyl; +Cc: 23135
> Something like this?
Looks good to me,
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#23135: [PATCH] Support completion of bang-rules in CSS mode
2016-03-30 21:06 ` Stefan Monnier
@ 2016-03-31 19:23 ` Simen Heggestøyl
0 siblings, 0 replies; 5+ messages in thread
From: Simen Heggestøyl @ 2016-03-31 19:23 UTC (permalink / raw)
To: 23135-done
[-- Attachment #1: Type: text/plain, Size: 31 bytes --]
Installed in master.
-- Simen
[-- Attachment #2: Type: text/html, Size: 54 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-03-31 19:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-28 12:52 bug#23135: [PATCH] Support completion of bang-rules in CSS mode Simen Heggestøyl
2016-03-28 15:16 ` Stefan Monnier
2016-03-30 16:33 ` Simen Heggestøyl
2016-03-30 21:06 ` Stefan Monnier
2016-03-31 19:23 ` Simen Heggestøyl
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.