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?
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.
Basically, select region and then C-x r t + Tab .
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):
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)
There now is a mode called highlight-indent-guides which seems to work quite well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With