EmacsCrashCode

A few one-liners someone attending the EmacsCrashCourse might put in an InitFile.

Many of these settings are not at all typical; some are quite personal, and other still could be either annoying or confusing for beginners. However a “grab bag”-style list of Emacs customizations to experiment with may be quicker than hunting such lines down in the EmacsManual – if they’re even there.

General userinterface and appearance

 (tool-bar-mode -1)                             ; No toolbar
 (menu-bar-mode -1)                             ; No menubar
 (define-key menu-bar-tools-menu [games] nil)   ; Remove games menu
 (scroll-bar-mode -1)                           ; No scrollbar
 (set-scroll-bar-mode 'right)                   ; Scrollbar on the right
 (setq inhibit-startup-message t)               ; No message at startup
 (setq visible-bell t)                          ; No beep when reporting errors
 (global-font-lock-mode 1)                      ; Color enabled
 (set-background-color "darkblue")              ; Background color
 (set-face-background 'region "gray80")         ; Color for selected lines
 (global-hl-line-mode t)                        ; Highlight cursor line
 (add-to-list 'default-frame-alist '(font . "")); Change fonts

Cursor and mouse

 (blink-cursor-mode 0)                          ; No blinking cursor
 (setq track-eol nil)                           ; Cursor don't track end-of-line
 (setq mouse-yank-at-point t)                   ; Paste at cursor position
 (setq scroll-preserve-screen-position t)       ; Scroll without moving cursor
 (mouse-avoidance-mode 'jump)                   ; Mouse avoids cursor
 (set-cursor-color "black")                     ; Cursor color
 (column-number-mode t)                         ; Show column number in mode-line
 (mouse-wheel-mode t)                           ; Mouse-wheel enabled

Customization for your locale, environment and computer.

 (setq european-calendar-style 't)              ; European style calendar
 (setq calendar-week-start-day 1)               ; Week starts monday
 (setq ps-paper-type 'a4)                       ; Specify printing format
 (setq ispell-dictionary "english")             ; Set ispell dictionary
 (setq shell-file-name "/bin/bash")             ; Set Shell for M-| command
 (setq tex-shell-file-name "/bin/bash")         ; Set Shell used by TeX
 (setq grep-command "grep -i -nH -e ")          ; Set grep command options
 (setq exec-path (append exec-path '("/bin")))  ; Change binary path

Files and sessions

 (setq auto-save-timeout 60)                    ; Autosave every minute
 (desktop-save-mode t)                          ; Save session before quitting
 (setq confirm-kill-emacs 'yes-or-no-p)         ; Confirm quit
 (speedbar t)                                   ; Quick file access with bar
 (setq make-backup-files nil)                   ; No backup files ~
 (setq read-file-name-completion-ignore-case 't); Ignore case when completing file names

Tabs, spaces, lines and parenthesis

 (setq-default indent-tabs-mode nil)            ; Use spaces instead of tabs
 (setq tab-width 4)                             ; Length of tab is 4 SPC
 (setq sentence-end-double-space nil)           ; Sentences end with one space
 (setq truncate-partial-width-windows nil)      ; Don't truncate long lines
 (setq-default indicate-empty-lines t)          ; Show empty lines
 (setq next-line-add-newlines t)                ; Add newline when at buffer end
 (setq require-final-newline 't)                ; Always newline at end of file
 (global-linum-mode 1)                          ; Show line numbers on buffers
 (show-paren-mode 1)                            ; Highlight parenthesis pairs
 (setq blink-matching-paren-distance nil)       ; Blinking parenthesis
 (setq show-paren-style 'expression)            ; Highlight text between parens

Buffers and windows

 (setq pop-up-frames t)                         ; Buffers in separate frames
 (setq frame-title-format "%b - emacs")         ; Use buffer name as frame title
 (global-set-key "\C-x\C-b" 'buffer-menu)       ; CxCb puts point on buffer list
 (setq window-min-height 10)                    ; Minimal height of windows
 (setq enable-recursive-minibuffers t)          ; Stack  minibuffers
 (icomplete-mode t)                             ; Completion in mini-buffer
 (setq read-buffer-completion-ignore-case 't)   ; Ignore case when completing buffer names
 (windmove-default-keybindings)                 ; Shift arrows switch windows
                                                ; Note: This interferes with
                                                ;  cua-mode where shift arrow starts
                                                ;  marking. An alternative is
                                                ;  (windmove-default-keybindings 'meta)
 (setq-default case-fold-search t)              ; Search is case sensitive

Key bindings

 (setq suggest-key-bindings nil)                ; No key-binsing hints for M-x
 (global-unset-key "\C-x\C-v")                  ; Suppress a shortcut
 (cua-mode t)                                   ; Cut/Paste with C-x/C-c/C-v

Miscellaneous

 (put 'narrow-to-region  'disabled nil)         ; Allow narrow-to-region command
 (setq disabled-command-hook nil)               ; Allow all disabled commands
 (setq undo-limit 100000)                       ; Increase number of undo
 (defalias 'qrr 'query-replace-regexp)          ; Define an alias
 (setq default-major-mode 'text-mode)           ; Text-mode is default mode
 (add-hook 'text-mode-hook 'turn-on-auto-fill)  ; auto-formatting in text-mode
 (defalias 'yes-or-no-p 'y-or-n-p)              ; y/n instead of yes/no
 (require 'cl)                                  ; Use Common Lisp features
                                                ; Note: There are some problems
                                                ;  with this. It might be better
                                                ;  to just use it when compiling
                                                ;  elisp files, see the elisp manual.

Some of the functions called with a ‘nil’ argument work slightly better with a negative numeric argument. For example the following are called with ‘nil’ but their help in Emacs 23.X mentions that

 (tool-bar-mode nil)                            ; No toolbar
 (mouse-wheel-mode t)                           ; Mouse-wheel enabled
 (column-number-mode t)                         ; Show column number in mode-line
 (global-hl-line-mode t)                        ; Highlight cursor line
 (blink-cursor-mode 0)                          ; No blinking cursor
 (icomplete-mode t)                             ; Completion in mini-buffer
 (desktop-save-mode t)                          ; Save session before quitting
 (speedbar t)                                   ; Quick file access with bar
 (cua-mode t)                                   ; Cut/Paste with C-x/C-c/C-v

See also: PopularOptions.

For some functions listed above (i.e. ‘speedbar’) it may even be a bit confusing to use ‘t’ or ‘nil’ as an argument, because ‘nil’ toggles the relevant mode, instead of always turning it off. Should we update the list of functions to explicitly use numeric arguments? – GiorgosKeramidas


CategoryDotEmacs