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#20256: 25.0.50; css-mode: filling multi-line comments Date: Thu, 09 Apr 2015 20:51:06 +0200 Message-ID: <1428605466.1765.0@smtp.gmail.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=-UTrYruy4sT+6NKuISpW5" X-Trace: ger.gmane.org 1428605543 16473 80.91.229.3 (9 Apr 2015 18:52:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 9 Apr 2015 18:52:23 +0000 (UTC) Cc: 20256@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Apr 09 20:52:12 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 1YgHYg-0002hm-RC for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Apr 2015 20:52:11 +0200 Original-Received: from localhost ([::1]:36121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YgHYg-0008Nl-58 for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Apr 2015 14:52:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YgHYb-0008Nd-VQ for bug-gnu-emacs@gnu.org; Thu, 09 Apr 2015 14:52:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YgHYY-0002RK-NU for bug-gnu-emacs@gnu.org; Thu, 09 Apr 2015 14:52:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:33469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YgHYY-0002RB-J8 for bug-gnu-emacs@gnu.org; Thu, 09 Apr 2015 14:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YgHYX-0007qK-W3 for bug-gnu-emacs@gnu.org; Thu, 09 Apr 2015 14:52:02 -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: Thu, 09 Apr 2015 18:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20256 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20256-submit@debbugs.gnu.org id=B20256.142860547930073 (code B ref 20256); Thu, 09 Apr 2015 18:52:01 +0000 Original-Received: (at 20256) by debbugs.gnu.org; 9 Apr 2015 18:51:19 +0000 Original-Received: from localhost ([127.0.0.1]:51478 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YgHXq-0007oy-CH for submit@debbugs.gnu.org; Thu, 09 Apr 2015 14:51:19 -0400 Original-Received: from mail-lb0-f179.google.com ([209.85.217.179]:34843) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YgHXn-0007oi-T8 for 20256@debbugs.gnu.org; Thu, 09 Apr 2015 14:51:16 -0400 Original-Received: by lbbuc2 with SMTP id uc2so94719106lbb.2 for <20256@debbugs.gnu.org>; Thu, 09 Apr 2015 11:51:10 -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=PT4pVVg/LF+WrfA5xaoz8bqXf+7DCKgOs1GkxRXNVFY=; b=KofK5UbFHLa8i9maqCyTmW6mrm64WlpZn1yiA7tOSgPx1+zffQ6U+9JvW8qcfAz2qH qpzJEfODx9qBSjWZJ48Cdx3ixebkpYL3+3IK2fakTtUOzlrGysUplSUeSWrTI4gsFrEe M17dg6MiajtHM4lzn+pZPJYARyGSmS0u0qYOIP1hpsMqYwjUfHNb6nwJXcjMJXWCiTsH 9+Ud8jbdQY4wwAQaDb/jZoHMIMWFu25NuoLx4WrRHJESppH5A8soA2EHQa48d1JEtavE h+iWgJIQkUbiFIp43fRz4fVFhiDviIsIbYYO68sRUu9ZfFY48dN7fSi89Mp0kghjbINN nQgQ== X-Received: by 10.112.210.230 with SMTP id mx6mr29539260lbc.64.1428605469951; Thu, 09 Apr 2015 11:51:09 -0700 (PDT) Original-Received: from [192.168.1.114] (cm-84.215.44.110.getinternet.no. [84.215.44.110]) by mx.google.com with ESMTPSA id tp10sm2714673lbb.4.2015.04.09.11.51.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 11:51:09 -0700 (PDT) In-Reply-To: X-Mailer: geary/0.8.2 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: 140.186.70.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:101348 Archived-At: --=-UTrYruy4sT+6NKuISpW5 Content-Type: text/plain; charset=utf-8; format=flowed Thanks for the hints, Stefan! The following patch seems to work well for me, both with css-mode and scss-mode: From 16b46e34bb3e0e69a039e4ed0737013aa9a06f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Thu, 9 Apr 2015 19:09:04 +0200 Subject: [PATCH] css-mode.el: Support multi-line comment filling Fixes: debbugs:20256 * css-mode.el (css-fill-paragraph): Support multi-line comment filling. --- lisp/textmodes/css-mode.el | 57 ++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 851618c..f452e17 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -381,7 +381,7 @@ pseudo-classes, and at-rules." (setq-local comment-start-skip "/\\*+[ \t]*") (setq-local comment-end "*/") (setq-local comment-end-skip "[ \t]*\\*+/") - (setq-local fill-paragraph-function 'css-fill-paragraph) + (setq-local fill-paragraph-function #'css-fill-paragraph) (setq-local add-log-current-defun-function #'css-current-defun-name) (smie-setup css-smie-grammar #'css-smie-rules :forward-token #'css-smie--forward-token @@ -395,6 +395,10 @@ pseudo-classes, and at-rules." (defun css-fill-paragraph (&optional justify) (save-excursion + ;; Fill succeeding comment when invoked at the beginning of a + ;; multi-line comment. + (when (save-excursion (back-to-indentation) (looking-at "/\\*")) + (skip-chars-forward " \t/*")) (let ((ppss (syntax-ppss)) (eol (line-end-position))) (cond @@ -408,24 +412,39 @@ pseudo-classes, and at-rules." ;; This code is meant to be generic, so that it works not only for ;; css-mode but for all modes. (save-restriction - (narrow-to-region (nth 8 ppss) eol) - (comment-normalize-vars) ;Will define comment-continue. - (let ((fill-paragraph-function nil) - (paragraph-separate - (if (and comment-continue - (string-match "[^ \t]" comment-continue)) - (concat "\\(?:[ \t]*" (regexp-quote comment-continue) - "\\)?\\(?:" paragraph-separate "\\)") - paragraph-separate)) - (paragraph-start - (if (and comment-continue - (string-match "[^ \t]" comment-continue)) - (concat "\\(?:[ \t]*" (regexp-quote comment-continue) - "\\)?\\(?:" paragraph-start "\\)") - paragraph-start))) - (fill-paragraph justify) - ;; Don't try filling again. - t))) + ;; Ensure that multi-line variants of `comment-start' and + ;; `comment-end' are in use, in order to support multi-line + ;; comment filling in SCSS mode as well. + (let ((comment-start "/*") + (comment-end "*/")) + (narrow-to-region (nth 8 ppss) eol) + (comment-normalize-vars) ;Will define comment-continue. + (let ((fill-paragraph-function nil) + (paragraph-separate + (if (and comment-continue + (string-match "[^ \t]" comment-continue)) + (concat "\\(?:[ \t]*" + (regexp-opt + (list comment-continue comment-start + comment-end)) + "\\)?\\(?:" paragraph-separate "\\)") + paragraph-separate)) + (paragraph-start + (if (and comment-continue + (string-match "[^ \t]" comment-continue)) + (concat "\\(?:[ \t]*" + (regexp-quote comment-continue) + "\\)?\\(?:" paragraph-start "\\)") + paragraph-start)) + (adaptive-fill-function + (lambda () + (when (looking-at "[ \t]*/\\*[ \t]*") + (let ((str (match-string 0))) + (and (string-match "/\\*" str) + (replace-match " *" t t str))))))) + (fill-paragraph justify) + ;; Don't try filling again. + t)))) ((and (null (nth 8 ppss)) (or (nth 1 ppss) -- 2.1.4 --=-UTrYruy4sT+6NKuISpW5 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Thanks for the hints, Stefan!

The following patch s= eems to work well for me, both with css-mode and
scss-mode:
=


From 16b46e34bb3e0e69a039e4ed= 0737013aa9a06f86 Mon Sep 17 00:00:00 2001
From: =3D?UTF-8?q?Simen= =3D20Heggest=3DC3=3DB8yl?=3D <simenheg@gmail.com>
Date: Thu= , 9 Apr 2015 19:09:04 +0200
Subject: [PATCH] css-mode.el: Support= multi-line comment filling

Fixes: debbugs:20256

* css-mode.el (css-fill-paragraph): Support multi-l= ine comment
filling.
---
 lisp/textmodes= /css-mode.el | 57 ++++++++++++++++++++++++++++++----------------
=  1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el<= /div>
index 851618c..f452e17 100644
--- a/lisp/textmodes/css-= mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -381,7 +381= ,7 @@ pseudo-classes, and at-rules."
   (setq-local com= ment-start-skip "/\\*+[ \t]*")
   (setq-local comment-e= nd "*/")
   (setq-local comment-end-skip "[ \t]*\\*+/")=
-  (setq-local fill-paragraph-function 'css-fill-paragraph)=
+  (setq-local fill-paragraph-function #'css-fill-paragraph= )
   (setq-local add-log-current-defun-function #'css-c= urrent-defun-name)
   (smie-setup css-smie-grammar #'cs= s-smie-rules
              &nb= sp;:forward-token #'css-smie--forward-token
@@ -395,6 +395,10 @@ = pseudo-classes, and at-rules."
 
 (defun css-= fill-paragraph (&optional justify)
   (save-excursi= on
+    ;; Fill succeeding comment when invoked at the = beginning of a
+    ;; multi-line comment.
+ =    (when (save-excursion (back-to-indentation) (looking-at "/\\*"= ))
+      (skip-chars-forward " \t/*"))
=      (let ((ppss (syntax-ppss))
    &nbs= p;      (eol (line-end-position)))
    &= nbsp;  (cond
@@ -408,24 +412,39 @@ pseudo-classes, and at-ru= les."
         ;; This code is meant to = be generic, so that it works not only for
      &n= bsp;  ;; css-mode but for all modes.
      &n= bsp;  (save-restriction
-          = (narrow-to-region (nth 8 ppss) eol)
-        =  (comment-normalize-vars)      ;Will define comment-co= ntinue.
-          (let ((fill-paragraph= -function nil)
-              =  (paragraph-separate
-           &= nbsp;     (if (and comment-continue
-     &nb= sp;                    (s= tring-match "[^ \t]" comment-continue))
-       &n= bsp;             (concat "\\(?:[ \t]*" (regex= p-quote comment-continue)
-           &n= bsp;                 "\\)?\\(?:" pa= ragraph-separate "\\)")
-           &nbs= p;       paragraph-separate))
-     &nbs= p;          (paragraph-start
-   &n= bsp;             (if (and comment-continue
-                   &n= bsp;      (string-match "[^ \t]" comment-continue))
-                     (= concat "\\(?:[ \t]*" (regexp-quote comment-continue)
-   &nb= sp;                     &= nbsp;   "\\)?\\(?:" paragraph-start "\\)")
-     &= nbsp;             paragraph-start)))
-            (fill-paragraph justify)
=
-            ;; Don't try filling again.=
-            t)))
+ &nbs= p;        ;; Ensure that multi-line variants of `commen= t-start' and
+          ;; `comment-end'= are in use, in order to support multi-line
+      = ;    ;; comment filling in SCSS mode as well.
+   =        (let ((comment-start "/*")
+   &n= bsp;            (comment-end "*/"))
+            (narrow-to-region (nth 8 ppss) = eol)
+            (comment-normaliz= e-vars)    ;Will define comment-continue.
+   &nbs= p;        (let ((fill-paragraph-function nil)
+                  (paragraph= -separate
+               &nbs= p;   (if (and comment-continue
+        =                    (stri= ng-match "[^ \t]" comment-continue))
+        = ;               (concat "\\(?:[ \t]*"
+                   &n= bsp;           (regexp-opt
+   &nbs= p;                     &n= bsp;      (list comment-continue comment-start
+ &= nbsp;                    =                comment-end))
=
+                    = ;           "\\)?\\(?:" paragraph-separate "\\)")<= /div>
+                   =   paragraph-separate))
+           =        (paragraph-start
+      = ;             (if (and comment-continue
=
+                    = ;        (string-match "[^ \t]" comment-continue))
+                   &nbs= p;   (concat "\\(?:[ \t]*"
+         &nb= sp;                     (= regexp-quote comment-continue)
+         &nbs= p;                     "\= \)?\\(?:" paragraph-start "\\)")
+         &n= bsp;           paragraph-start))
+  = ;                (adaptive-fill-fun= ction
+                 &= nbsp; (lambda ()
+             &nbs= p;       (when (looking-at "[ \t]*/\\*[ \t]*")
+ &= nbsp;                    = (let ((str (match-string 0)))
+         &nbs= p;               (and (string-match "/\\= *" str)
+                =              (replace-match " *" t t st= r)))))))
+              (fill-= paragraph justify)
+             &n= bsp;;; Don't try filling again.
+         &nb= sp;    t))))
 
      &nbs= p; ((and (null (nth 8 ppss))
          &= nbsp;   (or (nth 1 ppss)
-- 
2.1.4
= --=-UTrYruy4sT+6NKuISpW5--