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

Previous Next

Package: emacs;

Reported by: Simen Heggestøyl <simenheg <at> gmail.com>

Date: Sat, 4 Apr 2015 13:51:02 UTC

Severity: minor

Found in version 25.0.50

Done: Simen Heggestøyl <simenheg <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #17 received at 20256 <at> debbugs.gnu.org (full text, mbox):

From: Simen Heggestøyl <simenheg <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 20256 <at> debbugs.gnu.org
Subject: Re: bug#20256: 25.0.50; css-mode: filling multi-line comments
Date: Fri, 10 Apr 2015 20:45:50 +0200
[Message part 1 (text/plain, inline)]
> As mentioned, I think this had better be a buffer-local setting, 
> rather
> than a let-binding.  After all, it would be good if it also works for
> auto-fill-mode.

Ah, thanks, I missed that. An updated patch follows. It defines
`css-adaptive-fill' buffer-locally, which makes `auto-fill-mode'
behave nice. `css-fill-paragraph' should now be general again.


From 4e46637ceeab0a0a266cac035204f6db798fbd38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg <at> gmail.com>
Date: Thu, 9 Apr 2015 19:09:04 +0200
Subject: [PATCH] css-mode.el: Support multi-line comment filling

Fixes: debbugs:20256

* lisp/textmodes/css-mode.el (css-fill-paragraph): Support multi-line
comment filling.
(css-adaptive-fill): New function.
(css-mode): Set `adaptive-fill-function'.
(scss-fill-paragraph): New function.
(scss-mode): Set `fill-paragraph-function'.
---
lisp/textmodes/css-mode.el | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index d1893a3..b4de1a5 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -381,7 +381,8 @@ 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 adaptive-fill-function #'css-adaptive-fill)
  (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 +396,12 @@ pseudo-classes, and at-rules."

(defun css-fill-paragraph (&optional justify)
  (save-excursion
+    ;; Fill succeeding comment when invoked right before a multi-line
+    ;; comment.
+    (when (save-excursion
+            (back-to-indentation)
+            (looking-at (regexp-quote comment-start)))
+      (goto-char (match-end 0)))
    (let ((ppss (syntax-ppss))
          (eol (line-end-position)))
      (cond
@@ -414,7 +421,10 @@ pseudo-classes, and at-rules."
                (paragraph-separate
                 (if (and comment-continue
                          (string-match "[^ \t]" comment-continue))
-                     (concat "\\(?:[ \t]*" (regexp-quote 
comment-continue)
+                     (concat "\\(?:[ \t]*"
+                             (regexp-opt
+                              (list comment-continue comment-start
+                                    comment-end))
                             "\\)?\\(?:" paragraph-separate "\\)")
                   paragraph-separate))
                (paragraph-start
@@ -468,6 +478,12 @@ pseudo-classes, and at-rules."
            ;; Don't use the default filling code.
            t)))))))

+(defun css-adaptive-fill ()
+  (when (looking-at "[ \t]*/\\*[ \t]*")
+    (let ((str (match-string 0)))
+      (and (string-match "/\\*" str)
+           (replace-match " *" t t str)))))
+
(defun css-current-defun-name ()
  "Return the name of the CSS section at point, or nil."
  (save-excursion
@@ -506,7 +522,17 @@ pseudo-classes, and at-rules."
  (setq-local comment-end "")
  (setq-local comment-start-skip "/[*/]+[ \t]*")
  (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)")
+  (setq-local fill-paragraph-function #'scss-fill-paragraph)
  (setq-local font-lock-defaults '(scss-font-lock-keywords nil t)))

+(defun scss-fill-paragraph (&optional justify)
+  "Call `css-fill-paragraph', but ensure that the 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 "*/"))
+    (css-fill-paragraph justify)))
+
(provide 'css-mode)
;;; css-mode.el ends here
-- 
2.1.4


[Message part 2 (text/html, inline)]

This bug report was last modified 10 years and 21 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.