Emacs Notes

The these are some general notes about Emacs.


Cutting, pasting and formatting

Set Mark: C-<space> or M-_

Kill marked region: C-w

Copy marked region: M-w

Reformat current paragraph or marked region: M-q

Force emacs to output spaces instead of tabs (auto "untabify"):
(custom-set-variables '(indent-tabs-mode nil))
Setting the default fill column to 75
(setq-default fill-column 75)
Set the c-mode indentation offset to 8 spaces:
(defun my-c-mode-common-hook()
        (setq c-mode-basic-offset 8))

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
Disable down-arrow and C-n from adding newlines at the end of a buffer
(setq next-line-add-newlines nil)

Buffer movement shortcuts

Goto line (C-x g)
(global-set-key "\C-xg" 'goto-line)
Goto beginning of buffer (C-x a, Standard Key M-<)
(global-set-key "\C-xa" 'beginning-of-buffer)
Goto end of buffer (C-x e, Standard Key M->)
(global-set-key "\C-xe" 'end-of-buffer)
Revert to last saved version of buffer (C-x r)
(global-set-key "\C-xr" 'revert-buffer)

Date and Time Display Options

Display time in status bar
(display-time)
Display date and time in status bar
(setq display-time-day-and-date t)
(display-time)
Display time in 24 hour mode in status bar
(setq display-time-24hr-format t)
(display-time)

Misc. Options

Display column number
(setq column-number-mode t)
Enable visual bell
(setq visible-bell t)
Disable menu bar
(menu-bar-mode -1)

Using aspell instead of ispell

(setq-default ispell-program-name "aspell")

A function to delete trailing whitespace from the end of every line in the current buffer:

defun elc-delete-buffer-trailing-ws ()
        "get rid of trailing whitespace in all lines in current buffer"
        (interactive)
        (save-excursion
                (goto-char (point-min))
                (end-of-line)
                (delete-horizontal-space)
                (loop do (let ((inhibit-field-text-motion t))
                        (end-of-line 2)
                        (delete-horizontal-space))
                                while (/= (point) (point-max)))))

Vi-style parenthesis matching using %

(defun match-paren (arg)
        "Go to the matching paren if on a paren; otherwise insert %."
        (interactive "p")
        (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
                ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
                (t (self-insert-command (or arg 1)))))

(global-set-key "%" 'match-paren)

Confirm exit

(defun confirm-exit-emacs ()
        "ask for confirmation before exiting emacs"
        (interactive)
        (if (yes-or-no-p "Are you sure you want to exit? ")
                (save-buffers-kill-emacs)))

(global-unset-key "\C-x\C-c")
(global-set-key "\C-x\C-c" 'confirm-exit-emacs)

Valid XHTML and CSS  //  Licensed under a Creative Commons Attribution 2.5 License

$Id: emacs.html 764 2006-08-31 05:27:34Z ranga $