From: "Simen Heggestøyl" <simenheg@gmail.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: 13425@debbugs.gnu.org, Tom Tromey <tom@tromey.com>
Subject: bug#13425: close this bug?
Date: Thu, 02 Feb 2017 20:12:14 +0100 [thread overview]
Message-ID: <1486062734.11108.0@smtp.gmail.com> (raw)
In-Reply-To: <jwv1svlhh57.fsf-monnier+Inbox@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 123 bytes --]
Thanks for the hints, Stefan.
The attached patch seems sufficient in my tests. Do you see any
problems with it?
-- Simen
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-WIP.patch --]
[-- Type: text/x-patch, Size: 2854 bytes --]
From b2772f486ab833fc5221577811a5d517dfc77742 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Thu, 2 Feb 2017 20:05:32 +0100
Subject: [PATCH] WIP
---
lisp/textmodes/css-mode.el | 44 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 40 insertions(+), 4 deletions(-)
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 19f74daec6..65a599d6d4 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -32,10 +32,11 @@
;;; Code:
+(require 'eww)
(require 'seq)
(require 'sgml-mode)
(require 'smie)
-(require 'eww)
+(require 'subr-x)
(defgroup css nil
"Cascading Style Sheets (CSS) editing mode."
@@ -741,7 +742,30 @@ css-indent-offset
(defconst css-smie-grammar
(smie-prec2->grammar
- (smie-precs->prec2 '((assoc ";") (assoc ",") (left ":")))))
+ (smie-precs->prec2
+ '((assoc ";")
+ ;; Colons that belong to a CSS property. These get a higher
+ ;; precedence than other colons, such as colons in selectors,
+ ;; which are represented by a plain ":" token.
+ (left ":-property")
+ (assoc ",")
+ (assoc ":")))))
+
+(defun css--colon-inside-selector-p ()
+ "Return t if point looks to be inside a CSS selector.
+This function is intended to be good enough to help SMIE during
+tokenization, but should not be regarded as a reliable function
+for determining wheter point is within a selector."
+ (save-excursion
+ (re-search-forward "[{};)]" nil t)
+ (eq (char-before) ?\{)))
+
+(defun css--colon-inside-funcall ()
+ "Return t if point is inside a function call."
+ (when-let (opening-paren-pos (nth 1 (syntax-ppss)))
+ (save-excursion
+ (goto-char opening-paren-pos)
+ (eq (char-after) ?\())))
(defun css-smie--forward-token ()
(cond
@@ -755,7 +779,13 @@ css-smie--forward-token
";")
((progn (forward-comment (point-max))
(looking-at "[;,:]"))
- (forward-char 1) (match-string 0))
+ (forward-char 1)
+ (if (equal (match-string 0) ":")
+ (if (or (css--colon-inside-selector-p)
+ (css--colon-inside-funcall))
+ ":"
+ ":-property")
+ (match-string 0)))
(t (smie-default-forward-token))))
(defun css-smie--backward-token ()
@@ -766,7 +796,13 @@ css-smie--backward-token
((and (eq (char-before) ?\}) (scss-smie--not-interpolation-p)
(> pos (point))) ";")
((memq (char-before) '(?\; ?\, ?\:))
- (forward-char -1) (string (char-after)))
+ (forward-char -1)
+ (if (eq (char-after) ?\:)
+ (if (or (css--colon-inside-selector-p)
+ (css--colon-inside-funcall))
+ ":"
+ ":-property")
+ (string (char-after))))
(t (smie-default-backward-token)))))
(defun css-smie-rules (kind token)
--
2.11.0
next prev parent reply other threads:[~2017-02-02 19:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-13 7:43 bug#13425: new css-mode indenter E Sabof
2013-01-15 5:00 ` Stefan Monnier
2013-01-15 19:32 ` E Sabof
2013-01-17 0:17 ` E Sabof
2017-01-25 23:06 ` bug#13425: close this bug? Tom Tromey
2017-01-29 14:01 ` Simen Heggestøyl
2017-01-29 17:16 ` Stefan Monnier
2017-01-29 17:38 ` Simen Heggestøyl
2017-01-29 18:15 ` Stefan Monnier
2017-02-02 19:12 ` Simen Heggestøyl [this message]
2017-02-03 0:02 ` Stefan Monnier
2017-02-04 19:31 ` Simen Heggestøyl
2017-01-30 22:17 ` Tom Tromey
2017-01-30 22:28 ` Stefan Monnier
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1486062734.11108.0@smtp.gmail.com \
--to=simenheg@gmail.com \
--cc=13425@debbugs.gnu.org \
--cc=monnier@IRO.UMontreal.CA \
--cc=tom@tromey.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).