bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20859: 25.0.50; css-mode: Comments within URIs


From: Simen Heggestøyl
Subject: bug#20859: 25.0.50; css-mode: Comments within URIs
Date: Fri, 21 Aug 2015 23:08:09 +0200

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]