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: Sun, 21 Jun 2015 19:38:11 +0200

I think I found a solution, by applying the string syntax class to the
whole URI.

Please consider the following patch:


From 69e4a7635f17dd2b5cb773b9088d154687a75b44 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

* css-mode.el (css-syntax-propertize-function): New function.
(css-mode): Set `syntax-propertize-function'.  (Bug#20859)
---
 lisp/textmodes/css-mode.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 424cdb7..9ffaa0a 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -198,6 +198,18 @@
     (modify-syntax-entry ?- "_" st)
     st))
 
+(defun css-syntax-propertize-function (start end)
+  (save-excursion
+    (goto-char start)
+    ;; Allow comment starters to appear inside unquoted URIs, such as
+    ;; url(http://www.example.com/*/).
+    (while (re-search-forward
+            "url\([[:space:]]*\\([^\"'\n[:space:]]+\\)[[:space:]]*\)"
+            end t)
+      (add-text-properties
+       (match-beginning 1) (match-end 1)
+       '(syntax-table (2) font-lock-face font-lock-string-face)))))
+
 (defconst css-escapes-re
   "\\\\\\(?:[^\000-\037\177]\\|[0-9a-fA-F]+[ \n\t\r\f]?\\)")
 (defconst css-nmchar-re (concat "\\(?:[-[:alnum:]]\\|" css-escapes-re "\\)"))
@@ -381,6 +393,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.1.4

reply via email to

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