今天用treesit查看json文件才发现它默认使用space缩进,看了站内站外似乎没有解决方案。有改用tab缩进的方法吗?
试试
(setq indent-tabs-mode t)
试过了,这个值默认就是t。貌似treesit是不遵守这个设置的,而用treesit-indent
这个函数缩进。
应该是改json-ts-mode-indent-offset
,但这个值只能改用多少个space缩进。
你要是进到 treesit-indent
的源码里就会发现它也是用 indent-to
来缩进的,而 indent-to
会去读 indent-tabs-mode
。
所以你这个问题应该是别的地方导致的,建议用 emacs -q 排查一下。
我是设置了下面2条设置就可以在 c/c++-ts-mode
中用 Tab 缩进了,indent-tabs-mode 要使用默认的 t 值。
(setopt c-ts-mode-indent-style 'linux)
(setopt c-ts-mode-indent-offset 8)
下面是我的 treesit设置,不过目前主要还是用内置的 cc-mode,不在C/C++上用 treesit了。
你的问题估计是其他设置把 indent-tabs-mode 改成 nil了。你可以在当前buffer下,执行C-h v indent-tabs-mode
看看是什么值。
JSON 是一种数据格式,建议用空格,不要用 tabs,可能是 js-ts-mode 的语法要求就是空格缩进。