mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-05 11:49:37 +00:00
Support filling line comments in c-ts-mode
Now we handle line comments separately because for line comments, each line is an individual node, unlike block comments, where the whole block comment is a single node. fill-comment-paragraph turns out to do the job perfectly fine. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--fill-paragraph): Extract out most parts into c-ts-mode--fill-block-comment. (c-ts-mode--fill-block-comment): New extracted function.
This commit is contained in:
parent
f02998939c
commit
d428d51066
1 changed files with 71 additions and 61 deletions
|
@ -682,6 +682,22 @@ ARG is passed to `fill-paragraph'."
|
||||||
(interactive "*P")
|
(interactive "*P")
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen)
|
(widen)
|
||||||
|
(let ((node (treesit-node-at (point))))
|
||||||
|
(when (string-match-p c-ts-mode--comment-regexp
|
||||||
|
(treesit-node-type node))
|
||||||
|
(if (save-excursion
|
||||||
|
(goto-char (treesit-node-start node))
|
||||||
|
(looking-at "//"))
|
||||||
|
(fill-comment-paragraph arg)
|
||||||
|
(c-ts-mode--fill-block-comment arg)))
|
||||||
|
;; Return t so `fill-paragraph' doesn't attempt to fill by
|
||||||
|
;; itself.
|
||||||
|
t)))
|
||||||
|
|
||||||
|
(defun c-ts-mode--fill-block-comment (&optional arg)
|
||||||
|
"Fillling function for block comments.
|
||||||
|
ARG is passed to `fill-paragraph'. Assume point is in a block
|
||||||
|
comment."
|
||||||
(let* ((node (treesit-node-at (point)))
|
(let* ((node (treesit-node-at (point)))
|
||||||
(start (treesit-node-start node))
|
(start (treesit-node-start node))
|
||||||
(end (treesit-node-end node))
|
(end (treesit-node-end node))
|
||||||
|
@ -692,8 +708,6 @@ ARG is passed to `fill-paragraph'."
|
||||||
(end-marker nil)
|
(end-marker nil)
|
||||||
(end-len 0))
|
(end-len 0))
|
||||||
(move-marker start-marker start)
|
(move-marker start-marker start)
|
||||||
(when (string-match-p c-ts-mode--comment-regexp
|
|
||||||
(treesit-node-type node))
|
|
||||||
;; We mask "/*" and the space before "*/" like
|
;; We mask "/*" and the space before "*/" like
|
||||||
;; `c-fill-paragraph' does.
|
;; `c-fill-paragraph' does.
|
||||||
(atomic-change-group
|
(atomic-change-group
|
||||||
|
@ -743,11 +757,7 @@ ARG is passed to `fill-paragraph'."
|
||||||
(when end-marker
|
(when end-marker
|
||||||
(goto-char end-marker)
|
(goto-char end-marker)
|
||||||
(delete-region (point) (+ end-len (point)))
|
(delete-region (point) (+ end-len (point)))
|
||||||
(insert (make-string end-len ?\s))))
|
(insert (make-string end-len ?\s))))))
|
||||||
(goto-char orig-point))
|
|
||||||
;; Return t so `fill-paragraph' doesn't attempt to fill by
|
|
||||||
;; itself.
|
|
||||||
t)))
|
|
||||||
|
|
||||||
(defun c-ts-mode-comment-setup ()
|
(defun c-ts-mode-comment-setup ()
|
||||||
"Set up local variables for C-like comment.
|
"Set up local variables for C-like comment.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue