jdtsmith / indent-bars

Fast, configurable indentation guide-bars for Emacs
GNU General Public License v3.0
265 stars 7 forks source link

c-ts-mode indentation value is not discovered #47

Open bogolisk opened 5 days ago

bogolisk commented 5 days ago

image

The code is from https://elixir.bootlin.com/zephyr/latest/source/kernel/msg_q.c#L330

I just loaded the 2 .elc files and M-x indent-bars-mode. My emacs is 29.2.

Why the bars in the middle of the TABs?

jdtsmith commented 5 days ago

Re-indent the entire file: C-x h C-u Tab. Or update your indentation settings to match the file's.

indent-bars learns about indentation from the settings like c-basic-offset. If your file doesn't respect that, problems ensue.

bogolisk commented 5 days ago

That is zephyr's official code, not mine. I'm just reading zephyr's code in emacs. They use linux style.

in that buffer: c-basic-offset is: set-from-style c-indentation-style is: linux

jdtsmith commented 4 days ago

I understand, but the source of the code doesn't matter here. indent-bars must be able to learn the indent block size to do its work. All it does for c-modes is:

((and (local-variable-p 'c-basic-offset) (numberp c-basic-offset))
    c-basic-offset)

What is the value of c-basic-offset after your buffer has initialized? Presumably it must be some number.

bogolisk commented 4 days ago

I'm using c-ts-mode, so this "patch" fixed the issue

$ diff -wu indent-bars.el.orig indent-bars.el
--- indent-bars.el.orig 2024-07-01 17:32:15.787381000 -0400
+++ indent-bars.el  2024-07-02 08:51:08.066778000 -0400
@@ -1506,6 +1506,9 @@
     web-mode-html-offset)
    ((and (local-variable-p 'c-basic-offset) (numberp c-basic-offset))
     c-basic-offset)
+   ((and (local-variable-p 'c-ts-common-indent-offset)
+         (symbolp c-ts-common-indent-offset))
+    (symbol-value c-ts-common-indent-offset))
    ((and (derived-mode-p 'yaml-mode) (boundp 'yaml-indent-offset))
     yaml-indent-offset)
    ((and (derived-mode-p 'elixir-mode) (boundp 'elixir-smie-indent-basic))
jdtsmith commented 4 days ago

Thanks. I'll check with the c*-mode people and implement something like this. I wonder why it doesn't update c-basic-offset? It is unfortunate that emacs doesn't provision a single local variable for this widely used information.

jdtsmith commented 12 hours ago

Please see if 756cfb0 works.