«
»

emacs

Tabs

12.10.12 | Comment?

I program a lot in Python, where white space really matters. My preference is a 4 character indent made of spaces. I am still trying to figure all this out, but here is what I have learned so far:

  • (setq-default tab-width 4) in .emacs (or init.el as the case may be) will set the tab width.
    • TODO: How do I evalute the .emacs file so I don’t have to restart emacs?
    • Here is nifty function that lets you toggle, if that is really what you want to do.
  • M-x untabify / tabify – Converts tabs to spaces and visa versa
  • The following sets a default indent of 4 spaces in the Python Major Mode: (from here)
    ;; Python Hook (add-hook 'python-mode-hook (function (lambda () (setq indent-tabs-mode nil python-indent 4))))
  • Still need to get auto-indent working
    • This almost works and has some other useful Python info. But tab doesn’t always work for indenting
    • C-c > and C-c < are the correct keys for indenting.
    • Also checkout C-M-\ which indents a whole block nicely
  • On a related note, in Python it is handy to have an indent guide, so you can quickly see what level a block is on. The package highlight-indentation does just that. It is a little rough around the edges, but is at least a good start. (See also here for useful related info)

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

You must be logged in to post a comment.


«
»