Why might my Emacs use spaces instead of tabs?

こ雲淡風輕ζ 提交于 2019-11-27 19:26:52

问题


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-indent-line-or-region. Does this function ignore my tabs-mode?


回答1:


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))))



回答2:


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.




回答3:


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".




回答4:


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:



回答5:


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.



来源:https://stackoverflow.com/questions/2885411/why-might-my-emacs-use-spaces-instead-of-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!