Pressing tab multiple time doesn't move text to the right. Is there is a way to make it behave like Visual Studio's smart indent? First tab indents, subsequent tabs move text to the next tab stop. Thank you.
Asked
Active
Viewed 528 times
2 Answers
5
Something like this?
(defun even-more-tabby-indent (&optional arg)
"This indent function tries to be more like Microsoft's IDEs
than `C-INDENT-COMMAND' and does the following: If we're at the
beginning of the line or `C-TAB-ALWAYS-INDENT' is true or `ARG'
is non-nil, indent like a sensible text editor. Otherwise the
user probably WANTS MOAR TABS. So call `C-INSERT-TAB-FUNCTION'."
(interactive "P")
(if (or c-tab-always-indent (bolp) arg)
(c-indent-command arg)
(funcall c-insert-tab-function)))
You'll then want to bind tab insertion with something like
(defun setup-tabby-indent ()
(local-set-key (kbd "<tab>") 'even-more-tabby-indent)
(setq c-tab-always-indent nil))
(add-hook 'c-mode-hook 'setup-tabby-indent)
I haven't used MS Visual Studio in many years, so I'm not sure whether this is exactly what you're after, but hopefully it's pretty clear how to modify.

Rupert Swarbrick
- 2,793
- 16
- 26
-
Ah, as Lazylabs says, maybe you want to use (tab-to-tab-stop) instead of the (funcall c-insert-tab-function) I suggested. – Rupert Swarbrick Aug 19 '11 at 15:11