Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display indentation guides in Emacs? [closed]

I'm trying to switch to Emacs as my primary source-code editor. I really miss one thing (common in even much simpler editors) - indentation guides (unobtrusive vertical lines which show the indentation level). Is Emacs able to display them?

like image 760
Thotep Avatar asked Oct 19 '09 10:10

Thotep


People also ask

How do I remove an indentation in Emacs?

To delete just the indentation of a line, go to the beginning of the line and use M-\ ( delete-horizontal-space ), which deletes all spaces and tabs around the cursor. If you have a fill prefix, M-^ deletes the fill prefix if it appears after the newline that is deleted.

How do I tab blocks in Emacs?

Basically, select region and then C-x r t + Tab .


2 Answers

I've made a function highlight-indentation for this purpose, code is on github.

When invoking highlight-indentation without a prefix argument the current indentation level is naively guessed from major mode (python, ruby and languages based on cc-mode). Only works for space indentations. Customize highlight-indent-face to change appearance of indentation lines.

Examples (ruby, python): Ruby, Python example

I also frequently use this snippet that folds all code on an indentation level greater than the current line. It's a great way of getting a quick overview of the outline.

(defun aj-toggle-fold ()   "Toggle fold all lines larger than indentation on current line"   (interactive)   (let ((col 1))     (save-excursion       (back-to-indentation)       (setq col (+ 1 (current-column)))       (set-selective-display        (if selective-display nil (or col 1)))))) (global-set-key [(M C i)] 'aj-toggle-fold) 
like image 92
antonj Avatar answered Sep 25 '22 15:09

antonj


There now is a mode called highlight-indent-guides which seems to work quite well.

like image 30
Marco Craveiro Avatar answered Sep 25 '22 15:09

Marco Craveiro