
I personally don’t use it, but it might tickle your fancy. The Smart-tabs-mode package helps Emacs indent with tabs and align with spaces in various languages. ( setq backward-delete-char-untabify-method 'hungry ) SmartTabs (Bonus) Instead of backspacing the whole tab, it backspaces the tab one space at a time. Making Backspace Properly Delete TabsĮmacs has a strange default behavior when backspacing tabs. You can view a list of ascii character IDs here. The line that is a little bit confusing to read is the one where we actually set the pipe character.Īll you really need to know about it is that 124 is the ascii ID of the pipe character (“|”). This is an example of #c1c1c1 on a light background. This is an example of #636363 on a dark background. If you’re using a light theme in Emacs, you’ll want a lighter color such as #c1c1c1. I set the text color of our pipe character to be #636363 which is a nice color if you’re using a dark-themed Emacs theme.


I have separated the whitespace-display-mappings portion of the snippet with a newline because it is the more confusing-to-read part of it. ( global-whitespace-mode ) ( setq whitespace-style ' ( face tabs tab-mark trailing )) ( custom-set-faces ' ( whitespace-tab (( t ( :foreground "#636363" ))))) ( setq whitespace-display-mappings ' (( tab-mark 9 )))

If you want to highlight spaces too, please refer to ErgoEmacs’ article on making whitespace visible. We will accomplish this by making tabs appear visible as a “|” (pipe) character. They are both whitespace characters that can easily be confused for eachother. Something that I feel that is very important to have in an editor is a way to identify spaces and tabs easily.
EMACS PYTHON INDENT BLOCK HOW TO
To accomplish this, refer to my How to Indent a Selection in Emacs guide. ( setq-default electric-indent-inhibit t ) Indent a selection left or right

Something that was driving me nuts was Emacs electric-indent indenting the previous line when I press enter. Making Indentation Behave Sanely (Electric Indent) ( setq backward-delete-char-untabify-method 'hungry ) (OPTIONAL) Shift width for evil-mode users For the vim-like motions of ">" and "> or << motion to indent or de-indent text. START TABS CONFIG Create a variable for our preferred tab width ( setq custom-tab-width 2 ) Two callable functions for enabling/disabling tabs in Emacs ( defun disable-tabs () ( setq indent-tabs-mode nil )) ( defun enable-tabs () ( local-set-key ( kbd "TAB" ) 'tab-to-tab-stop ) ( setq indent-tabs-mode t ) ( setq tab-width custom-tab-width )) Hooks to Enable Tabs ( add-hook 'prog-mode-hook 'enable-tabs ) Hooks to Disable Tabs ( add-hook 'lisp-mode-hook 'disable-tabs ) ( add-hook 'emacs-lisp-mode-hook 'disable-tabs ) Language-Specific Tweaks ( setq-default python-indent-offset custom-tab-width ) Python ( setq-default js-indent-level custom-tab-width ) Javascript Making electric-indent behave sanely ( setq-default electric-indent-inhibit t ) Make the backspace properly erase the tab instead of removing 1 space at a time. To learn how to customize tabs and spaces behavior differently, please refer to the Breaking It Down section. This configuration is meant for users that prefer tabs over spaces. Highlighting Tabs and Spaces Differently.Making Indentation Behave Sanely (Electric Indent).Using Tabs or Spaces in Different Files.
