Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > NZ Computing > Emacs The Way I Like It

Thread Tools

Emacs The Way I Like It

Lawrence D'Oliveiro
Posts: n/a
I like a very simple definition of auto-indent: when I press return, the
whitespace at the start of the previous line is automatically copied down to
the new line:

(defun auto_indent ()
"auto-indent the way I like it."
(let ((previndent (current-indentation)))
(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

(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

(global-set-key [?\C-c ?t]
'(lambda ()
"toggle tab expansion for current buffer."
(set 'indent-tabs-mode nil)
(message "tabs will be expanded to spaces")
(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.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble running Emacs-EPL (to run perl in emacs). Adam Funk Perl Misc 4 01-29-2007 10:42 AM
A reftex-like mode for ruby in emacs ? Vincent Fourmond Ruby 7 01-03-2007 08:50 PM
object-like macro used like function-like macro Patrick Kowalzick C++ 5 03-14-2006 03:30 PM
Re: Eclipse Search and Replace with Emacs like Case Sensitivity Java 0 01-25-2005 04:42 PM
Re_: Best way to run ipython inside of emacs shell? Yaroslav Bulatov Python 1 08-03-2004 05:14 PM