Emacs The Way I Like It

Discussion in 'NZ Computing' started by Lawrence D'Oliveiro, Nov 28, 2009.

  1. 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."
    (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.
    Lawrence D'Oliveiro, Nov 28, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil
    Replies:
    174
    Views:
    3,208
    Briscobar
    Apr 17, 2006
  2. { Listerine Enema }

    My wife's like kinda what my wife's like

    { Listerine Enema }, Jun 1, 2004, in forum: Computer Support
    Replies:
    0
    Views:
    930
    { Listerine Enema }
    Jun 1, 2004
  3. DVD Verdict
    Replies:
    0
    Views:
    404
    DVD Verdict
    Jun 18, 2004
  4. John John

    AMD Opteron: 1-way, 2-way, ... Up to 8-way.

    John John, Dec 24, 2005, in forum: Windows 64bit
    Replies:
    12
    Views:
    762
    Tony Sperling
    Dec 27, 2005
  5. Lawrence D'Oliveiro

    Choice Emacs Quotes

    Lawrence D'Oliveiro, Apr 5, 2010, in forum: NZ Computing
    Replies:
    0
    Views:
    515
    Lawrence D'Oliveiro
    Apr 5, 2010
Loading...

Share This Page