Add electric indent for preproc directives

It looks like there are few if no other cases where we get this
particular error in the AST than with insertion of '#'.

Consider:

```
int
main()
{
  |
}
```

If we only add '#' the AST yields (ERROR (ERROR)), which we can
exploit to hook onto electric indent.  The end result should be the
hashtag anchored to column 0.

* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): New rule.
(c-ts-base-mode): Add # to electric-indent-chars.
This commit is contained in:
Theodor Thornhill 2023-02-15 21:05:37 +01:00
parent 83af806ab7
commit f1f571e72a

View file

@ -219,6 +219,7 @@ delimiters < and >'s."
MODE is either `c' or `cpp'." MODE is either `c' or `cpp'."
(let ((common (let ((common
`(((parent-is "translation_unit") point-min 0) `(((parent-is "translation_unit") point-min 0)
((query "(ERROR (ERROR)) @indent") point-min 0)
((node-is ")") parent 1) ((node-is ")") parent 1)
((node-is "]") parent-bol 0) ((node-is "]") parent-bol 0)
((node-is "else") parent-bol 0) ((node-is "else") parent-bol 0)
@ -785,7 +786,7 @@ the semicolon. This function skips the semicolon."
;; Electric ;; Electric
(setq-local electric-indent-chars (setq-local electric-indent-chars
(append "{}():;," electric-indent-chars)) (append "{}():;,#" electric-indent-chars))
;; Imenu. ;; Imenu.
(setq-local treesit-simple-imenu-settings (setq-local treesit-simple-imenu-settings