I am trying to diagnose this problem. TAB creates 4 spaces instead of a 4 col TAB like I want. But I don't think it should because C-h v indent-tabs-mode
on the buffer in question says it is set to t
. When I check my keybindings, TAB is set to c-inde开发者_高级运维nt-line-or-region
. Does this function ignore my tabs-mode?
Tabs and indentation in Emacs is a considerably more complex subject than most people anticipate. I highly recommend spending some time reading about it -- it will almost certainly save you some confusion in the long run.
The following page at the Emacs Wiki groups together most of the relevant discussion: http://www.emacswiki.org/emacs/CategoryIndentation
There's quite a lot there, but it's worth looking through.
One or other of the TabsAreEvil and SmartTabs configurations is quite likely to be appealing to you, btw, depending on your personal opinions on the subject!
Make sure you read the page on the tab-stop-list variable. It's tucked away near the bottom of that list of links, but it's critical to understanding the behaviour of tabs in the absence of automated-indentation rules, along with things like 'tabify'.
ruler-mode is useful here as well. I enable it automatically with text-mode:
;; Use ruler in text-mode
(add-hook 'text-mode-hook
(function (lambda ()
(setq ruler-mode-show-tab-stops t)
(ruler-mode 1))))
I figured out the problem. It was inserting a tab character after all. It turns out I thought it wasn't because when I hit backspace that key is bound to c-electric-backspace
, which looks at the variable c-backspace-function
which was set to backward-delete-char-untabify
, which IMO defeats the purpose of having tabs.
Check tab-width
variable. If it is 8 (the default), then Emacs of course has to insert four spaces since a tab would be "too much".
Check of the file for Emacs "File Local Variables". These specially formatted lines can override your settings when that file is loaded.
Here is an example from the bottom of a bit of Ruby code, forcing indent to 2 spaces, and tabs converted to spaces:
# Local Variables:
# tab-width: 2
# ruby-indent-level: 2
# indent-tabs-mode: nil
# End:
Be sure to take a look at the first line of the file as well. If you see something like // -- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -- This line will override any global or mode settings.
精彩评论