Skip to content

Instantly share code, notes, and snippets.

@d11wtq
Created September 28, 2011 16:46
Show Gist options
  • Save d11wtq/1248449 to your computer and use it in GitHub Desktop.
Save d11wtq/1248449 to your computer and use it in GitHub Desktop.
;;; dwim-tab.el --- minor mode to force indentation when TAB would otherwise stall
(defun dwim-tab ()
"Indents normally once, then switches to tab-to-tab-stop if invoked again.
Always performs tab-to-tab-stop if the first TAB press does not cause the
point to move."
(interactive)
(when (or (eq last-command this-command)
(= (point) (progn
(indent-for-tab-command)
(point))))
(tab-to-tab-stop)))
(define-minor-mode dwim-tab-mode
"Toggle dwim-tab-mode.
With a non-nil argument, turns on dwim-tab-mode. With a nil argument, turns it
off.
When dwim-tab-mode is enabled, pressing the TAB key once will behave as normal,
but pressing it subsequent times, will continue to indent, using
tab-to-tab-stop.
If dwim-tab determines that the first TAB key press resulted in no movement of
the point, it will indent according to tab-to-tab-stop instead."
:lighter " DWIM"
:keymap '(("\t" . dwim-tab)))
(provide 'dwim-tab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment