Why can my Emacs use spaces instead of tabs?

I am trying to diagnose this problem. TAB creates 4 spaces instead of 4 col TAB as I want. But I do not think this is necessary, because Ch v indent-tabs-mode in the buffer in question says that it is set to t . When I check my bindings, TAB is set to c-indent-line-or-region . Does this function ignore my tab-mode?

+2
source share
5 answers

Tabs and padding in Emacs are a much more complex subject than most people predict. I highly recommend spending some time reading about this - it will almost certainly save you some confusion in the long run.

The following page in the Emacs Wiki brings together most of the relevant discussions: http://www.emacswiki.org/emacs/CategoryIndentation

There are many, but worth a look.

One or another configuration of TabsAreEvil and SmartTabs is likely to be attractive to you, by the way, depending on your personal opinions on this matter!

Make sure you read the page in the tab list variable. It’s hidden at the bottom of this list of links, but it’s crucial to understanding the behavior of tabs in the absence of automatic indentation rules, as well as things like tabify.

Proper mode is also useful here. I turn it on automatically in text mode:

 ;; Use ruler in text-mode (add-hook 'text-mode-hook (function (lambda () (setq ruler-mode-show-tab-stops t) (ruler-mode 1)))) 
+3
source

I understood the problem. In the end, he inserted a tab character. Turns out I thought this wasn't because when I click backspace, this key is bound to c-electric-backspace , which looks at the c-backspace-function variable that was set to backward-delete-char-untabify that IMO defeats the goal of having tabs.

+2
source

Check out the variable tab-width . If it's 8 (the default), Emacs, of course, should insert four spaces, as the tab will be "too much."

+1
source

File Check for Emacs "Local File Variables" . These specially formatted lines may override your settings when loading this file.

Here is an example from the bottom of the Ruby code bit, causing up to 2 spaces to be indented, and tabs converted to spaces:

 # Local Variables: # tab-width: 2 # ruby-indent-level: 2 # indent-tabs-mode: nil # End: 
+1
source

Be sure to take a look at the first line of the file. If you see something like // - tab-width: 4; Mode: C ++; c-basic-offset: 4; indent-tabs-mode: nil - This line overrides any global or mode settings.

+1
source

Source: https://habr.com/ru/post/1316112/


All Articles