Change indentation in c-ts-mode

This commit is contained in:
2025-08-27 14:04:29 -07:00
parent e517cd0ab8
commit 1445beb3d0

24
init.el
View File

@ -1888,6 +1888,7 @@ otherwise, call `bibtex-find-text'."
(nthcdr 1 rules))))))
;; c-ts-mode
(setopt ff-ignore-include t)
(defun my/find-other-file (&optional in-other-window event)
"Like `ff-find-other-file', but respect configuration variables.
IN-OTHER-WINDOW and EVENT are the same as the original command."
@ -1905,9 +1906,30 @@ EVENT is the same as the original command."
:after evil
:hook ((c-ts-mode c++-ts-mode) . my/eglot-if-trusted)
:init
(defun my/-c-ts-in-doc-comment-p (&optional include-end)
(when-let ((node (treesit-thing-at-point "comment" 'toplevel))
(start (treesit-node-start node))
(end (treesit-node-end node)))
(and (> (point) (+ start 2))
(eql (char-after (+ start 1)) ?*)
(memql (char-after (+ start 2)) '(?* ?!))
(or include-end
(<= (point) (- end 2))))))
(defun my/c-ts-newline (&optional arg)
"Insert ARG newlines as with `newline'.
If inside a comment and in multi-line comment mode, act as
`default-indent-new-line'."
(interactive "*P")
(when (and arg (< (prefix-numeric-value arg) 0))
(user-error "Count cannot be negative"))
(if (my/-c-ts-in-doc-comment-p)
(dotimes (_ (prefix-numeric-value arg))
(default-indent-new-line))
(newline arg t)))
(setq-default c-ts-mode-indent-offset 4)
(setopt ff-ignore-include t)
:config
(dolist (sym '(c-ts-mode-map c++-ts-mode-map))
(keymap-set (symbol-value sym) "<remap> <newline>" #'my/c-ts-newline))
(evil-define-key 'normal 'c-ts-mode-map
"go" #'my/find-other-file
"gO" #'my/find-other-file-other-window)