emacs-devel
[Top][All Lists]
Advanced

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

Re: Missing features in c-ts-mode


From: Theodor Thornhill
Subject: Re: Missing features in c-ts-mode
Date: Wed, 15 Feb 2023 20:31:33 +0100

Theodor Thornhill <theo@thornhill.no> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Theodor Thornhill <theo@thornhill.no>
>>> Cc: emacs-devel@gnu.org
>>> Date: Wed, 15 Feb 2023 19:29:20 +0100
>>> 
>>> Eli Zaretskii <eliz@gnu.org> writes:
>>> 
>>> > There's a couple of useful features that are currently missing from
>>> > c/c++-ts-mode:
>>> >
>>> >   M-a and M-e (go to beginning/end of statement)
>>> >   electric # (aligns # to the left unless it's in a comment or a string)
>>> >
>>> > Can we add these, please?
>>> 
>>> Isn't M-a and M-e available on master?
>>
>> Maybe, I didn't look there, sorry.  If they work there, then this one
>> is fine.
>>
>
> They should be there, but they may need tweaking.  Let me know if they
> behave unexpectedly.
>
>>> I'll look into electric #. For emacs-29 or master?
>>
>> If it is simple and safe enough, emacs-29.
>>
>> Thanks.
>
> No worries :-)
>
> Theo

This patch adds some support for this- but I'm not really satisfied yet.
It will electrically indent if you've typed "#i", or if you insert "#"
before say, "if".  The reason it behaves this way right now is that the
parser returns an (ERROR (ERROR)) node when only # is inserted.  I'll
see if I can find some workaround for it.


diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 020f2642ac2..29e917a2aee 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -785,7 +785,13 @@ c-ts-base-mode
 
   ;; Electric
   (setq-local electric-indent-chars
-              (append "{}():;," electric-indent-chars))
+              (append "{}():;,#" electric-indent-chars))
+
+  (setq-local electric-indent-functions
+              (list
+               (lambda (c) (save-excursion
+                        (forward-char -1)
+                        (looking-back "#" nil)))))
 
   ;; Imenu.
   (setq-local treesit-simple-imenu-settings



reply via email to

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