Reliable tab behavior per file type for teaching with nano?

Michael Lehn <[email protected]> Sun, 6 Apr 2025 23:18:49 +0200
Newsgroups gmane.editors.nano.general
Message-ID <[email protected]>
--Apple-Mail=_C940A697-8966-4A33-A739-681D3F3D3DCE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

Hello everyone,

I'm preparing a beginner programming course in which students will use =
nano as their main editor inside the terminal. =20
They will write simple C code (for Arduino), Python scripts, and =
Makefiles.

To keep things simple and beginner-friendly, I=E2=80=99d like to avoid =
introducing vim, emacs, or any external editor, and rely entirely on =
nano with a preconfigured .nanorc.

What I want is:

MAKEFILES
---------
- tabsize 8
- tabs must be preserved (i.e., no conversion to spaces, as make =
demands)

ALL OTHER FILES (C, Python, etc.)
---------------------------------
- tabsize 4
- tabs should be converted to spaces (set tabstospaces)

I=E2=80=99ve tried using separate syntax blocks in .nanorc like this:

  syntax "makefile" "^(Makefile|makefile|GNUmakefile)$"
  color green ".*"
  set tabsize 8
  unset tabstospaces

  syntax "default" ".*"
  color normal ".*"
  set tabsize 4
  set tabstospaces

However, this approach does not work as intended. =20
nano appears to apply set and unset globally, regardless of which syntax =
block a file matches. =20
As a result, the last set or unset in the config overrides previous ones =
globally, even for other file types. =20
So Makefiles still get tabsize 4 and converted spaces, which breaks =
make.

My question: =20
Is there a reliable way to enforce different tab behavior (especially =
regarding tabstospaces) depending on file type, purely via .nanorc, =
without wrapping nano in a shell script or wrapper?

If not, what=E2=80=99s the recommended workaround in practice? I=E2=80=99m=
 open to any solution used by nano users or teachers in similar =
situations.

Thank you very much =E2=80=93 and thanks for building such a clean and =
friendly editor!

Best regards, =20
Michael

=
--------------------------------------------------------------------------=
---------
Dr. Michael Lehn
University of Ulm, Institute for Numerical Mathematics
Zimmer 1 09
Helmholtzstr. 20
D-89069 Ulm, Germany
Phone: (+49) 731 50-23534, Fax: (+49) 731 50-23548
=
--------------------------------------------------------------------------=
---------


--Apple-Mail=_C940A697-8966-4A33-A739-681D3F3D3DCE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"overflow-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;"><div>Hello =
everyone,</div><div><br></div><div>I'm preparing a beginner programming =
course in which students will use nano as their main editor inside the =
terminal. &nbsp;</div><div>They will write simple C code (for Arduino), =
Python scripts, and Makefiles.</div><div><br></div><div>To keep things =
simple and beginner-friendly, I=E2=80=99d like to avoid introducing vim, =
emacs, or any external editor, and rely entirely on nano with a =
preconfigured .nanorc.</div><div><br></div><div>What I want =
is:</div><div><br></div><div>MAKEFILES</div><div>---------</div><div>- =
tabsize 8</div><div>- tabs must be preserved (i.e., no conversion to =
spaces, as make demands)</div><div><br></div><div>ALL OTHER FILES (C, =
Python, etc.)</div><div>---------------------------------</div><div>- =
tabsize 4</div><div>- tabs should be converted to spaces (set =
tabstospaces)</div><div><br></div><div>I=E2=80=99ve tried using separate =
syntax blocks in .nanorc like this:</div><div><br></div><div>&nbsp; =
syntax "makefile" "^(Makefile|makefile|GNUmakefile)$"</div><div>&nbsp; =
color green ".*"</div><div>&nbsp; set tabsize 8</div><div>&nbsp; unset =
tabstospaces</div><div><br></div><div>&nbsp; syntax "default" =
".*"</div><div>&nbsp; color normal ".*"</div><div>&nbsp; set tabsize =
4</div><div>&nbsp; set tabstospaces</div><div><br></div><div>However, =
this approach does not work as intended. &nbsp;</div><div>nano appears =
to apply set and unset globally, regardless of which syntax block a file =
matches. &nbsp;</div><div>As a result, the last set or unset in the =
config overrides previous ones globally, even for other file types. =
&nbsp;</div><div>So Makefiles still get tabsize 4 and converted spaces, =
which breaks make.</div><div><br></div><div>My question: =
&nbsp;</div><div>Is there a reliable way to enforce different tab =
behavior (especially regarding tabstospaces) depending on file type, =
purely via .nanorc, without wrapping nano in a shell script or =
wrapper?</div><div><br></div><div>If not, what=E2=80=99s the recommended =
workaround in practice? I=E2=80=99m open to any solution used by nano =
users or teachers in similar situations.</div><div><br></div><div>Thank =
you very much =E2=80=93 and thanks for building such a clean and =
friendly editor!</div><div><br></div><div>Best regards, =
&nbsp;</div><div>Michael</div><div><br></div><div>
<meta charset=3D"UTF-8"><div dir=3D"auto" style=3D"caret-color: rgb(0, =
0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; =
text-indent: 0px; text-transform: none; white-space: normal; =
word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: =
none; overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: =
after-white-space;"><div>-------------------------------------------------=
----------------------------------<br>Dr. Michael Lehn<br>University of =
Ulm, Institute for Numerical&nbsp;Mathematics</div><div>Zimmer 1 =
09<br>Helmholtzstr. 20<br>D-89069 Ulm, Germany<br>Phone: (+49) 731 =
50-23534, Fax: (+49)&nbsp;731 =
50-23548<br>--------------------------------------------------------------=
---------------------</div></div>
</div>
<br></body></html>=

--Apple-Mail=_C940A697-8966-4A33-A739-681D3F3D3DCE--