diff options
author | Theodor Thornhill <theo@thornhill.no> | 2022-12-02 16:05:35 +0100 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2022-12-07 12:01:51 -0800 |
commit | c83c95634e7a8d0f334ac5d45eebf357e413906c (patch) | |
tree | c4b61f98ef2b63d7575efb36f7a454c97cbb5dca /lisp/progmodes/c-ts-mode.el | |
parent | 6479691cf0756d776bbc91cab5e5c339def81777 (diff) | |
download | emacs-c83c95634e7a8d0f334ac5d45eebf357e413906c.tar.gz emacs-c83c95634e7a8d0f334ac5d45eebf357e413906c.tar.bz2 emacs-c83c95634e7a8d0f334ac5d45eebf357e413906c.zip |
Add c-ts-mode-indent-defun (bug#59662)
Add in this function to mimic 'c-indent-defun'.
* lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-defun): New function.
(c-ts-mode-map): New mode map that uses said function.
Diffstat (limited to 'lisp/progmodes/c-ts-mode.el')
-rw-r--r-- | lisp/progmodes/c-ts-mode.el | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 862d8766e0b..0b17541a0a2 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -520,9 +520,30 @@ the subtrees." (if (looking-at "\\s<\\|\n") (forward-line 1))))) +(defun c-ts-mode-indent-defun () + "Indent the current top-level declaration syntactically. + +`treesit-defun-type-regexp' defines what constructs to indent." + (interactive "*") + (let ((orig-point (point-marker))) + ;; If `treesit-beginning-of-defun' returns nil, we are not in a + ;; defun, so don't indent anything. + (when (treesit-beginning-of-defun) + (let ((start (point))) + (treesit-end-of-defun) + (indent-region start (point)))) + (goto-char orig-point))) + +(defvar-keymap c-ts-mode-map + :doc "Keymap for the C language with tree-sitter" + :parent prog-mode-map + "C-c C-q" #'c-ts-mode-indent-defun) + ;;;###autoload (define-derived-mode c-ts-base-mode prog-mode "C" - "Major mode for editing C, powered by tree-sitter." + "Major mode for editing C, powered by tree-sitter. + +\\{c-ts-mode-map}" :syntax-table c-ts-mode--syntax-table ;; Navigation. |