all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* c++-ts-mode and namespace indentation
@ 2023-08-24  9:04 Louis-Guillaume Gagnon
  2023-08-25 17:50 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Louis-Guillaume Gagnon @ 2023-08-24  9:04 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I've recently switched to the new c++-ts-mode (a game changer for source
code featuring deeply nested templates!). I'm quite pleased with it, but
I can't figure out how to make it such that a namespace block doesn't
increase the indentation level.  I previously achieved this with
(c-set-offset 'innamespace 0); Can anyone spell out how to achieve this
under treesitter?

Thanks!

L-G





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++-ts-mode and namespace indentation
  2023-08-24  9:04 c++-ts-mode and namespace indentation Louis-Guillaume Gagnon
@ 2023-08-25 17:50 ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-08-25 17:50 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Thu, 24 Aug 2023 09:04:55 +0000
> From: Louis-Guillaume Gagnon <gagnonlg@protonmail.com>
> 
> I've recently switched to the new c++-ts-mode (a game changer for source
> code featuring deeply nested templates!). I'm quite pleased with it, but
> I can't figure out how to make it such that a namespace block doesn't
> increase the indentation level.  I previously achieved this with
> (c-set-offset 'innamespace 0); Can anyone spell out how to achieve this
> under treesitter?

The c++-ts-mode doesn't support c-set-offset, which is specific to CC
Mode.  Try using c-ts-mode-indent-offset instead.  If that somehow
doesn't work, I suggest to submit a detailed bug report describing the
feature you'd like to see.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* c++-ts-mode and namespace indentation
@ 2023-09-06 15:37 xzhou@xeechou.net xzhou@xeechou.net
  2023-09-15  2:56 ` Yuan Fu
  0 siblings, 1 reply; 4+ messages in thread
From: xzhou@xeechou.net xzhou@xeechou.net @ 2023-09-06 15:37 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

> Date: Thu, 24 Aug 2023 09:04:55 +0000
> From: Louis-Guillaume Gagnon <gagnonlg@protonmail.com>
> 
> I've recently switched to the new c++-ts-mode (a game changer for source
> code featuring deeply nested templates!). I'm quite pleased with it, but
> I can't figure out how to make it such that a namespace block doesn't
> increase the indentation level.  I previously achieved this with
> (c-set-offset 'innamespace 0); Can anyone spell out how to achieve this
> under treesitter?

Hi,


I managed to create an simple function to archive the same goal

  (defun my/indent-rules ()
    `(;;here is my custom rules
      ((parent-is "namespace_definition") parent-bol 0)
      ,@(alist-get 'bsd (c-ts-mode--indent-styles 'cpp)))
    )


Then you would simply (setq c-ts-mode-indent-style #'my-indent-style). I 
followed some guides here: https://casouri.github.io/note/2023/tree-sitter-starter-guide/html-manual/Parser_002dbased-Indentation.html.


Regards,

Xichen


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++-ts-mode and namespace indentation
  2023-09-06 15:37 xzhou@xeechou.net xzhou@xeechou.net
@ 2023-09-15  2:56 ` Yuan Fu
  0 siblings, 0 replies; 4+ messages in thread
From: Yuan Fu @ 2023-09-15  2:56 UTC (permalink / raw)
  To: gagnonlg@protonmail.com; +Cc: help-gnu-emacs@gnu.org



> On Sep 6, 2023, at 8:37 AM, xzhou@xeechou.net xzhou@xeechou.net <xzhou@xeechou.net> wrote:
> 
>> Date: Thu, 24 Aug 2023 09:04:55 +0000
>> From: Louis-Guillaume Gagnon <gagnonlg@protonmail.com>
>> 
>> I've recently switched to the new c++-ts-mode (a game changer for source
>> code featuring deeply nested templates!). I'm quite pleased with it, but
>> I can't figure out how to make it such that a namespace block doesn't
>> increase the indentation level.  I previously achieved this with
>> (c-set-offset 'innamespace 0); Can anyone spell out how to achieve this
>> under treesitter?
> 
> Hi,
> 
> 
> I managed to create an simple function to archive the same goal
> 
>  (defun my/indent-rules ()
>    `(;;here is my custom rules
>      ((parent-is "namespace_definition") parent-bol 0)
>      ,@(alist-get 'bsd (c-ts-mode--indent-styles 'cpp)))
>    )
> 
> 
> Then you would simply (setq c-ts-mode-indent-style #'my-indent-style). I 
> followed some guides here: https://casouri.github.io/note/2023/tree-sitter-starter-guide/html-manual/Parser_002dbased-Indentation.html.

An alternative that avoids using c-ts-mode--indent-styles:

(defun c++-ts-mode-config ()
  (push '((parent-is "namespace_definition") parent-bol 0)
        treesit-simple-indent-rules))

(add-hook 'c++-ts-mode-hook #'c++-ts-mode-config)

Yuan


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-15  2:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24  9:04 c++-ts-mode and namespace indentation Louis-Guillaume Gagnon
2023-08-25 17:50 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2023-09-06 15:37 xzhou@xeechou.net xzhou@xeechou.net
2023-09-15  2:56 ` Yuan Fu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.