all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Simen Heggestøyl" <simenheg@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 20256@debbugs.gnu.org
Subject: bug#20256: 25.0.50; css-mode: filling multi-line comments
Date: Thu, 09 Apr 2015 20:51:06 +0200	[thread overview]
Message-ID: <1428605466.1765.0@smtp.gmail.com> (raw)
In-Reply-To: <jwvr3rvresl.fsf-monnier+emacsbugs@gnu.org>

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

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?= <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-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

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

  reply	other threads:[~2015-04-09 18:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-04 13:12 bug#20256: 25.0.50; css-mode: filling multi-line comments Simen Heggestøyl
2015-04-07 18:26 ` Stefan Monnier
2015-04-09 18:51   ` Simen Heggestøyl [this message]
2015-04-10  1:25     ` Stefan Monnier
2015-04-10 18:45       ` Simen Heggestøyl
2015-04-13 14:28         ` Stefan Monnier
2015-04-18 10:02           ` Simen Heggestøyl
2015-04-18 14:06             ` Stefan Monnier
2015-04-18 18:33               ` Simen Heggestøyl
2015-04-20 16:09                 ` Stefan Monnier
2015-04-21 19:08                   ` Simen Heggestøyl
2015-04-21 20:26                     ` Stefan Monnier
2015-04-26 20:56                   ` Simen Heggestøyl
2015-04-27  4:11                     ` Stefan Monnier
2015-04-27 20:32                       ` Simen Heggestøyl
2015-04-27 22:46                         ` Stefan Monnier

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428605466.1765.0@smtp.gmail.com \
    --to=simenheg@gmail.com \
    --cc=20256@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.