reddit / emacs

Convert a Double Space Indentation to Tab (width - 4) Indentation

_analysis230_ · 2022-08-24 06:53
I am facing this problem which on the face of it should be easy to solve but isn't. this is my `.editorconf`: root = true [*] indent_style = tab tab_width = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true I am running doom emacs with ts-ls with LSP for javascript. I have some files in my project that are indented with 4-width Tabs and that's how I like it. If I change something in them and save they stay properly indented with 4-width Tabs. I have other files in the same project that are indented with 2 spaces. I don't want that. I want to be able to convert that to 4-width tab but that does not happen automatically on save, they stay in 2 space formatting. Any new file I create in Emacs is also indented with 2 spaces, but if I create the file in VSCode and write some Tab spaced text and open it back in Emacs it stays Tab indented. How can I fix this?
lebensterben · 2022-08-24 07:04
you need to turn if the auto formatting of lsp. most language server disregard settings in .editorconfig.
_analysis230_ · 2022-08-24 07:06
You mean turn off? But I need the auto formatting. It helps me keep my code organized. There must be a way to set it up to format with tabs, right?
lebensterben · 2022-08-24 07:13
yep that was a typo. See here https://github.com/typescript-language-server/typescript-language-server#workspacedidchangeconfiguration I suspect [language].format.convertTabsToSpaces is on.
_analysis230_ · 2022-08-24 09:04
So I solved the problem by setting the js2-basic-offset to 4 Now it's works as it should.