reddit / emacs
How do i force emacs to use tabs instead of spaces for indentation?
Exzelt8042 · 2022-04-08 12:08
I've tried
`(setq-default indent-tabs-mode 'only)`
` (advice-add 'indent-to :around`
`(lambda (orig-fun column &rest args)`
`(when (eq indent-tabs-mode 'only)`
`(setq column (* tab-width (round column tab-width))))`
`(apply orig-fun column args)))`
but that doesn't work, any other way to do it?
EDIT: I got it to work
(setq-default indent-tabs-mode t)
(setq-default tab-width 4) ; Assuming you want your tabs to be four spaces wide
(defvaralias 'c-basic-offset 'tab-width)
(setq ruby-indent-tabs-mode t)
(defvaralias 'ruby-indent-level 'tab-width)
(defvaralias 'sgml-basic-offset 'tab-width)
sunnyata · 2022-04-08 15:07
This guy right here officer.
pwnedary · 2022-04-08 15:38
Note that Emacs's implementation of indenting with tabs is broken since it will align stuff with tabs instead of switching over to spaces for those matters.
Icommentedtoday · 2022-04-08 16:00
Unrelated but what is your flare supposed to say? Is it supposed to say: "vi is better than emacs and emacs is better than vim" or is it "I went from vi to emacs to vim".
alftheo · 2022-04-08 16:10
I just go white-space-mode and concentrate
00-11 · 2022-04-08 16:38
Time travel to the 70s.
Exzelt8042 · 2022-04-08 16:51
ah thanks
bigfig · 2022-04-08 17:10
[Awesome!](https://www.youtube.com/watch?v=EM0VwEkxWTg)
youRFate · 2022-04-08 17:10
I hope its not possible.
Starlight100 · 2022-04-08 17:56
You can use [smart-tabs-mode](https://www.emacswiki.org/emacs/SmartTabs) to indent with tabs, align with spaces.
It's not built into emacs and a few odd languages require a bit of set up to get it working properly. But it gets the job done. I wish something like this was in core Emacs.
Exzelt8042 · 2022-04-08 17:58
why not lol
youRFate · 2022-04-08 18:08
Generally, most programmers prefer spaces instead of tabs, because they are consistent across platforms, editors etc.
We also enforce this using some tools in our codebases.
Also [you will make more money](https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/).
Exzelt8042 · 2022-04-08 18:13
I'll check that out, thanks
RobThorpe · 2022-04-08 18:16
> (setq ruby-indent-tabs-mode t)
It seems to me that you shouldn't need this. Ruby-mode should deal with tabs in the standard Emacs way. Perhaps this is a bug.
Exzelt8042 · 2022-04-08 18:18
yeah could be . I don't use Ruby but just threw it in for good measure
Sudo_Brew · 2022-04-08 19:06
You're going to keep running into modes and situations where it will break and you'll have to add more configuration to fix it. I used to work on a project that mandated tabs, and I needed a good 20 lines (at least) of configuration to make it behave. Some modes like rjsx have features that simply don't work with tabs. If you *can* switch to spaces, it'll make life easier and the code will look exactly the same. I feel the pain of not having that option, though.
Red-Portal · 2022-04-08 20:47
Excuse me, but are you a psychopath?
bighi · 2022-04-08 21:28
Tabs are the perfect way to indent stuff.
Do you prefer 2 spaces? Tab can be represented as 2 spaces for you. While if someone else prefers 4 spaces, tab can be 4 spaces for them. 8 spaces? It can be 8 spaces for you, you maniac!
Everyone can have their own levels of indentation, while standardizing it to 1 single tab in the code.
Starlight100 · 2022-04-08 23:44
This. For c-like languages, it's tabs all the way.
The width of the indent is a visual effect. You wouldn't hard-fix visual effects like the color-theme into your code, and the same should hold for indent width.
The only draw back of tabs is you need some advanced tooling to handle the alignments with spaces once the indent level is reached. Not everyone has that tooling. And some projects (linux kernel) insist on aligning with tabs which means you are forced to view everything at tab-width 8, defeating the advantage of tabs.
The world is so close a tab indentation utopia, but held back by the lack of tooling.
Exzelt8042 · 2022-04-09 02:33
i mean in certain cases, ill need to use tabs like for make files also its nice to hit back only once rather than 4 times