; * lisp/progmodes/c-ts-mode.el: Add outline section headers.
This commit is contained in:
parent
e4e3634539
commit
a42b20dd95
1 changed files with 14 additions and 0 deletions
|
@ -39,6 +39,8 @@
|
||||||
(declare-function treesit-node-child-by-field-name "treesit.c")
|
(declare-function treesit-node-child-by-field-name "treesit.c")
|
||||||
(declare-function treesit-node-type "treesit.c")
|
(declare-function treesit-node-type "treesit.c")
|
||||||
|
|
||||||
|
;;; Custom variables
|
||||||
|
|
||||||
(defcustom c-ts-mode-indent-offset 2
|
(defcustom c-ts-mode-indent-offset 2
|
||||||
"Number of spaces for each indentation step in `c-ts-mode'."
|
"Number of spaces for each indentation step in `c-ts-mode'."
|
||||||
:version "29.1"
|
:version "29.1"
|
||||||
|
@ -91,6 +93,8 @@ follows the form of `treesit-simple-indent-rules'."
|
||||||
table)
|
table)
|
||||||
"Syntax table for `c++-ts-mode'.")
|
"Syntax table for `c++-ts-mode'.")
|
||||||
|
|
||||||
|
;;; Indent
|
||||||
|
|
||||||
(defun c-ts-mode--indent-styles (mode)
|
(defun c-ts-mode--indent-styles (mode)
|
||||||
"Indent rules supported by `c-ts-mode'.
|
"Indent rules supported by `c-ts-mode'.
|
||||||
MODE is either `c' or `cpp'."
|
MODE is either `c' or `cpp'."
|
||||||
|
@ -381,6 +385,8 @@ MODE is either `c' or `cpp'."
|
||||||
@c-ts-mode--fontify-defun)
|
@c-ts-mode--fontify-defun)
|
||||||
(:match "^DEFUN$" @fn)))))
|
(:match "^DEFUN$" @fn)))))
|
||||||
|
|
||||||
|
;;; Font-lock helpers
|
||||||
|
|
||||||
(defun c-ts-mode--fontify-declarator (node override start end &rest args)
|
(defun c-ts-mode--fontify-declarator (node override start end &rest args)
|
||||||
"Fontify a declarator (whatever under the \"declarator\" field).
|
"Fontify a declarator (whatever under the \"declarator\" field).
|
||||||
For NODE, OVERRIDE, START, END, and ARGS, see
|
For NODE, OVERRIDE, START, END, and ARGS, see
|
||||||
|
@ -473,6 +479,8 @@ For NODE, OVERRIDE, START, and END, see
|
||||||
(t 'font-lock-warning-face))
|
(t 'font-lock-warning-face))
|
||||||
override start end)))
|
override start end)))
|
||||||
|
|
||||||
|
;;; Imenu
|
||||||
|
|
||||||
(defun c-ts-mode--imenu-1 (node)
|
(defun c-ts-mode--imenu-1 (node)
|
||||||
"Helper for `c-ts-mode--imenu'.
|
"Helper for `c-ts-mode--imenu'.
|
||||||
Find string representation for NODE and set marker, then recurse
|
Find string representation for NODE and set marker, then recurse
|
||||||
|
@ -537,6 +545,8 @@ the subtrees."
|
||||||
(when var-index `(("Variable" . ,var-index)))
|
(when var-index `(("Variable" . ,var-index)))
|
||||||
(when func-index `(("Function" . ,func-index))))))
|
(when func-index `(("Function" . ,func-index))))))
|
||||||
|
|
||||||
|
;;; Defun navigation
|
||||||
|
|
||||||
(defun c-ts-mode--end-of-defun ()
|
(defun c-ts-mode--end-of-defun ()
|
||||||
"`end-of-defun-function' of `c-ts-mode'."
|
"`end-of-defun-function' of `c-ts-mode'."
|
||||||
;; A struct/enum/union_specifier node doesn't include the ; at the
|
;; A struct/enum/union_specifier node doesn't include the ; at the
|
||||||
|
@ -582,6 +592,8 @@ the semicolon. This function skips the semicolon."
|
||||||
(treesit-node-end node))
|
(treesit-node-end node))
|
||||||
(goto-char orig-point)))
|
(goto-char orig-point)))
|
||||||
|
|
||||||
|
;;; Filling
|
||||||
|
|
||||||
(defun c-ts-mode--fill-paragraph (&optional arg)
|
(defun c-ts-mode--fill-paragraph (&optional arg)
|
||||||
"Fillling function for `c-ts-mode'.
|
"Fillling function for `c-ts-mode'.
|
||||||
ARG is passed to `fill-paragraph'."
|
ARG is passed to `fill-paragraph'."
|
||||||
|
@ -646,6 +658,8 @@ ARG is passed to `fill-paragraph'."
|
||||||
;; itself.
|
;; itself.
|
||||||
t)))
|
t)))
|
||||||
|
|
||||||
|
;;; Modes
|
||||||
|
|
||||||
(defvar-keymap c-ts-mode-map
|
(defvar-keymap c-ts-mode-map
|
||||||
:doc "Keymap for the C language with tree-sitter"
|
:doc "Keymap for the C language with tree-sitter"
|
||||||
:parent prog-mode-map
|
:parent prog-mode-map
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue