From 5c06edd90a5b80ecc92176b64376c8dac8b2b14c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 8 Nov 2020 20:02:16 -0500 Subject: [PATCH] lang/web: fix comments not joining/filling correctly Before, joining these two lines // hello // world Results in // hello // world And filling the following // Pretend this line is longer than 80 characters Becomes // Pretend this lineis longer than 80 characters --- modules/lang/web/+css.el | 4 +++- modules/lang/web/autoload/css.el | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/lang/web/+css.el b/modules/lang/web/+css.el index 414d92ae6..c386e7658 100644 --- a/modules/lang/web/+css.el +++ b/modules/lang/web/+css.el @@ -22,7 +22,9 @@ If set to `nil', disable all the above behaviors.") (setq-hook! 'css-mode-hook ;; Correctly continue /* and // comments on newline-and-indent - comment-line-break-function #'+css/comment-indent-new-line) + comment-line-break-function #'+css/comment-indent-new-line + ;; Fix `fill-paragraph' not conjoining line comments in CSS modes correctly. + adaptive-fill-function #'+css-adaptive-fill-fn) (after! (:any css-mode sass-mode) (set-docsets! '(css-mode scss-mode sass-mode) diff --git a/modules/lang/web/autoload/css.el b/modules/lang/web/autoload/css.el index d83e770e2..4d5279f1d 100644 --- a/modules/lang/web/autoload/css.el +++ b/modules/lang/web/autoload/css.el @@ -92,3 +92,14 @@ Meant for `comment-line-break-function' in `css-mode' and `scss-mode'." (save-excursion (just-one-space) (insert "\n" (make-string pre-indent indent-char))))))))) + +;;;###autoload +(defun +css-adaptive-fill-fn () + "An `adaptive-fill-function' that conjoins SCSS line comments correctly." + (when (looking-at "[ \t]*/[/*][ \t]*") + (let ((str (match-string 0))) + (when (string-match "/[/*]" str) + (replace-match (if (string= (match-string 0 str) "/*") + " *" + "//") + t t str)))))