emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 f1f571e72ae: Add electric indent for preproc directives


From: Theodor Thornhill
Subject: emacs-29 f1f571e72ae: Add electric indent for preproc directives
Date: Thu, 16 Feb 2023 14:12:11 -0500 (EST)

branch: emacs-29
commit f1f571e72ae10285762d3a941e56f7c4048272af
Author: Theodor Thornhill <theo@thornhill.no>
Commit: Theodor Thornhill <theo@thornhill.no>

    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.
---
 lisp/progmodes/c-ts-mode.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]