aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimen Heggestøyl2015-04-18 20:25:40 +0200
committerSimen Heggestøyl2015-04-18 20:25:40 +0200
commit1dee790fc1467709bcb2fb651b23b521e9ca71da (patch)
treebdcddc7dbaec22922c74cbda7d666ec682750f52
parent9760c6cde3f280b2318e9550c2688b1761b09c30 (diff)
downloademacs-1dee790fc1467709bcb2fb651b23b521e9ca71da.tar.gz
emacs-1dee790fc1467709bcb2fb651b23b521e9ca71da.zip
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'.
-rw-r--r--lisp/textmodes/css-mode.el23
1 files changed, 20 insertions, 3 deletions
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index d1893a36f27..424cdb7f830 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -381,7 +381,8 @@ pseudo-classes, and at-rules."
381 (setq-local comment-start-skip "/\\*+[ \t]*") 381 (setq-local comment-start-skip "/\\*+[ \t]*")
382 (setq-local comment-end "*/") 382 (setq-local comment-end "*/")
383 (setq-local comment-end-skip "[ \t]*\\*+/") 383 (setq-local comment-end-skip "[ \t]*\\*+/")
384 (setq-local fill-paragraph-function 'css-fill-paragraph) 384 (setq-local fill-paragraph-function #'css-fill-paragraph)
385 (setq-local adaptive-fill-function #'css-adaptive-fill)
385 (setq-local add-log-current-defun-function #'css-current-defun-name) 386 (setq-local add-log-current-defun-function #'css-current-defun-name)
386 (smie-setup css-smie-grammar #'css-smie-rules 387 (smie-setup css-smie-grammar #'css-smie-rules
387 :forward-token #'css-smie--forward-token 388 :forward-token #'css-smie--forward-token
@@ -395,6 +396,12 @@ pseudo-classes, and at-rules."
395 396
396(defun css-fill-paragraph (&optional justify) 397(defun css-fill-paragraph (&optional justify)
397 (save-excursion 398 (save-excursion
399 ;; Fill succeeding comment when invoked right before a multi-line
400 ;; comment.
401 (when (save-excursion
402 (beginning-of-line)
403 (comment-search-forward (point-at-eol) t))
404 (goto-char (match-end 0)))
398 (let ((ppss (syntax-ppss)) 405 (let ((ppss (syntax-ppss))
399 (eol (line-end-position))) 406 (eol (line-end-position)))
400 (cond 407 (cond
@@ -414,8 +421,11 @@ pseudo-classes, and at-rules."
414 (paragraph-separate 421 (paragraph-separate
415 (if (and comment-continue 422 (if (and comment-continue
416 (string-match "[^ \t]" comment-continue)) 423 (string-match "[^ \t]" comment-continue))
417 (concat "\\(?:[ \t]*" (regexp-quote comment-continue) 424 (concat "\\(?:[ \t]*\\(?:"
418 "\\)?\\(?:" paragraph-separate "\\)") 425 (regexp-quote comment-continue) "\\|"
426 comment-start-skip "\\|"
427 comment-end-skip "\\)\\)?"
428 "\\(?:" paragraph-separate "\\)")
419 paragraph-separate)) 429 paragraph-separate))
420 (paragraph-start 430 (paragraph-start
421 (if (and comment-continue 431 (if (and comment-continue
@@ -468,6 +478,12 @@ pseudo-classes, and at-rules."
468 ;; Don't use the default filling code. 478 ;; Don't use the default filling code.
469 t))))))) 479 t)))))))
470 480
481(defun css-adaptive-fill ()
482 (when (looking-at "[ \t]*/\\*[ \t]*")
483 (let ((str (match-string 0)))
484 (and (string-match "/\\*" str)
485 (replace-match " *" t t str)))))
486
471(defun css-current-defun-name () 487(defun css-current-defun-name ()
472 "Return the name of the CSS section at point, or nil." 488 "Return the name of the CSS section at point, or nil."
473 (save-excursion 489 (save-excursion
@@ -504,6 +520,7 @@ pseudo-classes, and at-rules."
504 "Major mode to edit \"Sassy CSS\" files." 520 "Major mode to edit \"Sassy CSS\" files."
505 (setq-local comment-start "// ") 521 (setq-local comment-start "// ")
506 (setq-local comment-end "") 522 (setq-local comment-end "")
523 (setq-local comment-continue " *")
507 (setq-local comment-start-skip "/[*/]+[ \t]*") 524 (setq-local comment-start-skip "/[*/]+[ \t]*")
508 (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)") 525 (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\*+/\\)")
509 (setq-local font-lock-defaults '(scss-font-lock-keywords nil t))) 526 (setq-local font-lock-defaults '(scss-font-lock-keywords nil t)))