From: "Simen Heggestøyl" <simenheg@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 20859@debbugs.gnu.org
Subject: bug#20859: 25.0.50; css-mode: Comments within URIs
Date: Fri, 21 Aug 2015 23:08:09 +0200 [thread overview]
Message-ID: <1440191289.7669.0@smtp.gmail.com> (raw)
In-Reply-To: <jwvd20o4ktj.fsf-monnier+emacsbugs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 3212 bytes --]
On Mon, Jun 22, 2015 at 3:13 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
> There's also a real problem: how should we treat url(foo)bar) ?
I find the regexp
"url\\((\\)[[:space:]]*[^\"'\n[:space:]]+[[:space:]]*\\()\\)"
hungry enough to work for all of the following cases:
url(foobar);
url(foo)bar);
url(http://www.example.com/foo.html);
url('http://www.example.com/foo.html');
url("http://www.example.com/foo.html");
> Just like single quotes and double quotes are usually highlighted as
> part of the string. IOW, I think it's OK to highlight the parens as
> part of the string, tho only when the argument inside the parens is
> not
> itself wrapped in '...' or "...".
>
> So we should use a regexp that only matches when the contents of the
> parens is not quoted.
>
> If you really care about it you could add a font-lock-keyword which
> matches "url(...)" and overrides the face on the open and close
> parens.
Thanks for the tip, I'll do that.
In sum, the patch now looks like:
From 67e48674bf42faa20ee8571ecf84c4bdc48148a3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@gmail.com>
Date: Sat, 20 Jun 2015 17:17:31 +0200
Subject: [PATCH] Handle comments inside unquoted URIs in css-mode
* lisp/textmodes/css-mode.el (css--uri-re): New defconst.
(css-syntax-propertize-function): New function.
(css-mode): Set `syntax-propertize-function'.
---
lisp/textmodes/css-mode.el | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 424cdb7..1383420 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -198,6 +198,14 @@
(modify-syntax-entry ?- "_" st)
st))
+(eval-and-compile
+ (defconst css--uri-re
+ "url\\((\\)[[:space:]]*[^\"'\n[:space:]]+[[:space:]]*\\()\\)"))
+
+(defconst css-syntax-propertize-function
+ (syntax-propertize-rules
+ (css--uri-re (1 "|") (2 "|"))))
+
(defconst css-escapes-re
"\\\\\\(?:[^\000-\037\177]\\|[0-9a-fA-F]+[ \n\t\r\f]?\\)")
(defconst css-nmchar-re (concat "\\(?:[-[:alnum:]]\\|" css-escapes-re
"\\)"))
@@ -278,7 +286,13 @@
"\\(?:\\(" css-proprietary-nmstart-re "\\)\\|"
css-nmstart-re "\\)" css-nmchar-re "*"
"\\)\\s-*:")
- (1 (if (match-end 2) 'css-proprietary-property 'css-property)))))
+ (1 (if (match-end 2) 'css-proprietary-property 'css-property)))
+ ;; Make sure the parens in a url(...) expression receive the
+ ;; default face. This is done because the parens may sometimes
+ ;; receive generic string delimiter syntax (see
+ ;; `css-syntax-propertize-function').
+ (,css--uri-re
+ (1 'default t) (2 'default t))))
(defvar css-font-lock-keywords (css--font-lock-keywords))
@@ -381,6 +395,8 @@ pseudo-classes, and at-rules."
(setq-local comment-start-skip "/\\*+[ \t]*")
(setq-local comment-end "*/")
(setq-local comment-end-skip "[ \t]*\\*+/")
+ (setq-local syntax-propertize-function
+ css-syntax-propertize-function)
(setq-local fill-paragraph-function #'css-fill-paragraph)
(setq-local adaptive-fill-function #'css-adaptive-fill)
(setq-local add-log-current-defun-function #'css-current-defun-name)
--
2.5.0
[-- Attachment #2: Type: text/html, Size: 4617 bytes --]
next prev parent reply other threads:[~2015-08-21 21:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-20 15:04 bug#20859: 25.0.50; css-mode: Comments within URIs Simen Heggestøyl
2015-06-21 17:38 ` Simen Heggestøyl
2015-06-22 15:54 ` Stefan Monnier
2015-06-22 1:13 ` Stefan Monnier
2015-08-21 21:08 ` Simen Heggestøyl [this message]
2015-08-22 4:04 ` Stefan Monnier
2015-08-22 8:19 ` Simen Heggestøyl
2015-08-22 14:47 ` Stefan Monnier
2015-08-22 17:21 ` Simen Heggestøyl
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=1440191289.7669.0@smtp.gmail.com \
--to=simenheg@gmail.com \
--cc=20859@debbugs.gnu.org \
--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 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).