mirror of
				https://github.com/larstvei/dot-emacs.git
				synced 2025-11-04 09:20:11 +00:00 
			
		
		
		
	Tweaked the markdown.
This commit is contained in:
		
							parent
							
								
									e21fc91384
								
							
						
					
					
						commit
						eac3bdfe80
					
				
							
								
								
									
										365
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										365
									
								
								README.md
									
									
									
									
									
								
							@ -62,15 +62,17 @@ To avoid doing this each time a change is made we can add a function to
 | 
				
			|||||||
the `after-save-hook` ensuring to always tangle and byte-compile the
 | 
					the `after-save-hook` ensuring to always tangle and byte-compile the
 | 
				
			||||||
`org`-document after changes.
 | 
					`org`-document after changes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun init-hook ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun init-hook ()
 | 
				
			||||||
  "If the current buffer is 'init.org' the code-blocks are
 | 
					  "If the current buffer is 'init.org' the code-blocks are
 | 
				
			||||||
    tangled, and the tangled file is compiled."
 | 
					tangled, and the tangled file is compiled."
 | 
				
			||||||
  (when (equal (buffer-file-name)
 | 
					  (when (equal (buffer-file-name)
 | 
				
			||||||
               (expand-file-name (concat user-emacs-directory "init.org")))
 | 
					               (expand-file-name (concat user-emacs-directory "init.org")))
 | 
				
			||||||
    (org-babel-tangle)
 | 
					    (org-babel-tangle)
 | 
				
			||||||
    (byte-compile-file (concat user-emacs-directory "init.el"))))
 | 
					    (byte-compile-file (concat user-emacs-directory "init.el"))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'after-save-hook 'init-hook)
 | 
					(add-hook 'after-save-hook 'init-hook)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Package
 | 
					## Package
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -78,19 +80,24 @@ Managing extensions for Emacs is simplified using `package` which
 | 
				
			|||||||
is built in to Emacs 24 and newer. To load downloaded packages we
 | 
					is built in to Emacs 24 and newer. To load downloaded packages we
 | 
				
			||||||
need to initialize `package`.
 | 
					need to initialize `package`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (require 'package)
 | 
					```lisp
 | 
				
			||||||
    (package-initialize)
 | 
					(require 'package)
 | 
				
			||||||
 | 
					(package-initialize)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Packages can be fetched from different mirrors, [melpa](http://melpa.milkbox.net/#/) is the largest
 | 
					Packages can be fetched from different mirrors, [melpa](http://melpa.milkbox.net/#/) is the largest
 | 
				
			||||||
archive and is well maintained.
 | 
					archive and is well maintained.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-to-list 'package-archives
 | 
					```lisp
 | 
				
			||||||
 | 
					(add-to-list 'package-archives
 | 
				
			||||||
             '("MELPA" . "http://melpa.milkbox.net/packages/") t)
 | 
					             '("MELPA" . "http://melpa.milkbox.net/packages/") t)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
We can define a predicate that tells us wither or not the newest version
 | 
					We can define a predicate that tells us wither or not the newest version
 | 
				
			||||||
of a package is installed.
 | 
					of a package is installed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun newest-package-installed-p (package)
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun newest-package-installed-p (package)
 | 
				
			||||||
  "Return true if the newest available PACKAGE is installed."
 | 
					  "Return true if the newest available PACKAGE is installed."
 | 
				
			||||||
  (when (package-installed-p package)
 | 
					  (when (package-installed-p package)
 | 
				
			||||||
    (let* ((local-pkg-desc (or (assq package package-alist)
 | 
					    (let* ((local-pkg-desc (or (assq package package-alist)
 | 
				
			||||||
@ -99,14 +106,16 @@ of a package is installed.
 | 
				
			|||||||
      (and local-pkg-desc newest-pkg-desc
 | 
					      (and local-pkg-desc newest-pkg-desc
 | 
				
			||||||
           (version-list-= (package-desc-vers (cdr local-pkg-desc))
 | 
					           (version-list-= (package-desc-vers (cdr local-pkg-desc))
 | 
				
			||||||
                           (package-desc-vers (cdr newest-pkg-desc)))))))
 | 
					                           (package-desc-vers (cdr newest-pkg-desc)))))))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Let's write a function to install a package if it is not installed or
 | 
					Let's write a function to install a package if it is not installed or
 | 
				
			||||||
upgrades it if a new version has been released. Here our predicate comes
 | 
					upgrades it if a new version has been released. Here our predicate comes
 | 
				
			||||||
in handy.
 | 
					in handy.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun upgrade-or-install-package (package)
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun upgrade-or-install-package (package)
 | 
				
			||||||
  "Unless the newest available version of PACKAGE is installed
 | 
					  "Unless the newest available version of PACKAGE is installed
 | 
				
			||||||
    PACKAGE is installed and the current version is deleted."
 | 
					PACKAGE is installed and the current version is deleted."
 | 
				
			||||||
  (unless (newest-package-installed-p package)
 | 
					  (unless (newest-package-installed-p package)
 | 
				
			||||||
    (let ((pkg-desc (assq package package-alist)))
 | 
					    (let ((pkg-desc (assq package package-alist)))
 | 
				
			||||||
      (when pkg-desc
 | 
					      (when pkg-desc
 | 
				
			||||||
@ -114,6 +123,7 @@ in handy.
 | 
				
			|||||||
                        (package-version-join
 | 
					                        (package-version-join
 | 
				
			||||||
                         (package-desc-vers (cdr pkg-desc)))))
 | 
					                         (package-desc-vers (cdr pkg-desc)))))
 | 
				
			||||||
      (package-install package))))
 | 
					      (package-install package))))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The `package-refresh-contents` function downloads archive descriptions,
 | 
					The `package-refresh-contents` function downloads archive descriptions,
 | 
				
			||||||
this is a major bottleneck in this configuration. To avoid this we can
 | 
					this is a major bottleneck in this configuration. To avoid this we can
 | 
				
			||||||
@ -123,10 +133,12 @@ second specifies wither one should update during the initialization. The
 | 
				
			|||||||
third is a path to a file where a time-stamp is stored in order to check
 | 
					third is a path to a file where a time-stamp is stored in order to check
 | 
				
			||||||
when packages were updated last.
 | 
					when packages were updated last.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defvar days-between-updates 1)
 | 
					```lisp
 | 
				
			||||||
    (defvar do-package-update-on-init t)
 | 
					(defvar days-between-updates 1)
 | 
				
			||||||
    (defvar package-last-update-file
 | 
					(defvar do-package-update-on-init t)
 | 
				
			||||||
 | 
					(defvar package-last-update-file
 | 
				
			||||||
  (expand-file-name (concat user-emacs-directory ".package-last-update")))
 | 
					  (expand-file-name (concat user-emacs-directory ".package-last-update")))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The tricky part is figuring out when the last time the Emacs was updated!
 | 
					The tricky part is figuring out when the last time the Emacs was updated!
 | 
				
			||||||
Here is a hacky way of doing it, using [time-stamps](http://www.gnu.org/software/emacs/manual/html_node/emacs/Time-Stamps.html). By adding a
 | 
					Here is a hacky way of doing it, using [time-stamps](http://www.gnu.org/software/emacs/manual/html_node/emacs/Time-Stamps.html). By adding a
 | 
				
			||||||
@ -134,9 +146,10 @@ time-stamp to the a file, we can determine wither or not to do an
 | 
				
			|||||||
update. After that we must run the `time-stamp`-function to update the
 | 
					update. After that we must run the `time-stamp`-function to update the
 | 
				
			||||||
time-stamp.
 | 
					time-stamp.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (require 'time-stamp)
 | 
					```lisp
 | 
				
			||||||
    ;; Open the package-last-update-file
 | 
					(require 'time-stamp)
 | 
				
			||||||
    (with-temp-file package-last-update-file
 | 
					;; Open the package-last-update-file
 | 
				
			||||||
 | 
					(with-temp-file package-last-update-file
 | 
				
			||||||
  (if (file-exists-p package-last-update-file)
 | 
					  (if (file-exists-p package-last-update-file)
 | 
				
			||||||
      (progn
 | 
					      (progn
 | 
				
			||||||
        ;; Insert it's original content's.
 | 
					        ;; Insert it's original content's.
 | 
				
			||||||
@ -157,12 +170,14 @@ time-stamp.
 | 
				
			|||||||
    ;; If no such file exists it is created with a time-stamp.
 | 
					    ;; If no such file exists it is created with a time-stamp.
 | 
				
			||||||
    (insert "Time-stamp: <>")
 | 
					    (insert "Time-stamp: <>")
 | 
				
			||||||
    (time-stamp)))
 | 
					    (time-stamp)))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Now we can use the function above to make sure packages are installed and
 | 
					Now we can use the function above to make sure packages are installed and
 | 
				
			||||||
up to date. Here are some packages I find useful (some of these
 | 
					up to date. Here are some packages I find useful (some of these
 | 
				
			||||||
configurations are also dependent on them).
 | 
					configurations are also dependent on them).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (when do-package-update-on-init
 | 
					```lisp
 | 
				
			||||||
 | 
					(when do-package-update-on-init
 | 
				
			||||||
  (package-refresh-contents)
 | 
					  (package-refresh-contents)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  (dolist (package
 | 
					  (dolist (package
 | 
				
			||||||
@ -188,13 +203,15 @@ configurations are also dependent on them).
 | 
				
			|||||||
             pretty-lambdada   ; the word `lambda' as the Greek letter.
 | 
					             pretty-lambdada   ; the word `lambda' as the Greek letter.
 | 
				
			||||||
             smex))            ; M-x interface with Ido-style fuzzy matching.
 | 
					             smex))            ; M-x interface with Ido-style fuzzy matching.
 | 
				
			||||||
    (upgrade-or-install-package package)))
 | 
					    (upgrade-or-install-package package)))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Require
 | 
					## Require
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Some features are not loaded by default to minimize initialization time,
 | 
					Some features are not loaded by default to minimize initialization time,
 | 
				
			||||||
so they have to be required (or loaded, if you will).
 | 
					so they have to be required (or loaded, if you will).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (dolist (feature
 | 
					```lisp
 | 
				
			||||||
 | 
					(dolist (feature
 | 
				
			||||||
         '(auto-compile             ; auto-compile .el files
 | 
					         '(auto-compile             ; auto-compile .el files
 | 
				
			||||||
           auto-complete-config     ; a configuration for auto-complete-mode
 | 
					           auto-complete-config     ; a configuration for auto-complete-mode
 | 
				
			||||||
           jedi                     ; auto-completion for python
 | 
					           jedi                     ; auto-completion for python
 | 
				
			||||||
@ -203,6 +220,7 @@ so they have to be required (or loaded, if you will).
 | 
				
			|||||||
           recentf                  ; recently opened files
 | 
					           recentf                  ; recently opened files
 | 
				
			||||||
           tex-mode))               ; TeX, LaTeX, and SliTeX mode commands
 | 
					           tex-mode))               ; TeX, LaTeX, and SliTeX mode commands
 | 
				
			||||||
  (require feature))
 | 
					  (require feature))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Sane defaults
 | 
					## Sane defaults
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -210,74 +228,93 @@ These are what *I* consider to be saner defaults.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
We can set variables to whatever value we'd like using `setq`.
 | 
					We can set variables to whatever value we'd like using `setq`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq initial-scratch-message nil     ; Clean scratch buffer.
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq initial-scratch-message nil     ; Clean scratch buffer.
 | 
				
			||||||
      inhibit-startup-message t       ; No splash screen please.
 | 
					      inhibit-startup-message t       ; No splash screen please.
 | 
				
			||||||
      default-input-method "TeX"      ; Use TeX when toggeling input method.
 | 
					      default-input-method "TeX"      ; Use TeX when toggeling input method.
 | 
				
			||||||
      ring-bell-function 'ignore      ; Quite as a mouse.
 | 
					      ring-bell-function 'ignore      ; Quite as a mouse.
 | 
				
			||||||
      doc-view-continuous t           ; At page edge goto next/previous.
 | 
					      doc-view-continuous t           ; At page edge goto next/previous.
 | 
				
			||||||
      echo-keystrokes 0.1)            ; Show keystrokes asap.
 | 
					      echo-keystrokes 0.1)            ; Show keystrokes asap.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ;; Some mac-bindings interfere with Emacs bindings.
 | 
					;; Some mac-bindings interfere with Emacs bindings.
 | 
				
			||||||
    (when (boundp 'mac-pass-command-to-system)
 | 
					(when (boundp 'mac-pass-command-to-system)
 | 
				
			||||||
  (setq mac-pass-command-to-system nil))
 | 
					  (setq mac-pass-command-to-system nil))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Some variables are buffer-local, so changing them using `setq` will only
 | 
					Some variables are buffer-local, so changing them using `setq` will only
 | 
				
			||||||
change them in a single buffer. Using `setq-default` we change the
 | 
					change them in a single buffer. Using `setq-default` we change the
 | 
				
			||||||
buffer-local variable's default value.
 | 
					buffer-local variable's default value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq-default fill-column 76                    ; Maximum line width.
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq-default fill-column 76                    ; Maximum line width.
 | 
				
			||||||
              indent-tabs-mode nil              ; Use spaces instead of tabs.
 | 
					              indent-tabs-mode nil              ; Use spaces instead of tabs.
 | 
				
			||||||
              split-width-threshold 100         ; Split verticly by default.
 | 
					              split-width-threshold 100         ; Split verticly by default.
 | 
				
			||||||
              auto-fill-function 'do-auto-fill) ; Auto-fill-mode everywhere.
 | 
					              auto-fill-function 'do-auto-fill) ; Auto-fill-mode everywhere.
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The `load-path` specifies where Emacs should look for `.el`-files (or
 | 
					The `load-path` specifies where Emacs should look for `.el`-files (or
 | 
				
			||||||
Emacs lisp files). I have a directory called `site-lisp` where I keep all
 | 
					Emacs lisp files). I have a directory called `site-lisp` where I keep all
 | 
				
			||||||
extensions that have been installed manually (these are mostly my own
 | 
					extensions that have been installed manually (these are mostly my own
 | 
				
			||||||
projects).
 | 
					projects).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (let ((default-directory (concat user-emacs-directory "site-lisp/")))
 | 
					```lisp
 | 
				
			||||||
 | 
					(let ((default-directory (concat user-emacs-directory "site-lisp/")))
 | 
				
			||||||
  (when (file-exists-p default-directory)
 | 
					  (when (file-exists-p default-directory)
 | 
				
			||||||
    (normal-top-level-add-to-load-path '("."))
 | 
					    (normal-top-level-add-to-load-path '("."))
 | 
				
			||||||
    (normal-top-level-add-subdirs-to-load-path)))
 | 
					    (normal-top-level-add-subdirs-to-load-path)))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Answering *yes* and *no* to each question from Emacs can be tedious, a
 | 
					Answering *yes* and *no* to each question from Emacs can be tedious, a
 | 
				
			||||||
single *y* or *n* will suffice.
 | 
					single *y* or *n* will suffice.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (fset 'yes-or-no-p 'y-or-n-p)
 | 
					```lisp
 | 
				
			||||||
 | 
					(fset 'yes-or-no-p 'y-or-n-p)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To avoid file system clutter we put all auto saved files in a single
 | 
					To avoid file system clutter we put all auto saved files in a single
 | 
				
			||||||
directory.
 | 
					directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defvar emacs-autosave-directory
 | 
					```lisp
 | 
				
			||||||
 | 
					(defvar emacs-autosave-directory
 | 
				
			||||||
  (concat user-emacs-directory "autosaves/")
 | 
					  (concat user-emacs-directory "autosaves/")
 | 
				
			||||||
  "This variable dictates where to put auto saves. It is set to a
 | 
					  "This variable dictates where to put auto saves. It is set to a
 | 
				
			||||||
  directory called autosaves located wherever your .emacs.d/ is
 | 
					  directory called autosaves located wherever your .emacs.d/ is
 | 
				
			||||||
  located.")
 | 
					  located.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ;; Sets all files to be backed up and auto saved in a single directory.
 | 
					;; Sets all files to be backed up and auto saved in a single directory.
 | 
				
			||||||
    (setq backup-directory-alist
 | 
					(setq backup-directory-alist
 | 
				
			||||||
      `((".*" . ,emacs-autosave-directory))
 | 
					      `((".*" . ,emacs-autosave-directory))
 | 
				
			||||||
      auto-save-file-name-transforms
 | 
					      auto-save-file-name-transforms
 | 
				
			||||||
      `((".*" ,emacs-autosave-directory t)))
 | 
					      `((".*" ,emacs-autosave-directory t)))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Set `utf-8` as preferred coding system.
 | 
					Set `utf-8` as preferred coding system.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (set-language-environment "UTF-8")
 | 
					```lisp
 | 
				
			||||||
 | 
					(set-language-environment "UTF-8")
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
By default the `narrow-to-region` command is disabled and issues a
 | 
					By default the `narrow-to-region` command is disabled and issues a
 | 
				
			||||||
warning, because it might confuse new users. I find it useful sometimes,
 | 
					warning, because it might confuse new users. I find it useful sometimes,
 | 
				
			||||||
and don't want to be warned.
 | 
					and don't want to be warned.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (put 'narrow-to-region 'disabled nil)
 | 
					```lisp
 | 
				
			||||||
 | 
					(put 'narrow-to-region 'disabled nil)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Call `auto-complete` default configuration, which enables `auto-complete`
 | 
					Call `auto-complete` default configuration, which enables `auto-complete`
 | 
				
			||||||
globally.
 | 
					globally.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (ac-config-default)
 | 
					```lisp
 | 
				
			||||||
 | 
					(ac-config-default)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Automaticly revert `doc-view`-buffers when the file changes on disk.
 | 
					Automaticly revert `doc-view`-buffers when the file changes on disk.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'doc-view-mode-hook 'auto-revert-mode)
 | 
					```lisp
 | 
				
			||||||
 | 
					(add-hook 'doc-view-mode-hook 'auto-revert-mode)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Modes
 | 
					## Modes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -285,16 +322,19 @@ There are some modes that are enabled by default that I don't find
 | 
				
			|||||||
particularly useful. We create a list of these modes, and disable all of
 | 
					particularly useful. We create a list of these modes, and disable all of
 | 
				
			||||||
these.
 | 
					these.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (dolist (mode
 | 
					```lisp
 | 
				
			||||||
 | 
					(dolist (mode
 | 
				
			||||||
         '(tool-bar-mode                ; No toolbars, more room for text.
 | 
					         '(tool-bar-mode                ; No toolbars, more room for text.
 | 
				
			||||||
           scroll-bar-mode              ; No scroll bars either.
 | 
					           scroll-bar-mode              ; No scroll bars either.
 | 
				
			||||||
           blink-cursor-mode))          ; The blinking cursor gets old.
 | 
					           blink-cursor-mode))          ; The blinking cursor gets old.
 | 
				
			||||||
  (funcall mode 0))
 | 
					  (funcall mode 0))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Let's apply the same technique for enabling modes that are disabled by
 | 
					Let's apply the same technique for enabling modes that are disabled by
 | 
				
			||||||
default.
 | 
					default.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (dolist (mode
 | 
					```lisp
 | 
				
			||||||
 | 
					(dolist (mode
 | 
				
			||||||
         '(abbrev-mode                ; E.g. sopl -> System.out.println.
 | 
					         '(abbrev-mode                ; E.g. sopl -> System.out.println.
 | 
				
			||||||
           auto-compile-on-load-mode  ; Compile .el files on load ...
 | 
					           auto-compile-on-load-mode  ; Compile .el files on load ...
 | 
				
			||||||
           auto-compile-on-save-mode  ; ... and save.
 | 
					           auto-compile-on-save-mode  ; ... and save.
 | 
				
			||||||
@ -303,21 +343,28 @@ default.
 | 
				
			|||||||
           recentf-mode               ; Recently opened files.
 | 
					           recentf-mode               ; Recently opened files.
 | 
				
			||||||
           show-paren-mode))          ; Highlight matching parentheses.
 | 
					           show-paren-mode))          ; Highlight matching parentheses.
 | 
				
			||||||
  (funcall mode 1))
 | 
					  (funcall mode 1))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This makes `.md`-files open in `markdown-mode`.
 | 
					This makes `.md`-files open in `markdown-mode`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
 | 
					```lisp
 | 
				
			||||||
 | 
					(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Visual
 | 
					## Visual
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Change the color-theme to `monokai` (downloaded using `package`).
 | 
					Change the color-theme to `monokai` (downloaded using `package`).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (load-theme 'monokai t)
 | 
					```lisp
 | 
				
			||||||
 | 
					(load-theme 'monokai t)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Use the [Inconsolata](http://www.levien.com/type/myfonts/inconsolata.html) font if it's installed on the system.
 | 
					Use the [Inconsolata](http://www.levien.com/type/myfonts/inconsolata.html) font if it's installed on the system.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (when (member "Inconsolata" (font-family-list))
 | 
					```lisp
 | 
				
			||||||
 | 
					(when (member "Inconsolata" (font-family-list))
 | 
				
			||||||
  (set-face-attribute 'default nil :font "Inconsolata-13"))
 | 
					  (set-face-attribute 'default nil :font "Inconsolata-13"))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Ido
 | 
					## Ido
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -327,38 +374,47 @@ names you can write a part of it and select one from a list of
 | 
				
			|||||||
possibilities. Using `ido-vertical-mode` changes the way possibilities
 | 
					possibilities. Using `ido-vertical-mode` changes the way possibilities
 | 
				
			||||||
are displayed, and `flx-ido-mode` enables fuzzy matching.
 | 
					are displayed, and `flx-ido-mode` enables fuzzy matching.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (dolist (mode
 | 
					```lisp
 | 
				
			||||||
 | 
					(dolist (mode
 | 
				
			||||||
         '(ido-mode                   ; Interactivly do.
 | 
					         '(ido-mode                   ; Interactivly do.
 | 
				
			||||||
           ido-everywhere             ; Use Ido for all buffer/file reading.
 | 
					           ido-everywhere             ; Use Ido for all buffer/file reading.
 | 
				
			||||||
           ido-vertical-mode          ; Makes ido-mode display vertically.
 | 
					           ido-vertical-mode          ; Makes ido-mode display vertically.
 | 
				
			||||||
           flx-ido-mode))             ; Toggle flx ido mode.
 | 
					           flx-ido-mode))             ; Toggle flx ido mode.
 | 
				
			||||||
  (funcall mode 1))
 | 
					  (funcall mode 1))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
We can set the order of file selections in `ido`. I prioritize source
 | 
					We can set the order of file selections in `ido`. I prioritize source
 | 
				
			||||||
files along with `org`- and `tex`-files.
 | 
					files along with `org`- and `tex`-files.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq ido-file-extensions-order
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq ido-file-extensions-order
 | 
				
			||||||
      '(".el" ".scm" ".lisp" ".java" ".c" ".h" ".org" ".tex"))
 | 
					      '(".el" ".scm" ".lisp" ".java" ".c" ".h" ".org" ".tex"))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Sometimes when using `ido-switch-buffer` the `*Messages*` buffer get in
 | 
					Sometimes when using `ido-switch-buffer` the `*Messages*` buffer get in
 | 
				
			||||||
the way, so we set it to be ignored (it can be accessed using `C-h e`, so
 | 
					the way, so we set it to be ignored (it can be accessed using `C-h e`, so
 | 
				
			||||||
there is really no need for it in the buffer list).
 | 
					there is really no need for it in the buffer list).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-to-list 'ido-ignore-buffers "*Messages*")
 | 
					```lisp
 | 
				
			||||||
 | 
					(add-to-list 'ido-ignore-buffers "*Messages*")
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To make `M-x` behave more like `ido-mode` we can use the `smex`
 | 
					To make `M-x` behave more like `ido-mode` we can use the `smex`
 | 
				
			||||||
package. It needs to be initialized, and we can replace the binding to
 | 
					package. It needs to be initialized, and we can replace the binding to
 | 
				
			||||||
the standard `execute-extended-command` with `smex`.
 | 
					the standard `execute-extended-command` with `smex`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (smex-initialize)
 | 
					```lisp
 | 
				
			||||||
    (global-set-key (kbd "M-x") 'smex)
 | 
					(smex-initialize)
 | 
				
			||||||
 | 
					(global-set-key (kbd "M-x") 'smex)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Calendar
 | 
					## Calendar
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Define a function to display week numbers in `calender-mode`. The snippet
 | 
					Define a function to display week numbers in `calender-mode`. The snippet
 | 
				
			||||||
is from [EmacsWiki](http://www.emacswiki.org/emacs/CalendarWeekNumbers).
 | 
					is from [EmacsWiki](http://www.emacswiki.org/emacs/CalendarWeekNumbers).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun calendar-show-week (arg)
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun calendar-show-week (arg)
 | 
				
			||||||
  "Displaying week number in calendar-mode."
 | 
					  "Displaying week number in calendar-mode."
 | 
				
			||||||
  (interactive "P")
 | 
					  (interactive "P")
 | 
				
			||||||
  (copy-face font-lock-constant-face 'calendar-iso-week-face)
 | 
					  (copy-face font-lock-constant-face 'calendar-iso-week-face)
 | 
				
			||||||
@ -373,17 +429,22 @@ is from [EmacsWiki](http://www.emacswiki.org/emacs/CalendarWeekNumbers).
 | 
				
			|||||||
                      (calendar-absolute-from-gregorian
 | 
					                      (calendar-absolute-from-gregorian
 | 
				
			||||||
                       (list month day year)))))
 | 
					                       (list month day year)))))
 | 
				
			||||||
               'font-lock-face 'calendar-iso-week-face))))
 | 
					               'font-lock-face 'calendar-iso-week-face))))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Evaluate the `calendar-show-week` function.
 | 
					Evaluate the `calendar-show-week` function.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (calendar-show-week t)
 | 
					```lisp
 | 
				
			||||||
 | 
					(calendar-show-week t)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Set Monday as the first day of the week, and set my location.
 | 
					Set Monday as the first day of the week, and set my location.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq calendar-week-start-day 1
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq calendar-week-start-day 1
 | 
				
			||||||
      calendar-latitude 60.0
 | 
					      calendar-latitude 60.0
 | 
				
			||||||
      calendar-longitude 10.7
 | 
					      calendar-longitude 10.7
 | 
				
			||||||
      calendar-location-name "Oslo, Norway")
 | 
					      calendar-location-name "Oslo, Norway")
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Mail
 | 
					## Mail
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -392,9 +453,10 @@ computers. Because the mail-setup wont work without these programs
 | 
				
			|||||||
installed we bind `load-mail-setup` to `nil`. If the value is changed to
 | 
					installed we bind `load-mail-setup` to `nil`. If the value is changed to
 | 
				
			||||||
a `non-nil` value mail is setup.
 | 
					a `non-nil` value mail is setup.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defvar load-mail-setup nil)
 | 
					```lisp
 | 
				
			||||||
 | 
					(defvar load-mail-setup nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (when load-mail-setup
 | 
					(when load-mail-setup
 | 
				
			||||||
  ;; We need mu4e
 | 
					  ;; We need mu4e
 | 
				
			||||||
  (require 'mu4e)
 | 
					  (require 'mu4e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -430,7 +492,7 @@ a `non-nil` value mail is setup.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  (defadvice mu4e (before show-mu4e (arg) activate)
 | 
					  (defadvice mu4e (before show-mu4e (arg) activate)
 | 
				
			||||||
    "Always show mu4e in fullscreen and remember window
 | 
					    "Always show mu4e in fullscreen and remember window
 | 
				
			||||||
    configuration."
 | 
					configuration."
 | 
				
			||||||
    (unless arg
 | 
					    (unless arg
 | 
				
			||||||
      (window-configuration-to-register :mu4e-fullscreen)
 | 
					      (window-configuration-to-register :mu4e-fullscreen)
 | 
				
			||||||
      (mu4e-update-mail-and-index t)
 | 
					      (mu4e-update-mail-and-index t)
 | 
				
			||||||
@ -442,49 +504,62 @@ a `non-nil` value mail is setup.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  ;; Overwrite the native 'compose-mail' binding to 'show-mu4e'.
 | 
					  ;; Overwrite the native 'compose-mail' binding to 'show-mu4e'.
 | 
				
			||||||
  (global-set-key (kbd "C-x m") 'mu4e))
 | 
					  (global-set-key (kbd "C-x m") 'mu4e))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Flyspell
 | 
					## Flyspell
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Flyspell offers on-the-fly spell checking. We can enable flyspell for all
 | 
					Flyspell offers on-the-fly spell checking. We can enable flyspell for all
 | 
				
			||||||
text-modes with this snippet.
 | 
					text-modes with this snippet.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'text-mode-hook 'turn-on-flyspell)
 | 
					```lisp
 | 
				
			||||||
 | 
					(add-hook 'text-mode-hook 'turn-on-flyspell)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To use flyspell for programming there is `flyspell-prog-mode`, that only
 | 
					To use flyspell for programming there is `flyspell-prog-mode`, that only
 | 
				
			||||||
enables spell checking for comments and strings. We can enable it for all
 | 
					enables spell checking for comments and strings. We can enable it for all
 | 
				
			||||||
programming modes using the `prog-mode-hook`. Flyspell interferes with
 | 
					programming modes using the `prog-mode-hook`. Flyspell interferes with
 | 
				
			||||||
auto-complete mode, but there is a workaround provided by auto complete.
 | 
					auto-complete mode, but there is a workaround provided by auto complete.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'prog-mode-hook 'flyspell-prog-mode)
 | 
					```lisp
 | 
				
			||||||
    (ac-flyspell-workaround)
 | 
					(add-hook 'prog-mode-hook 'flyspell-prog-mode)
 | 
				
			||||||
 | 
					(ac-flyspell-workaround)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To cycle through dictionary's we can define a variable containing a
 | 
					To cycle through dictionary's we can define a variable containing a
 | 
				
			||||||
cyclic list of installed language packs.
 | 
					cyclic list of installed language packs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defvar ispell-languages '#1=("english" "norsk" . #1#))
 | 
					```lisp
 | 
				
			||||||
 | 
					(defvar ispell-languages '#1=("english" "norsk" . #1#))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Now we only need a small function to change set the language and shift
 | 
					Now we only need a small function to change set the language and shift
 | 
				
			||||||
the list.
 | 
					the list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun cycle-languages ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun cycle-languages ()
 | 
				
			||||||
  "Changes the ispell-dictionary to whatever is the next (or cdr) in the
 | 
					  "Changes the ispell-dictionary to whatever is the next (or cdr) in the
 | 
				
			||||||
    LANGUAGES (cyclic) list."
 | 
					LANGUAGES (cyclic) list."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (ispell-change-dictionary
 | 
					  (ispell-change-dictionary
 | 
				
			||||||
   (car (setq ispell-languages (cdr ispell-languages)))))
 | 
					   (car (setq ispell-languages (cdr ispell-languages)))))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Org
 | 
					## Org
 | 
				
			||||||
 | 
					
 | 
				
			||||||
I use `org-agenda` for appointments and such.
 | 
					I use `org-agenda` for appointments and such.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq org-agenda-start-on-weekday nil              ; Show agenda from today.
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq org-agenda-start-on-weekday nil              ; Show agenda from today.
 | 
				
			||||||
      org-agenda-files '("~/Dropbox/life.org")     ; A list of agenda files.
 | 
					      org-agenda-files '("~/Dropbox/life.org")     ; A list of agenda files.
 | 
				
			||||||
      org-agenda-default-appointment-duration 120) ; 2 hours appointments.
 | 
					      org-agenda-default-appointment-duration 120) ; 2 hours appointments.
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
When editing org-files with source-blocks, we want the source blocks to
 | 
					When editing org-files with source-blocks, we want the source blocks to
 | 
				
			||||||
be themed as they would in their native mode.
 | 
					be themed as they would in their native mode.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq org-src-fontify-natively t)
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq org-src-fontify-natively t)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Interactive functions
 | 
					## Interactive functions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -493,36 +568,43 @@ be themed as they would in their native mode.
 | 
				
			|||||||
To search recent files useing `ido-mode` we add this snippet from
 | 
					To search recent files useing `ido-mode` we add this snippet from
 | 
				
			||||||
[EmacsWiki](http://www.emacswiki.org/emacs/CalendarWeekNumbers).
 | 
					[EmacsWiki](http://www.emacswiki.org/emacs/CalendarWeekNumbers).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun recentf-ido-find-file ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun recentf-ido-find-file ()
 | 
				
			||||||
  "Find a recent file using Ido."
 | 
					  "Find a recent file using Ido."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (let ((f (ido-completing-read "Choose recent file: " recentf-list nil t)))
 | 
					  (let ((f (ido-completing-read "Choose recent file: " recentf-list nil t)))
 | 
				
			||||||
    (when f
 | 
					    (when f
 | 
				
			||||||
      (find-file f))))
 | 
					      (find-file f))))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`just-one-space` removes all whitespace around a point - giving it a
 | 
					`just-one-space` removes all whitespace around a point - giving it a
 | 
				
			||||||
negative argument it removes newlines as well. We wrap a interactive
 | 
					negative argument it removes newlines as well. We wrap a interactive
 | 
				
			||||||
function around it to be able to bind it to a key.
 | 
					function around it to be able to bind it to a key.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun remove-whitespace-inbetween ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun remove-whitespace-inbetween ()
 | 
				
			||||||
  "Removes whitespace before and after the point."
 | 
					  "Removes whitespace before and after the point."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (just-one-space -1))
 | 
					  (just-one-space -1))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This interactive function switches you to a `shell`, and if triggered in
 | 
					This interactive function switches you to a `shell`, and if triggered in
 | 
				
			||||||
the shell it switches back to the previous buffer.
 | 
					the shell it switches back to the previous buffer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun switch-to-shell ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun switch-to-shell ()
 | 
				
			||||||
  "Jumps to eshell or back."
 | 
					  "Jumps to eshell or back."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (if (string= (buffer-name) "*shell*")
 | 
					  (if (string= (buffer-name) "*shell*")
 | 
				
			||||||
      (switch-to-prev-buffer)
 | 
					      (switch-to-prev-buffer)
 | 
				
			||||||
    (shell)))
 | 
					    (shell)))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To duplicate either selected text or a line we define this interactive
 | 
					To duplicate either selected text or a line we define this interactive
 | 
				
			||||||
function.
 | 
					function.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun duplicate-thing ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun duplicate-thing ()
 | 
				
			||||||
  "Ethier duplicates the line or the region"
 | 
					  "Ethier duplicates the line or the region"
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (save-excursion
 | 
					  (save-excursion
 | 
				
			||||||
@ -532,10 +614,12 @@ function.
 | 
				
			|||||||
      (unless (region-active-p)
 | 
					      (unless (region-active-p)
 | 
				
			||||||
        (newline))
 | 
					        (newline))
 | 
				
			||||||
      (insert (buffer-substring start end)))))
 | 
					      (insert (buffer-substring start end)))))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To tidy up a buffer we define this function borrowed from [simenheg](https://github.com/simenheg).
 | 
					To tidy up a buffer we define this function borrowed from [simenheg](https://github.com/simenheg).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun tidy ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun tidy ()
 | 
				
			||||||
  "Ident, untabify and unwhitespacify current buffer, or region if active."
 | 
					  "Ident, untabify and unwhitespacify current buffer, or region if active."
 | 
				
			||||||
  (interactive)
 | 
					  (interactive)
 | 
				
			||||||
  (let ((beg (if (region-active-p) (region-beginning) (point-min)))
 | 
					  (let ((beg (if (region-active-p) (region-beginning) (point-min)))
 | 
				
			||||||
@ -543,47 +627,62 @@ To tidy up a buffer we define this function borrowed from [simenheg](https://git
 | 
				
			|||||||
    (indent-region beg end)
 | 
					    (indent-region beg end)
 | 
				
			||||||
    (whitespace-cleanup)
 | 
					    (whitespace-cleanup)
 | 
				
			||||||
    (untabify beg (if (< end (point-max)) end (point-max)))))
 | 
					    (untabify beg (if (< end (point-max)) end (point-max)))))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Key bindings
 | 
					## Key bindings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bindings for [expand-region](https://github.com/magnars/expand-region.el).
 | 
					Bindings for [expand-region](https://github.com/magnars/expand-region.el).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (global-set-key (kbd "C-'")  'er/expand-region)
 | 
					```lisp
 | 
				
			||||||
    (global-set-key (kbd "C-;")  'er/contract-region)
 | 
					(global-set-key (kbd "C-'")  'er/expand-region)
 | 
				
			||||||
 | 
					(global-set-key (kbd "C-;")  'er/contract-region)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bindings for [multiple-cursors](https://github.com/magnars/multiple-cursors.el).
 | 
					Bindings for [multiple-cursors](https://github.com/magnars/multiple-cursors.el).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (global-set-key (kbd "C-c e")  'mc/edit-lines)
 | 
					```lisp
 | 
				
			||||||
    (global-set-key (kbd "C-c a")  'mc/mark-all-like-this)
 | 
					(global-set-key (kbd "C-c e")  'mc/edit-lines)
 | 
				
			||||||
    (global-set-key (kbd "C-c n")  'mc/mark-next-like-this)
 | 
					(global-set-key (kbd "C-c a")  'mc/mark-all-like-this)
 | 
				
			||||||
 | 
					(global-set-key (kbd "C-c n")  'mc/mark-next-like-this)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bindings for [Magit](http://magit.github.io).
 | 
					Bindings for [Magit](http://magit.github.io).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (global-set-key (kbd "C-c m") 'magit-status)
 | 
					```lisp
 | 
				
			||||||
 | 
					(global-set-key (kbd "C-c m") 'magit-status)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bindings for [ace-jump-mode](https://github.com/winterTTr/ace-jump-mode).
 | 
					Bindings for [ace-jump-mode](https://github.com/winterTTr/ace-jump-mode).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (global-set-key (kbd "C-c SPC") 'ace-jump-mode)
 | 
					```lisp
 | 
				
			||||||
 | 
					(global-set-key (kbd "C-c SPC") 'ace-jump-mode)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bindings for `move-text`.
 | 
					Bindings for `move-text`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (global-set-key (kbd "<M-S-up>")    'move-text-up)
 | 
					```lisp
 | 
				
			||||||
    (global-set-key (kbd "<M-S-down>")  'move-text-down)
 | 
					(global-set-key (kbd "<M-S-up>")    'move-text-up)
 | 
				
			||||||
 | 
					(global-set-key (kbd "<M-S-down>")  'move-text-down)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bind some native Emacs functions.
 | 
					Bind some native Emacs functions.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (global-set-key (kbd "C-c s")    'ispell-word)
 | 
					```lisp
 | 
				
			||||||
    (global-set-key (kbd "C-c t")    'org-agenda-list)
 | 
					(global-set-key (kbd "C-c s")    'ispell-word)
 | 
				
			||||||
    (global-set-key (kbd "C-x k")    'kill-this-buffer)
 | 
					(global-set-key (kbd "C-c t")    'org-agenda-list)
 | 
				
			||||||
    (global-set-key (kbd "C-x C-r")  'recentf-ido-find-file)
 | 
					(global-set-key (kbd "C-x k")    'kill-this-buffer)
 | 
				
			||||||
 | 
					(global-set-key (kbd "C-x C-r")  'recentf-ido-find-file)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bind the functions defined above.
 | 
					Bind the functions defined above.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (global-set-key (kbd "C-c l")    'cycle-languages)
 | 
					```lisp
 | 
				
			||||||
    (global-set-key (kbd "C-c j")    'remove-whitespace-inbetween)
 | 
					(global-set-key (kbd "C-c l")    'cycle-languages)
 | 
				
			||||||
    (global-set-key (kbd "C-x t")    'switch-to-shell)
 | 
					(global-set-key (kbd "C-c j")    'remove-whitespace-inbetween)
 | 
				
			||||||
    (global-set-key (kbd "C-c d")    'duplicate-thing)
 | 
					(global-set-key (kbd "C-x t")    'switch-to-shell)
 | 
				
			||||||
    (global-set-key (kbd "<C-tab>")  'tidy)
 | 
					(global-set-key (kbd "C-c d")    'duplicate-thing)
 | 
				
			||||||
 | 
					(global-set-key (kbd "<C-tab>")  'tidy)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Advice
 | 
					## Advice
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -591,7 +690,8 @@ An advice can be given to a function to make it behave differently. This
 | 
				
			|||||||
advice makes `eval-last-sexp` (bound to `C-x C-e`) replace the sexp with
 | 
					advice makes `eval-last-sexp` (bound to `C-x C-e`) replace the sexp with
 | 
				
			||||||
the value.
 | 
					the value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defadvice eval-last-sexp (around replace-sexp (arg) activate)
 | 
					```lisp
 | 
				
			||||||
 | 
					(defadvice eval-last-sexp (around replace-sexp (arg) activate)
 | 
				
			||||||
  "Replace sexp when called with a prefix argument."
 | 
					  "Replace sexp when called with a prefix argument."
 | 
				
			||||||
  (if arg
 | 
					  (if arg
 | 
				
			||||||
      (let ((pos (point)))
 | 
					      (let ((pos (point)))
 | 
				
			||||||
@ -600,20 +700,25 @@ the value.
 | 
				
			|||||||
        (backward-kill-sexp)
 | 
					        (backward-kill-sexp)
 | 
				
			||||||
        (forward-sexp))
 | 
					        (forward-sexp))
 | 
				
			||||||
    ad-do-it))
 | 
					    ad-do-it))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`Flyspell` signals an error if there is no spell-checking tool is
 | 
					`Flyspell` signals an error if there is no spell-checking tool is
 | 
				
			||||||
installed. We can advice `turn-on=flyspell` and `flyspell-prog-mode` to
 | 
					installed. We can advice `turn-on=flyspell` and `flyspell-prog-mode` to
 | 
				
			||||||
only try to enable `flyspell` if a spell-checking tool is avalible.
 | 
					only try to enable `flyspell` if a spell-checking tool is avalible.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defadvice turn-on-flyspell (around check nil activate)
 | 
					```lisp
 | 
				
			||||||
 | 
					(defadvice turn-on-flyspell (around check nil activate)
 | 
				
			||||||
  "Turns on flyspell only if a spell-checking tool is installed."
 | 
					  "Turns on flyspell only if a spell-checking tool is installed."
 | 
				
			||||||
  (when (executable-find ispell-program-name)
 | 
					  (when (executable-find ispell-program-name)
 | 
				
			||||||
    ad-do-it))
 | 
					    ad-do-it))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defadvice flyspell-prog-mode (around check nil activate)
 | 
					```lisp
 | 
				
			||||||
 | 
					(defadvice flyspell-prog-mode (around check nil activate)
 | 
				
			||||||
  "Turns on flyspell only if a spell-checking tool is installed."
 | 
					  "Turns on flyspell only if a spell-checking tool is installed."
 | 
				
			||||||
  (when (executable-find ispell-program-name)
 | 
					  (when (executable-find ispell-program-name)
 | 
				
			||||||
    ad-do-it))
 | 
					    ad-do-it))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Language mode specific
 | 
					# Language mode specific
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -624,25 +729,31 @@ only try to enable `flyspell` if a spell-checking tool is avalible.
 | 
				
			|||||||
can add some extra lisp-modes. We run the `pretty-lambda-for-modes`
 | 
					can add some extra lisp-modes. We run the `pretty-lambda-for-modes`
 | 
				
			||||||
function to activate `pretty-lambda-mode` in lisp modes.
 | 
					function to activate `pretty-lambda-mode` in lisp modes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (dolist (mode '(slime-repl-mode geiser-repl-mode))
 | 
					```lisp
 | 
				
			||||||
 | 
					(dolist (mode '(slime-repl-mode geiser-repl-mode))
 | 
				
			||||||
  (add-to-list 'pretty-lambda-auto-modes mode))
 | 
					  (add-to-list 'pretty-lambda-auto-modes mode))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (pretty-lambda-for-modes)
 | 
					(pretty-lambda-for-modes)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
I use `Paredit` when editing lisp code, we enable this for all lisp-modes
 | 
					I use `Paredit` when editing lisp code, we enable this for all lisp-modes
 | 
				
			||||||
in the `pretty-lambda-auto-modes` list.
 | 
					in the `pretty-lambda-auto-modes` list.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (dolist (mode pretty-lambda-auto-modes)
 | 
					```lisp
 | 
				
			||||||
 | 
					(dolist (mode pretty-lambda-auto-modes)
 | 
				
			||||||
  ;; add paredit-mode to all mode-hooks
 | 
					  ;; add paredit-mode to all mode-hooks
 | 
				
			||||||
  (add-hook (intern (concat (symbol-name mode) "-hook")) 'paredit-mode))
 | 
					  (add-hook (intern (concat (symbol-name mode) "-hook")) 'paredit-mode))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Emacs Lisp
 | 
					### Emacs Lisp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
In `emacs-lisp-mode` we can enable `eldoc-mode` to display information
 | 
					In `emacs-lisp-mode` we can enable `eldoc-mode` to display information
 | 
				
			||||||
about a function or a variable in the echo area.
 | 
					about a function or a variable in the echo area.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
 | 
					```lisp
 | 
				
			||||||
    (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
 | 
					(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
 | 
				
			||||||
 | 
					(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Common lisp
 | 
					### Common lisp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -652,21 +763,27 @@ Common Lisp developer. [Quicklisp](http://www.quicklisp.org/beta/) is a library
 | 
				
			|||||||
and you can install Slime following the instructions from the site along
 | 
					and you can install Slime following the instructions from the site along
 | 
				
			||||||
with this snippet.
 | 
					with this snippet.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (when (file-exists-p "~/quicklisp/slime-helper.elc")
 | 
					```lisp
 | 
				
			||||||
 | 
					(when (file-exists-p "~/quicklisp/slime-helper.elc")
 | 
				
			||||||
  (load (expand-file-name "~/quicklisp/slime-helper.elc")))
 | 
					  (load (expand-file-name "~/quicklisp/slime-helper.elc")))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
We can specify what Common Lisp program Slime should use (I use SBCL).
 | 
					We can specify what Common Lisp program Slime should use (I use SBCL).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq inferior-lisp-program "sbcl")
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq inferior-lisp-program "sbcl")
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To improve auto completion for Common Lisp editing we can use `ac-slime`
 | 
					To improve auto completion for Common Lisp editing we can use `ac-slime`
 | 
				
			||||||
which uses slime completions as a source.
 | 
					which uses slime completions as a source.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'slime-mode-hook 'set-up-slime-ac)
 | 
					```lisp
 | 
				
			||||||
    (add-hook 'slime-repl-mode-hook 'set-up-slime-ac)
 | 
					(add-hook 'slime-mode-hook 'set-up-slime-ac)
 | 
				
			||||||
 | 
					(add-hook 'slime-repl-mode-hook 'set-up-slime-ac)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (eval-after-load "auto-complete"
 | 
					(eval-after-load "auto-complete"
 | 
				
			||||||
  '(add-to-list 'ac-modes 'slime-repl-mode))
 | 
					  '(add-to-list 'ac-modes 'slime-repl-mode))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Scheme
 | 
					### Scheme
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -674,11 +791,13 @@ which uses slime completions as a source.
 | 
				
			|||||||
works pretty much out of the box, we only need to add auto completion,
 | 
					works pretty much out of the box, we only need to add auto completion,
 | 
				
			||||||
and specify which scheme-interpreter we prefer.
 | 
					and specify which scheme-interpreter we prefer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'geiser-mode-hook 'ac-geiser-setup)
 | 
					```lisp
 | 
				
			||||||
    (add-hook 'geiser-repl-mode-hook 'ac-geiser-setup)
 | 
					(add-hook 'geiser-mode-hook 'ac-geiser-setup)
 | 
				
			||||||
    (eval-after-load "auto-complete"
 | 
					(add-hook 'geiser-repl-mode-hook 'ac-geiser-setup)
 | 
				
			||||||
 | 
					(eval-after-load "auto-complete"
 | 
				
			||||||
  '(add-to-list 'ac-modes 'geiser-repl-mode))
 | 
					  '(add-to-list 'ac-modes 'geiser-repl-mode))
 | 
				
			||||||
    (setq geiser-active-implementations '(racket))
 | 
					(setq geiser-active-implementations '(racket))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Java and C
 | 
					## Java and C
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -686,27 +805,33 @@ The `c-mode-common-hook` is a general hook that work on all C-like
 | 
				
			|||||||
languages (C, C++, Java, etc…). I like being able to quickly compile
 | 
					languages (C, C++, Java, etc…). I like being able to quickly compile
 | 
				
			||||||
using `C-c C-c` (instead of `M-x compile`), a habit from `latex-mode`.
 | 
					using `C-c C-c` (instead of `M-x compile`), a habit from `latex-mode`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun c-setup ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun c-setup ()
 | 
				
			||||||
  (local-set-key (kbd "C-c C-c") 'compile))
 | 
					  (local-set-key (kbd "C-c C-c") 'compile))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'c-mode-common-hook 'c-setup)
 | 
					(add-hook 'c-mode-common-hook 'c-setup)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Some statements in Java appear often, and become tedious to write
 | 
					Some statements in Java appear often, and become tedious to write
 | 
				
			||||||
out. We can use abbrevs to speed this up.
 | 
					out. We can use abbrevs to speed this up.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (define-abbrev-table 'java-mode-abbrev-table
 | 
					```lisp
 | 
				
			||||||
 | 
					(define-abbrev-table 'java-mode-abbrev-table
 | 
				
			||||||
  '(("psv" "public static void main(String[] args) {" nil 0)
 | 
					  '(("psv" "public static void main(String[] args) {" nil 0)
 | 
				
			||||||
    ("sopl" "System.out.println" nil 0)
 | 
					    ("sopl" "System.out.println" nil 0)
 | 
				
			||||||
    ("sop" "System.out.printf" nil 0)))
 | 
					    ("sop" "System.out.printf" nil 0)))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To be able to use the abbrev table defined above, `abbrev-mode` must be
 | 
					To be able to use the abbrev table defined above, `abbrev-mode` must be
 | 
				
			||||||
activated.
 | 
					activated.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun java-setup ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun java-setup ()
 | 
				
			||||||
  (abbrev-mode t)
 | 
					  (abbrev-mode t)
 | 
				
			||||||
  (setq-local compile-command (concat "javac " (buffer-name))))
 | 
					  (setq-local compile-command (concat "javac " (buffer-name))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'java-mode-hook 'java-setup)
 | 
					(add-hook 'java-mode-hook 'java-setup)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Assembler
 | 
					## Assembler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -714,24 +839,30 @@ When writing assembler code I use `#` for comments. By defining
 | 
				
			|||||||
`comment-start` we can add comments using `M-;` like in other programming
 | 
					`comment-start` we can add comments using `M-;` like in other programming
 | 
				
			||||||
modes. Also in assembler should one be able to compile using `C-c C-c`.
 | 
					modes. Also in assembler should one be able to compile using `C-c C-c`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (defun asm-setup ()
 | 
					```lisp
 | 
				
			||||||
 | 
					(defun asm-setup ()
 | 
				
			||||||
  (setq comment-start "#")
 | 
					  (setq comment-start "#")
 | 
				
			||||||
  (local-set-key (kbd "C-c C-c") 'compile))
 | 
					  (local-set-key (kbd "C-c C-c") 'compile))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'asm-mode-hook 'asm-setup)
 | 
					(add-hook 'asm-mode-hook 'asm-setup)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## LaTeX
 | 
					## LaTeX
 | 
				
			||||||
 | 
					
 | 
				
			||||||
`.tex`-files should be associated with `latex-mode` instead of
 | 
					`.tex`-files should be associated with `latex-mode` instead of
 | 
				
			||||||
`tex-mode`.
 | 
					`tex-mode`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-to-list 'auto-mode-alist '("\\.tex\\'" . latex-mode))
 | 
					```lisp
 | 
				
			||||||
 | 
					(add-to-list 'auto-mode-alist '("\\.tex\\'" . latex-mode))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
I like using the [Minted](https://code.google.com/p/minted/) package for source blocks in LaTeX. To make org
 | 
					I like using the [Minted](https://code.google.com/p/minted/) package for source blocks in LaTeX. To make org
 | 
				
			||||||
use this we add the following snippet.
 | 
					use this we add the following snippet.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-to-list 'org-latex-packages-alist '("" "minted"))
 | 
					```lisp
 | 
				
			||||||
    (setq org-latex-listings 'minted)
 | 
					(add-to-list 'org-latex-packages-alist '("" "minted"))
 | 
				
			||||||
 | 
					(setq org-latex-listings 'minted)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Because [Minted](https://code.google.com/p/minted/) uses [Pygments](http://pygments.org) (an external process), we must add the
 | 
					Because [Minted](https://code.google.com/p/minted/) uses [Pygments](http://pygments.org) (an external process), we must add the
 | 
				
			||||||
`-shell-escape` option to the `org-latex-pdf-process` commands. The
 | 
					`-shell-escape` option to the `org-latex-pdf-process` commands. The
 | 
				
			||||||
@ -739,14 +870,16 @@ Because [Minted](https://code.google.com/p/minted/) uses [Pygments](http://pygme
 | 
				
			|||||||
Tex- and LaTeX-mode, we can add the flag with a rather dirty statement
 | 
					Tex- and LaTeX-mode, we can add the flag with a rather dirty statement
 | 
				
			||||||
(if anyone finds a nicer way to do this, please let me know).
 | 
					(if anyone finds a nicer way to do this, please let me know).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq org-latex-pdf-process
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq org-latex-pdf-process
 | 
				
			||||||
      (mapcar
 | 
					      (mapcar
 | 
				
			||||||
       (lambda (str)
 | 
					       (lambda (str)
 | 
				
			||||||
         (concat "pdflatex -shell-escape "
 | 
					         (concat "pdflatex -shell-escape "
 | 
				
			||||||
                 (substring str (string-match "-" str))))
 | 
					                 (substring str (string-match "-" str))))
 | 
				
			||||||
       org-latex-pdf-process))
 | 
					       org-latex-pdf-process))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setcar (cdr (cddaar tex-compile-commands)) " -shell-escape ")
 | 
					(setcar (cdr (cddaar tex-compile-commands)) " -shell-escape ")
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Python
 | 
					## Python
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -754,12 +887,14 @@ Tex- and LaTeX-mode, we can add the flag with a rather dirty statement
 | 
				
			|||||||
dependent on some python programs as well, so make sure you follow the
 | 
					dependent on some python programs as well, so make sure you follow the
 | 
				
			||||||
instructions from the site.
 | 
					instructions from the site.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (setq jedi:server-command
 | 
					```lisp
 | 
				
			||||||
 | 
					(setq jedi:server-command
 | 
				
			||||||
      (cons "python3" (cdr jedi:server-command))
 | 
					      (cons "python3" (cdr jedi:server-command))
 | 
				
			||||||
      python-shell-interpreter "python3")
 | 
					      python-shell-interpreter "python3")
 | 
				
			||||||
    (add-hook 'python-mode-hook 'jedi:setup)
 | 
					(add-hook 'python-mode-hook 'jedi:setup)
 | 
				
			||||||
    (setq jedi:complete-on-dot t)
 | 
					(setq jedi:complete-on-dot t)
 | 
				
			||||||
    (add-hook 'python-mode-hook 'jedi:ac-setup)
 | 
					(add-hook 'python-mode-hook 'jedi:ac-setup)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Haskell
 | 
					## Haskell
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -767,12 +902,16 @@ instructions from the site.
 | 
				
			|||||||
the echo area. Haskell has several indentation modes - I prefer using
 | 
					the echo area. Haskell has several indentation modes - I prefer using
 | 
				
			||||||
`haskell-indent`.
 | 
					`haskell-indent`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
 | 
					```lisp
 | 
				
			||||||
    (add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
 | 
					(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
 | 
				
			||||||
 | 
					(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Matlab
 | 
					## Matlab
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Matlab is very similar to Octave, which is supported by Emacs. We just
 | 
					Matlab is very similar to Octave, which is supported by Emacs. We just
 | 
				
			||||||
need to let `.m`-files be associated with `octave-mode`.
 | 
					need to let `.m`-files be associated with `octave-mode`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
 | 
					```lisp
 | 
				
			||||||
 | 
					(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user