From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Newsgroups: gmane.emacs.bugs Subject: bug#20859: 25.0.50; css-mode: Comments within URIs Date: Fri, 21 Aug 2015 23:08:09 +0200 Message-ID: <1440191289.7669.0@smtp.gmail.com> References: <1434812678.1585.2@smtp.gmail.com> <1434812678.1585.2@smtp.gmail.com> <"Simen =?UTF-8?Q?Heggest=C3=B8=3D=3FISO-8859-1=3FQ=3Fyl?="'s_message_of_"Sat, _20_Jun_2015_17:04:38_+0200"> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=-LEwgLxEhkScJdcLt8zTl" X-Trace: ger.gmane.org 1440191371 20843 80.91.229.3 (21 Aug 2015 21:09:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 21 Aug 2015 21:09:31 +0000 (UTC) Cc: 20859@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 21 23:09:13 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZStYm-0007xP-2b for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Aug 2015 23:09:12 +0200 Original-Received: from localhost ([::1]:44095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZStYl-0007Y4-8Q for geb-bug-gnu-emacs@m.gmane.org; Fri, 21 Aug 2015 17:09:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZStYf-0007UX-Cj for bug-gnu-emacs@gnu.org; Fri, 21 Aug 2015 17:09:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZStYc-0006bl-5F for bug-gnu-emacs@gnu.org; Fri, 21 Aug 2015 17:09:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZStYb-0006be-V6 for bug-gnu-emacs@gnu.org; Fri, 21 Aug 2015 17:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZStYb-0003Ay-Nw for bug-gnu-emacs@gnu.org; Fri, 21 Aug 2015 17:09:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 21 Aug 2015 21:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20859 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20859-submit@debbugs.gnu.org id=B20859.144019129612109 (code B ref 20859); Fri, 21 Aug 2015 21:09:01 +0000 Original-Received: (at 20859) by debbugs.gnu.org; 21 Aug 2015 21:08:16 +0000 Original-Received: from localhost ([127.0.0.1]:34795 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZStXr-00039D-6v for submit@debbugs.gnu.org; Fri, 21 Aug 2015 17:08:15 -0400 Original-Received: from mail-lb0-f181.google.com ([209.85.217.181]:35391) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZStXo-000392-VE for 20859@debbugs.gnu.org; Fri, 21 Aug 2015 17:08:13 -0400 Original-Received: by lbcbn3 with SMTP id bn3so50845043lbc.2 for <20859@debbugs.gnu.org>; Fri, 21 Aug 2015 14:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:subject:to:cc:message-id:in-reply-to:references :mime-version:content-type; bh=DdahFug3ekvtkbNug1Mm7QcmmmI5Pp8SWfqrBIgWgRg=; b=FBcC0itbl/bdyMAyqoxnT1UfRhdyivhETkJzPKBy4R9vfS19ikvt+MGFNJuNq5ZNwB RbgTLZu0ZwrjSnZMOky6OqiTHZfP9fbVX87BYG0nhk/QIjAaUg/aZ1O8QNFGVKLBbgIN Na78mmuc458zYDFJlyD4UU8QiEmpq9LELwu2qmzbsxpLmiANgkDpcQKvxcEYWv0334CU hBVqCAiVcG5/9HWc3e3J/rj8cUtocLauybiYWQS1qlWFuezPe8TkQO0j/L0I+qBHYIiS v/D/AATulvVmgO2XNRSdRMmnbcowCdRRulX4hTIpNaMViJpSpMhzfB9BdlPKJjf85HaR ZfdA== X-Received: by 10.152.23.103 with SMTP id l7mr9558922laf.50.1440191292220; Fri, 21 Aug 2015 14:08:12 -0700 (PDT) Original-Received: from [192.168.100.7] (cm-84.210.143.4.getinternet.no. [84.210.143.4]) by smtp.gmail.com with ESMTPSA id b5sm2630770laa.34.2015.08.21.14.08.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Aug 2015 14:08:11 -0700 (PDT) In-Reply-To: X-Mailer: geary/0.10.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:105682 Archived-At: --=-LEwgLxEhkScJdcLt8zTl Content-Type: text/plain; charset=utf-8; format=flowed On Mon, Jun 22, 2015 at 3:13 AM, Stefan Monnier 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?= 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 --=-LEwgLxEhkScJdcLt8zTl Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Jun 22, 2015 at 3:13 AM, Stefan Monnier <monnier@iro.umontreal.c= a> wrote:
There's also a real problem: how should we treat u= rl(foo)bar) ?

I find the regexp = "url\\((\\)[[:space:]]*[^\"'\n[:space:]]+[[:space:]]*\\()\\)"
hun= gry enough to work for all of the following cases:

url(foobar);
url(foo)bar);
url('<= a href=3D"http://www.example.com/foo.html">http://www.example.com/foo.html<= /a>');

Just like single quot= es 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 20= 01
From: =3D?UTF-8?q?Simen=3D20Heggest=3DC3=3DB8yl?=3D <simenh= eg@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-mod= e): Set `syntax-propertize-function'.
---
 lisp/te= xtmodes/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:]]+[[:spac= e:]]*\\()\\)"))
+
+(defconst css-syntax-propertize-func= tion
+ (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-e= scapes-re "\\)"))
@@ -278,7 +286,13 @@
    &n= bsp;          "\\(?:\\(" css-proprietary-nmstart-r= e "\\)\\|"
               = ;css-nmstart-re "\\)" css-nmchar-re "*"
      &nbs= p;        "\\)\\s-*:")
- (1 (if (match-en= d 2) 'css-proprietary-property 'css-property)))))
+ (1 (if (m= atch-end 2) 'css-proprietary-property 'css-property)))
+ ;; Ma= ke sure the parens in a url(...) expression receive the
+ ;; d= efault face. This is done because the parens may sometimes
+ ;= ; receive generic string delimiter syntax (see
+ ;; `css-synta= x-propertize-function').
+ (,css--uri-re
+ (1 'd= efault t) (2 'default t))))
 
 (defvar css-fo= nt-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-l= ocal fill-paragraph-function #'css-fill-paragraph)
   (= setq-local adaptive-fill-function #'css-adaptive-fill)
  &nb= sp;(setq-local add-log-current-defun-function #'css-current-defun-name)
-- 
2.5.0

= --=-LEwgLxEhkScJdcLt8zTl--