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: Sat, 18 Apr 2015 12:02:30 +0200	[thread overview]
Message-ID: <1429351350.28233.1@smtp.gmail.com> (raw)
In-Reply-To: <jwvh9skm7r0.fsf-monnier+emacsbugs@gnu.org>

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

Thanks again for the feedback, Stefan! An updated patch follows.

-- Simen


 From 839810c2fc79d64634be2d27148df9f0759e1c8b 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

* 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-mode): Set `comment-continue'.
---
 lisp/textmodes/css-mode.el | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index d1893a3..424cdb7 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
+            (beginning-of-line)
+            (comment-search-forward (point-at-eol) t))
+      (goto-char (match-end 0)))
     (let ((ppss (syntax-ppss))
           (eol (line-end-position)))
       (cond
@@ -414,8 +421,11 @@ pseudo-classes, and at-rules."
                 (paragraph-separate
                  (if (and comment-continue
                           (string-match "[^ \t]" comment-continue))
-                     (concat "\\(?:[ \t]*" (regexp-quote 
comment-continue)
-                             "\\)?\\(?:" paragraph-separate "\\)")
+                     (concat "\\(?:[ \t]*\\(?:"
+                             (regexp-quote comment-continue) "\\|"
+                             comment-start-skip "\\|"
+                             comment-end-skip "\\)\\)?"
+                             "\\(?:" paragraph-separate "\\)")
                    paragraph-separate))
                 (paragraph-start
                  (if (and comment-continue
@@ -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
@@ -504,6 +520,7 @@ pseudo-classes, and at-rules."
   "Major mode to edit \"Sassy CSS\" files."
   (setq-local comment-start "// ")
   (setq-local comment-end "")
+  (setq-local comment-continue " *")
   (setq-local comment-start-skip "/[*/]+[ \t]*")
   (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)")
   (setq-local font-lock-defaults '(scss-font-lock-keywords nil t)))
-- 
2.1.4

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

  reply	other threads:[~2015-04-18 10:02 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
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 [this message]
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=1429351350.28233.1@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.