(defun auto_indent ()
"auto-indent the way I like it."
(interactive)
(let ((previndent (current-indentation)))
(newline)
(delete-horizontal-space)
(indent-to previndent)
) ; let
) ; auto_indent
Bind this to the return key:
(global-set-key "\015" 'auto_indent)
If I want just a newline, I can press alt-return:
(global-set-key [?\C-\M-m] 'newline)
Of course ctrl-q-ctrl-j also works. :)
I define windows-right-bracket and windows-left-bracket to increase and
decrease the indentation of the selected region, without losing the
selection:
(global-set-key [?\s-]]
'(lambda (beg end)
"indent selected range by 4 columns without losing selection."
(interactive "*r")
(let (deactivate-mark)
(set 'point_marker (point-marker))
(indent-rigidly beg end 4)
(goto-char (marker-position point_marker))
) ; let
) ; lambda
)
(global-set-key [?\s-[]
'(lambda (beg end)
"unindent selected range by 4 columns without losing selection."
(interactive "*r")
(let (deactivate-mark)
(set 'point_marker (point-marker))
(indent-rigidly beg end -4)
(goto-char (marker-position point_marker))
) ; let
) ; lambda
)
Pressing tab inserts whitespace (either tabs or spaces) to take me to the
next tab stop:
(global-set-key "\t" 'tab-to-tab-stop)
Pressing ctrl-c-t toggles between having the tab key inserting tabs or
spaces:
(global-set-key [?\C-c ?t]
'(lambda ()
"toggle tab expansion for current buffer."
(interactive)
(cond
(indent-tabs-mode
(set 'indent-tabs-mode nil)
(message "tabs will be expanded to spaces")
)
(t
(set 'indent-tabs-mode t)
(message "tabs will not be expanded to spaces")
)
) ; cond
) ; lambda
)
Emacs 23 changed the meaning of the up- and down-arrow keys to move by
screen line rather than text line. I prefer the old behaviour, so this
restores it in a backward-compatible way:
(when (fboundp 'next-logical-line)
(global-set-key [down] 'next-logical-line)
(global-set-key [up] 'previous-logical-line)
(global-set-key (kbd "M-<down>") 'next-line)
(global-set-key (kbd "M-<up>") 'previous-line)
) ; when
Note I can press alt-up-arrow and-alt-down-arrow to move by screen lines. Or
use ctrl-p and ctrl-n.
By the way, I have all the major-and-minor-mode business turned off. I do
all my editing in fundamental mode.