unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Simen Heggestøyl" <simenheg@gmail.com>
To: 20859@debbugs.gnu.org
Subject: bug#20859: 25.0.50; css-mode: Comments within URIs
Date: Sun, 21 Jun 2015 19:38:11 +0200	[thread overview]
Message-ID: <1434908291.13002.0@smtp.gmail.com> (raw)
In-Reply-To: <1434812678.1585.2@smtp.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1913 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2823 bytes --]

  reply	other threads:[~2015-06-21 17:38 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 [this message]
2015-06-22 15:54   ` Stefan Monnier
2015-06-22  1:13 ` Stefan Monnier
2015-08-21 21:08   ` Simen Heggestøyl
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=1434908291.13002.0@smtp.gmail.com \
    --to=simenheg@gmail.com \
    --cc=20859@debbugs.gnu.org \
    /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).