Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
doc:emacs-config [2014/05/09 19:58] – created gkazhoya | doc:emacs-config [2015/04/27 19:10] (current) – gkazhoya | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Emacs Initialization File ====== | ====== Emacs Initialization File ====== | ||
- | The most configuration you need to do is in the Emacs init file. | + | The main part of configuring your IDE is done through |
- | According to the GNU Emacs Manual, "Emacs looks for your init file using the filenames '' | + | According to the GNU Emacs Manual, "Emacs looks for your init file using the filenames '' |
- | Alternatively, | + | Alternatively, |
+ | |||
+ | At the bottom of this doc is an excerpt from the '' | ||
+ | The simple settings are already provided with comments and won't be explained further, just try them out. | ||
+ | For more documentation and to know what are possible values of variables use '' | ||
+ | |||
+ | If the configuration file will give errors you will see an error buffer on Emacs startup. Most usual causes of errors are missing extension source files and incompatibilities between different Emacs versions. For each '' | ||
+ | |||
+ | <code lisp> | ||
+ | (add-to-list ' | ||
+ | (require ' | ||
+ | </ | ||
+ | |||
+ | For debugging problems caused by version incompatibilities just Google or use the documentation hotkeys. | ||
+ | |||
+ | |||
+ | === Example init.el for programming in Lisp === | ||
+ | |||
+ | <code lisp> | ||
+ | |||
+ | ;;; -*- mode: Emacs-Lisp -*- | ||
+ | ;;; Emacs version: 24.4 | ||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | ;; Set this to 'dark if your background is black | ||
+ | (setq frame-background-mode ' | ||
+ | |||
+ | ;;; Set the editing mode for *scratch* buffer to text (it's Lisp per default) | ||
+ | (setq initial-major-mode ' | ||
+ | |||
+ | ;;; Set the mode for buffers with unknown mode to text | ||
+ | ;;; previously default-major-mode in emacs23 | ||
+ | (setq major-mode ' | ||
+ | |||
+ | ;;; Highlight the opening / closing brackets | ||
+ | (show-paren-mode t) | ||
+ | |||
+ | ;;; Default tab and indentation width | ||
+ | (setq default-tab-width 2) | ||
+ | (setq standard-indent 2) | ||
+ | |||
+ | ;;; Display the column in the status (mode part) | ||
+ | (column-number-mode t) | ||
+ | |||
+ | ;;; Don't use tabs for whitespace while indenting | ||
+ | (setq indent-tabs-mode nil) | ||
+ | (setq-default indent-tabs-mode nil) | ||
+ | |||
+ | ;;; No menu bar and toolbar on the top of emacs | ||
+ | ;;; I kind of like the menu bar right now, so it will stay. | ||
+ | ;;; (menu-bar-mode -1) | ||
+ | (tool-bar-mode -1) | ||
+ | |||
+ | ;;; Highlight and overwrite selected regions (CUA mode) | ||
+ | ;;; new in emacs24 | ||
+ | (cua-mode 1) | ||
+ | (setq cua-enable-cua-keys nil) | ||
+ | (setq cua-enable-modeline-indications t) | ||
+ | (setq cua-remap-control-v nil) | ||
+ | (setq cua-remap-control-z nil) | ||
+ | |||
+ | ;;; Enable editing in columns: C-x C-n (enable) and C-u C-x C-n (disable) | ||
+ | (put ' | ||
+ | |||
+ | ;; Enable narrowing of pages: C-x n p (narrow) and C-x n w (widen) | ||
+ | (put ' | ||
+ | |||
+ | ;;; Editing code in different programming languages. Emacs major modes. | ||
+ | ;;; Lisp specific things are in the bottom of the file. | ||
+ | (autoload ' | ||
+ | (autoload ' | ||
+ | (autoload ' | ||
+ | (autoload ' | ||
+ | (autoload ' | ||
+ | (autoload ' | ||
+ | (setq auto-mode-alist | ||
+ | (append ' | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | (" | ||
+ | auto-mode-alist)) | ||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | ;;; Fix for the DEL key that acts like BACKSPACE on some machines | ||
+ | (global-set-key ' | ||
+ | |||
+ | ;;; Use regexp search per default. | ||
+ | ;;; Swap regexp and normal search key bindings. | ||
+ | (global-set-key (kbd " | ||
+ | (global-set-key (kbd " | ||
+ | (global-set-key (kbd " | ||
+ | (global-set-key (kbd " | ||
+ | (global-set-key (kbd " | ||
+ | (global-set-key (kbd " | ||
+ | |||
+ | ;;; Disable iconification bindings, they are annoying | ||
+ | (global-unset-key " | ||
+ | (global-unset-key " | ||
+ | |||
+ | ;;; Moving through windows faster | ||
+ | (global-set-key (kbd "C-x < | ||
+ | (global-set-key (kbd "C-x < | ||
+ | (global-set-key (kbd "C-x < | ||
+ | (global-set-key (kbd "C-x < | ||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | ;;; Emacs should always ask for confirmation on exit | ||
+ | (setq confirm-kill-emacs ' | ||
+ | |||
+ | ;;; Enable copy-pasting between programs (Kill-ring <-> x11) | ||
+ | (setq x-select-enable-clipboard t) | ||
+ | (setq interprogram-paste-function ' | ||
+ | |||
+ | ;;; Start emacs server for emacsclient | ||
+ | (server-start) | ||
+ | |||
+ | ;;; Disable recursive minibuffers | ||
+ | (setq minibuffer-max-depth nil) | ||
+ | |||
+ | ;;; Scrolling is too agressive in emacs. | ||
+ | (setq scroll-step 1) ; sets the keyboard scrolling step | ||
+ | (setq scroll-margin 1) ; sets the margin for keyboard scrolling | ||
+ | (setq scroll-conservatively 5) ; centers the window on the point conservatively | ||
+ | |||
+ | ;;; Turn off the startup screen | ||
+ | (setq inhibit-startup-screen t) | ||
+ | |||
+ | ;;; *scratch* should be empty on startup | ||
+ | (setq initial-scratch-message nil) | ||
+ | |||
+ | ;;; Don't clutter the directories with *~ backup files | ||
+ | ;;; and automatically overwrite them up to a number of backup versions | ||
+ | (setq backup-directory-alist (quote ((" | ||
+ | (setq delete-old-versions t) | ||
+ | (setq version-control t) | ||
+ | (setq kept-new-versions 3) | ||
+ | (setq kept-old-versions 3) | ||
+ | |||
+ | ;;; Don't automatically save the window configuration. | ||
+ | ;;; Use M-x desktop-save and M-x desktop-clear instead. | ||
+ | (setq desktop-save-mode nil) | ||
+ | |||
+ | ;;; Enable undo on window configuration: | ||
+ | (winner-mode) | ||
+ | |||
+ | ;;; Set the default browser to open URLs | ||
+ | ;;; Soon we should switch to eww, but for now let's keep the default. | ||
+ | ;;; (setq browse-url-browser-function (quote browse-url-default-browser)) | ||
+ | |||
+ | ;;; Enable tooltips: bubbles with help text | ||
+ | (gud-tooltip-mode t) | ||
+ | |||
+ | ;;; Enable autocompletion suggestions for minibuffer | ||
+ | (icomplete-mode 1) | ||
+ | |||
+ | ;;; When opening Lisp files, don't ask if the variables are safe for this list. | ||
+ | ;;; These are the variables from slime. | ||
+ | (setq safe-local-variable-values | ||
+ | (quote ((TeX-PDF . t) (readtable . nisp) (readtable . :nisp) | ||
+ | (Package . NISP) (Syntax . Common-Lisp) (Package . SAX) | ||
+ | (Encoding . utf-8) (Syntax . COMMON-LISP) (Package . CL-PPCRE) | ||
+ | (package . rune-dom) (readtable . runes) | ||
+ | (Syntax . ANSI-Common-Lisp) (Base . 10) (lexical-binding . t)))) | ||
+ | |||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | ;;; All the packages should go into the PACKAGES directory. | ||
+ | ;;; Let emacs know about it. | ||
+ | (add-to-list ' | ||
+ | |||
+ | ;;; Yasnippets: templates for standard structures. E.g. bsd TAB. | ||
+ | (require ' | ||
+ | (setq yas-snippet-dirs (quote (" | ||
+ | (yas-global-mode 1) | ||
+ | |||
+ | ;;; Whitespace highlights lines longer than 80 characters and similar. | ||
+ | ;;; It is included in emacs23 or later. | ||
+ | (require ' | ||
+ | (setq-default whitespace-style '(face trailing lines-tail indentation:: | ||
+ | (setq-default whitespace-line-column 80) | ||
+ | (setq-default whitespace-indentation nil) | ||
+ | (global-whitespace-mode 1) | ||
+ | (set-face-attribute ' | ||
+ | :foreground "# | ||
+ | :background nil | ||
+ | :weight ' | ||
+ | (set-face-attribute ' | ||
+ | :background "# | ||
+ | |||
+ | ;;; Autocomplete in the minibuffer for filenames etc. | ||
+ | (require ' | ||
+ | (ido-mode ' | ||
+ | (ido-everywhere 1) | ||
+ | (setq ido-completion-buffer-all-completions t) | ||
+ | (setq ido-auto-merge-delay-time 2) | ||
+ | (setq ido-default-buffer-method (quote selected-window)) | ||
+ | (setq ido-default-file-method (quote samewindow)) | ||
+ | (setq ido-enable-dot-prefix t) | ||
+ | (setq ido-enable-flex-matching t) | ||
+ | (setq ido-max-window-height 5) | ||
+ | (setq ido-read-file-name-as-directory-commands (quote (find-dired))) | ||
+ | (setq ido-show-dot-for-dired t) | ||
+ | (setq ido-use-filename-at-point (quote guess)) | ||
+ | (setq ido-use-url-at-point t) | ||
+ | |||
+ | ;;; When working with rectangles, highlight them | ||
+ | (autoload ' | ||
+ | "Set mark for rectangle." | ||
+ | (autoload ' | ||
+ | " | ||
+ | (autoload ' | ||
+ | "Kill a rectangular region and save it in the kill ring." t) | ||
+ | (autoload ' | ||
+ | "Copy a rectangular region to the kill ring." t) | ||
+ | (autoload ' | ||
+ | "Drag out a rectangular region with the mouse." | ||
+ | (define-key ctl-x-map " | ||
+ | (define-key ctl-x-map [?r ?\C-\ ] ' | ||
+ | (define-key ctl-x-map " | ||
+ | (define-key ctl-x-map " | ||
+ | (define-key ctl-x-map " | ||
+ | (define-key global-map [S-down-mouse-1] ' | ||
+ | |||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | (add-to-list ' | ||
+ | (require ' | ||
+ | (invoke-rosemacs) | ||
+ | |||
+ | (global-set-key " | ||
+ | (setq ros-completion-function (quote ido-completing-read)) | ||
+ | |||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | ;;; Adjust the indentation for MAKE-INSTANCE | ||
+ | (put ' | ||
+ | |||
+ | ;;; Paredit mode for editing lisp code. | ||
+ | ;;; Automatically generates closing parenthesis, | ||
+ | ;;; It is autoloaded in case one opens emacs without intending to program Lisp. | ||
+ | (autoload ' | ||
+ | (add-hook ' | ||
+ | (add-hook ' | ||
+ | (add-hook ' | ||
+ | (add-hook ' | ||
+ | (add-hook ' | ||
+ | (add-hook ' | ||
+ | (add-hook ' | ||
+ | (eval-after-load ' | ||
+ | ' | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | ;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
+ | |||
+ | (add-to-list ' | ||
+ | (require ' | ||
+ | (setq slime-backend " | ||
+ | (add-hook ' | ||
+ | |||
+ | (setq inferior-lisp-program "/ | ||
+ | (setq slime-lisp-implementations nil) | ||
+ | |||
+ | (add-to-list ' | ||
+ | (setq slime-contribs ' | ||
+ | | ||
+ | ;; slime-c-p-c | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ;; | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | (setq slime-startup-animation nil) | ||
+ | (setq slime-kill-without-query-p t) | ||
+ | (setq slime-repl-history-file " | ||
+ | (setq slime-repl-history-size 2000) | ||
+ | (setq slime-repl-only-save-lisp-buffers nil) | ||
+ | (setq slime-complete-symbol-function (quote slime-fuzzy-complete-symbol)) | ||
+ | (setq slime-ros-completion-function (quote ido-completing-read)) | ||
+ | |||
+ | (when (file-exists-p "/ | ||
+ | ;; the last slash in the following is crucial | ||
+ | (setq common-lisp-hyperspec-root " | ||
+ | |||
+ | (eval-after-load ' | ||
+ | ' | ||
+ | ;; Fix for M-, when using it with dired and A | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | (let ((yas-fallback-behavior nil)) | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | (let ((ppss (syntax-ppss))) | ||
+ | (if (nth 3 ppss) | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | (let ((ppss (syntax-ppss))) | ||
+ | (if (nth 3 ppss) | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | ;;; [ and ] should be handled paranthesis-like in lisp files. | ||
+ | (modify-syntax-entry ?\[ " | ||
+ | (modify-syntax-entry ?\] " | ||
+ | |||
+ | ;;; Global key bindings | ||
+ | (global-set-key " | ||
+ | (global-set-key " | ||
+ | ' | ||
+ | | ||
+ | | ||
+ | |||
+ | </ |