I am using Emacs for Python developement. My team is using Tab indentation, so I must do the same. The problem is that I can't figure out how to make python-mode use tabs instead of spaces. I want Emacs to automatically indent my line to the correct level when I press Ctrl-j.


You'll want to add the following to your .emacs file:

(add-hook 'python-mode-hook
  (lambda () (setq indent-tabs-mode t))
  • I'm a spoiled vim user, so I really don't know. What does the '-character do/mean? I find it rather odd to see an odd number of those in one statement ... – Bananguin Mar 18 '13 at 20:55
  • @user1129682 quotation, see gnu.org/software/emacs/manual/html_node/elisp/Quoting.html – Ulrich Dangel Mar 18 '13 at 21:04
  • @user1129682, emacs is mostly written in LISP, and the above is a LISP statement adding a function to python-mode-hook, a list of functions to run when starting to edit Python code. What the apostrophe does is to tell LISP that python-mode-hook is the variable to modify, not its name. – vonbrand Mar 19 '13 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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