bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20256: 25.0.50; css-mode: filling multi-line comments


From: Stefan Monnier
Subject: bug#20256: 25.0.50; css-mode: filling multi-line comments
Date: Tue, 07 Apr 2015 14:26:51 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

> From this comment in `css-fill-paragraph', it sounds like it is
> supposed to work, or has been working some time before:

>  ;; Filling inside a comment whose comment-end marker is not \n.
>  ;; This code is meant to be generic, so that it works not only for
>  ;; css-mode but for all modes.

> Could someone fill me in?

It is "work in progress", so it does work in some cases (e.g. if you
add a "*" line as in:

 /*
  *
  * Multi-line comment here.
  * This comment spans
  * multiple
  * lines.
  * Better fill it!
  */

).  The patch below seems to fix one half of the problem (tho it's
probably better to set adaptive-fill-function buffer-locally rather
than let-bind it, this was just a quick-hack).  Tweaking the
paragraph-separate regexp (so as to recognize the "/*" line as
a paragraph separator) should let you fix the second.


        Stefan


diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 7280080..c09245d 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -377,7 +377,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
@@ -418,7 +418,13 @@ pseudo-classes, and at-rules."
                           (string-match "[^ \t]" comment-continue))
                      (concat "\\(?:[ \t]*" (regexp-quote comment-continue)
                              "\\)?\\(?:" paragraph-start "\\)")
-                   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)))





reply via email to

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