0

I have been using Emacs for a while and it has been one of my favorite editors of all time, even more so than Vim. However, I've had a problem in regards to setting tabs and spaces.

Whenever I try to program in C or C++, whenever it auto-indents, it uses spaces instead of tabs. However, I would prefer it if they were hard tabs that appeared visually as 4 spaces.

Right now in my ~/.emacs.d/init.el, I have this:

(setq tab-width 4)
(setq c-default-style "linux")
(setq-default c-basic-offset 4
          tab-width 4
          indent-tabs-mode t)

I know that there isn't anything else conflicting in the init.el that could lead to it being overridden. So far nothing that I've tried online as of yet has been able to fix it, including searching the EmacsWiki, Stack Overflow, and Emacs Stack Exchange.

I'm using GNU Emacs 26.3 on Ubuntu GNU/Linux 20.04.

1
  • Please don't post the same question here and on StackOverflow. Please choose one and delete the other. Thx.
    – Drew
    Commented Jun 22, 2020 at 15:03

2 Answers 2

0

The usual warnings apply, of course: your nice 4-wide TABs indentation may look like crap in someone else's editor unless they also happen to have theirs set to 4-wide TABs (the historical standard, which Emacs follows, is that TABs occupy 8 columns).

So, assuming you're still happy with this idea:

Your code should do the trick I think, except the (tab-width 4) will signal an error (because tab-width is not a function) and stop processing the rest of your init file.

1
  • I've already tried it. I fixed the tab-width problem and already applied what I put in the question. The problem is that it DOESN'T work.
    – Roy
    Commented Jun 22, 2020 at 6:54
0

Turns out all I needed was to add this:

(setq backward-delete-char-untabify-method 'hungry)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.