all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* In go-ts-mode, tab-width 4 inserts two tabs instead of one
@ 2023-09-26 11:08 Pankaj Jangid
  2023-09-26 11:36 ` Augustin Chéneau (BTuin)
  0 siblings, 1 reply; 4+ messages in thread
From: Pankaj Jangid @ 2023-09-26 11:08 UTC (permalink / raw)
  To: Emacs Development

Suppose I have this struct,

#+begin_src go
package main

type Message struct {
	Response Response
	Request Request
	ForAPI string
}
#+end_src

If I keep default tab-width of 8, then it works fine. But when I change
the buffer local variable tab-width to 4, /mostly/ it inserts two tab
chars instead of one, /sometimes/ it works fine. I have one file where
it works just fine. And in all other files, it inserts two tabs instead
of one.

I am on branch emacs-29 and built with tree-sitter and gtk.

Language mode is go-ts-mode.



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

* Re: In go-ts-mode, tab-width 4 inserts two tabs instead of one
  2023-09-26 11:08 In go-ts-mode, tab-width 4 inserts two tabs instead of one Pankaj Jangid
@ 2023-09-26 11:36 ` Augustin Chéneau (BTuin)
  2023-09-26 12:31   ` Pankaj Jangid
  0 siblings, 1 reply; 4+ messages in thread
From: Augustin Chéneau (BTuin) @ 2023-09-26 11:36 UTC (permalink / raw)
  To: pankaj; +Cc: Emacs Development

Le 26/09/2023 à 13:08, Pankaj Jangid a écrit :
> Suppose I have this struct,
> 
> #+begin_src go
> package main
> 
> type Message struct {
> 	Response Response
> 	Request Request
> 	ForAPI string
> }
> #+end_src
> 
> If I keep default tab-width of 8, then it works fine. But when I change
> the buffer local variable tab-width to 4, /mostly/ it inserts two tab
> chars instead of one, /sometimes/ it works fine. I have one file where
> it works just fine. And in all other files, it inserts two tabs instead
> of one.
> 
> I am on branch emacs-29 and built with tree-sitter and gtk.
> 
> Language mode is go-ts-mode.
> 

That's because tab-width only controls the appearance of a tabulation. 
It doesn't change the actual indentation offset.
In go-ts-mode, the indentation offset is set by the variable 
go-ts-mode-indent-offset.  Since it is 8 by default and that you have 
set tab-width to 4, it inserts two tabs to keep the offset of 8.

So you simply need to set go-ts-mode-indent-offset to 4 or directly to 
tab-width (with (setq go-ts-mode-indent-offset tab-width)).





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

* Re: In go-ts-mode, tab-width 4 inserts two tabs instead of one
  2023-09-26 11:36 ` Augustin Chéneau (BTuin)
@ 2023-09-26 12:31   ` Pankaj Jangid
  2023-09-26 13:02     ` Augustin Chéneau (BTuin)
  0 siblings, 1 reply; 4+ messages in thread
From: Pankaj Jangid @ 2023-09-26 12:31 UTC (permalink / raw)
  To: Augustin Chéneau (BTuin); +Cc: Emacs Development

"Augustin Chéneau (BTuin)" <btuin@mailo.com> writes:

> That's because tab-width only controls the appearance of a
> tabulation.

I actually want this only. That is, I want to control the appearance of
tabulation only.

> In go-ts-mode, the indentation offset is set by the variable
> go-ts-mode-indent-offset.  Since it is 8 by default and that you have
> set tab-width to 4, it inserts two tabs to keep the offset of 8.
>
> So you simply need to set go-ts-mode-indent-offset to 4 or directly to
> tab-width (with (setq go-ts-mode-indent-offset tab-width)).

Setting both, tab-width and go-ts-mode-indent-offset, to 4 results in
the desired behaviour. But I did not understand this.

The doc string of go-ts-mode-indent-offset says, "Number of spaces for
each indentation step". But when I set both to 4, it uses TAB (which I
want), and not SPACEes.

Is this variable explained in detail elsewhere?



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

* Re: In go-ts-mode, tab-width 4 inserts two tabs instead of one
  2023-09-26 12:31   ` Pankaj Jangid
@ 2023-09-26 13:02     ` Augustin Chéneau (BTuin)
  0 siblings, 0 replies; 4+ messages in thread
From: Augustin Chéneau (BTuin) @ 2023-09-26 13:02 UTC (permalink / raw)
  To: pankaj; +Cc: Emacs Development

Le 26/09/2023 à 14:31, Pankaj Jangid a écrit :
> "Augustin Chéneau (BTuin)" <btuin@mailo.com> writes:
> 
>> That's because tab-width only controls the appearance of a
>> tabulation.
> 
> I actually want this only. That is, I want to control the appearance of
> tabulation only.
> 
>> In go-ts-mode, the indentation offset is set by the variable
>> go-ts-mode-indent-offset.  Since it is 8 by default and that you have
>> set tab-width to 4, it inserts two tabs to keep the offset of 8.
>>
>> So you simply need to set go-ts-mode-indent-offset to 4 or directly to
>> tab-width (with (setq go-ts-mode-indent-offset tab-width)).
> 
> Setting both, tab-width and go-ts-mode-indent-offset, to 4 results in
> the desired behaviour. But I did not understand this.
> 
> The doc string of go-ts-mode-indent-offset says, "Number of spaces for
> each indentation step". But when I set both to 4, it uses TAB (which I
> want), and not SPACEes.
> 
> Is this variable explained in detail elsewhere?
> 

So I don't know this very well, but from my understanding it replaces 
spaces with the equivalent tabs.

For instance, if you set tab-width to 4 and go-ts-mode-indent-offset to 
4, it will insert 4 spaces or equivalent, which are here equivalent to 1 
tab, so it will insert one tab instead.

If go-ts-mode-indent-offset is set to 6, it will insert 6 spaces or 
equivalent, which are here equivalent to one tab plus 2 spaces.

It you want to use spaces only instead, you might want to look at 
indent-tabs-mode.

There is also more information in the Emacs manual at "Indentation" 
(<https://www.gnu.org/software/emacs/manual/html_node/emacs/Indentation.html>) 
and in EmacsWiki (<https://www.emacswiki.org/emacs/IndentationBasics>).






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

end of thread, other threads:[~2023-09-26 13:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-26 11:08 In go-ts-mode, tab-width 4 inserts two tabs instead of one Pankaj Jangid
2023-09-26 11:36 ` Augustin Chéneau (BTuin)
2023-09-26 12:31   ` Pankaj Jangid
2023-09-26 13:02     ` Augustin Chéneau (BTuin)

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.