Commits

Jeffrey Stoffers committed 3320492

Was an old version

Comments (0)

Files changed (1)

.emacs.d/init.org

                   powerline          ; Rewrite of Powerline
                   pretty-lambdada    ; the word `lambda' as the Greek letter.
                   rainbow-delimiters ; Color nested parens for easy block identification
+                  smex               ; Ido like mode for m-x
                   undo-tree          ; Treat undo history as a tree
                   writeroom-mode     ; Distraction free writing mode
                   zenburn-theme      ; Low Contrast color theme
                   ))
          (upgrade-or-install-package package))
-       ;; This package is only relevant for Mac OS X.
-       (when (memq window-system '(mac ns))
-         (upgrade-or-install-package 'exec-path-from-shell)))
    #+END_SRC
 
 ** Require
    We can set variables to whatever value we'd like using =setq=.
 
    #+BEGIN_SRC emacs-lisp :tangle yes
-     (setq initial-scratch-message nil     ; Clean scratch buffer.
-           inhibit-startup-message t       ; No splash screen please.
-           default-input-method "TeX"      ; Use TeX when toggeling input method.
-           ring-bell-function 'ignore      ; Quite as a mouse.
-           doc-view-continuous t           ; At page edge goto next/previous.
-           echo-keystrokes 0.1)            ; Show keystrokes asap.
+     (setq initial-scratch-message nil                        ; Clean scratch buffer.
+           inhibit-startup-message t                          ; No splash screen please.
+           whitespace-line-column 80                          ; 80 columns for code
+           whitespace-style '(face tabs trailing lines-tail)) ; Highlight white space
+   #+END_SRC
+
+   Some variables are buffer-local, so changing them using =setq= will only
+   change them in a single buffer. Using =setq-default= we change the
+   buffer-local variable's default value.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (setq-default fill-column 76                    ; Maximum line width.
+                   indent-tabs-mode nil)             ; Use spaces instead of tabs.
+   #+END_SRC
+
+   Answering /yes/ and /no/ to each question from Emacs can be tedious, a
+   single /y/ or /n/ will suffice.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (fset 'yes-or-no-p 'y-or-n-p)
+   #+END_SRC
+
+   To avoid file system clutter we put all auto saved files in a single
+   directory.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (defvar emacs-autosave-directory
+       (concat user-emacs-directory "autosaves/")
+       "This variable dictates where to put auto saves. It is set to a
+       directory called autosaves located wherever your .emacs.d/ is
+       located.")
+
+     ;; Sets all files to be backed up and auto saved in a single directory.
+     (setq backup-directory-alist
+           `((".*" . ,emacs-autosave-directory))
+           auto-save-file-name-transforms
+           `((".*" ,emacs-autosave-directory t)))
+   #+END_SRC
+
+   Set =utf-8= as preferred coding system.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (set-language-environment "UTF-8")
+   #+END_SRC
+
+   Call =auto-complete= default configuration, which enables =auto-complete=
+   globally.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (ac-config-default)
+   #+END_SRC
+
+** Modes
+
+   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
+   these.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (dolist (mode
+              '(tool-bar-mode                ; No toolbars, more room for text.
+                scroll-bar-mode              ; No scroll bars either.
+                menu-bar-mode))          ; No Menu bar.
+       (funcall mode 0))
+   #+END_SRC
+
+   Let's apply the same technique for enabling modes that are disabled by
+   default.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (dolist (mode
+              '(abbrev-mode                ; E.g. sopl -> System.out.println.
+                auto-compile-on-load-mode  ; Compile .el files on load ...
+                auto-compile-on-save-mode  ; ... and save.
+                column-number-mode         ; Show column number in mode line.
+                line-number-mode           ; Show line number in mode line
+                delete-selection-mode      ; Replace selected text.
+                recentf-mode               ; Recently opened files.
+                show-paren-mode            ; Highlight matching parentheses.
+                global-undo-tree-mode))    ; Undo as a tree.
+       (funcall mode 1))
+   #+END_SRC
+
+   This makes =.md=-files open in =markdown-mode=.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
+   #+END_SRC
+
+   When composing mail from mutt use mail mode
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
+   #+END_SRC
+
+** Visual
+
+   Change the color-theme to =zenburn= (downloaded using =package=).
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (load-theme 'zenburn t)
+   #+END_SRC
+
+   Use the Deja Vu font.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-to-list 'default-frame-alist '(font . "Deja Vu Sans Mono-10"))
+   #+END_SRC
+
+   Use Rainbow delimiters in all programming modes
+   
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
+   #+END_SRC
+
+** Ido
+
+   Interactive do (or =ido-mode=) changes the way you switch buffers and
+   open files/directories. Instead of writing complete file paths and buffer
+   names you can write a part of it and select one from a list of
+   possibilities. Using =ido-vertical-mode= changes the way possibilities
+   are displayed, and =flx-ido-mode= enables fuzzy matching.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (dolist (mode
+              '(ido-mode                   ; Interactivly do.
+                ido-everywhere))           ; Use Ido for all buffer/file reading.
+       (funcall mode 1))
+   #+END_SRC
+
+   We can set the order of file selections in =ido=. I prioritize source
+   files along with =org=- and =tex=-files.
 
-     ;; Some mac-bindings interfere with Emacs bindings.
-     (when (boundp 'mac-pass-command-to-system)
-       (setq mac-pass-command-to-system nil))
-
-   #+END_SRC
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (setq ido-file-extensions-order
+           '(".el" ".scm" ".lisp" ".java" ".c" ".h" ".org" ".tex"))
+   #+END_SRC
+
+   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
+   there is really no need for it in the buffer list).
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-to-list 'ido-ignore-buffers "*Messages*")
+   #+END_SRC
+
+   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
+   the standard =execute-extended-command= with =smex=.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (smex-initialize)
+     (global-set-key (kbd "M-x") 'smex)
+     (global-set-key (kbd "M-X") 'smex-major-mode-commands)
+   #+END_SRC
+
+** Flyspell
+
+   Flyspell offers on-the-fly spell checking. We can enable flyspell for all
+   text-modes with this snippet.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-hook 'text-mode-hook 'turn-on-flyspell)
+   #+END_SRC
+
+   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
+   programming modes using the =prog-mode-hook=. Flyspell interferes with
+   auto-complete mode, but there is a workaround provided by auto complete.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-hook 'prog-mode-hook 'flyspell-prog-mode)
+     (ac-flyspell-workaround)
+   #+END_SRC
+
+** Org
+
+   When editing org-files with source-blocks, we want the source blocks to
+   be themed as they would in their native mode.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (setq org-src-fontify-natively t)
+   #+END_SRC
+
+*** Keys
+
+    Lets use the recommended key bindings from the org manual
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (global-set-key "\C-cl" 'org-store-link)
+     (global-set-key "\C-cc" 'org-capture)
+     (global-set-key "\C-ca" 'org-agenda)
+     (global-set-key "\C-cb" 'org-iswitchb)
+   #+END_SRC
+
+** Lisp
+
+   =Pretty-lambda= provides a customizable variable
+   =pretty-lambda-auto-modes= that is a list of common lisp modes. Here we
+   can add some extra lisp-modes. We run the =pretty-lambda-for-modes=
+   function to activate =pretty-lambda-mode= in lisp modes.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (dolist (mode '(slime-repl-mode geiser-repl-mode cider-mode cider-mode cider-repl-mode))
+       (add-to-list 'pretty-lambda-auto-modes mode))
+
+     (pretty-lambda-for-modes)
+   #+END_SRC
+
+   I use =Paredit= when editing lisp code, we enable this for all lisp-modes
+   in the =pretty-lambda-auto-modes= list.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (dolist (mode pretty-lambda-auto-modes)
+       ;; add paredit-mode to all mode-hooks
+       (add-hook (intern (concat (symbol-name mode) "-hook")) 'paredit-mode))
+   #+END_SRC
+
+*** Emacs Lisp
+
+    In =emacs-lisp-mode= we can enable =eldoc-mode= to display information
+    about a function or a variable in the echo area.
+
+    #+BEGIN_SRC emacs-lisp :tangle yes
+      (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
+      (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
+    #+END_SRC
+
+*** Common lisp
+
+    I use [[http://www.common-lisp.net/project/slime/][Slime]] along with =lisp-mode= to edit Common Lisp code. Slime
+    provides code evaluation and other great features, a must have for a
+    Common Lisp developer. [[http://www.quicklisp.org/beta/][Quicklisp]] is a library manager for Common Lisp,
+    and you can install Slime following the instructions from the site along
+    with this snippet.
+
+    #+BEGIN_SRC emacs-lisp :tangle yes
+      (when (file-exists-p "~/.quicklisp/slime-helper.elc")
+        (load (expand-file-name "~/.quicklisp/slime-helper.elc")))
+    #+END_SRC
+
+    We can specify what Common Lisp program Slime should use (I use SBCL).
+
+    #+BEGIN_SRC emacs-lisp :tangle yes
+      (setq inferior-lisp-program "sbcl")
+    #+END_SRC
+
+    To improve auto completion for Common Lisp editing we can use =ac-slime=
+    which uses slime completions as a source.
+
+    #+BEGIN_SRC emacs-lisp :tangle yes
+      (add-hook 'slime-mode-hook 'set-up-slime-ac)
+      (add-hook 'slime-repl-mode-hook 'set-up-slime-ac)
+
+      (eval-after-load "auto-complete"
+        '(add-to-list 'ac-modes 'slime-repl-mode))
+    #+END_SRC
+
+*** Scheme
+
+    [[http://www.nongnu.org/geiser/][Geiser]] provides features similar to Slime for Scheme editing. Everything
+    works pretty much out of the box, we only need to add auto completion,
+    and specify which scheme-interpreter we prefer.
+
+   #+BEGIN_SRC emacs-lisp :tangle yes
+     (add-hook 'geiser-mode-hook 'ac-geiser-setup)
+     (add-hook 'geiser-repl-mode-hook 'ac-geiser-setup)
+     (eval-after-load "auto-complete"
+       '(add-to-list 'ac-modes 'geiser-repl-mode))
+     (setq geiser-active-implementations '(racket))
+   #+END_SRC
 
-* Old Config
-;;;---------------------------------------------------------------------
-;;; Emacs Configuration
-;;;---------------------------------------------------------------------
-
-;; Turn off all window chrome
-(tool-bar-mode -1)
-(menu-bar-mode -1)
-(scroll-bar-mode -1)
-(setq inhibit-splash-screen 1)
-
-;; No stupid ~ backup files everywhere
-(setq backup-directory-alist '(("." . "~/.emacs.d/backups"))
-      backup-by-copying 1
-      delete-old-versions 1
-      kept-new-versions 6
-      kept-old-versions 2
-      version-control 1)
-
-;; Cursor position in modeline
-(line-number-mode 1)
-(column-number-mode 1)
-
-;; Code editing tweaks
-(show-paren-mode 1) ;Match parens
-(setq compilation-scroll-output 1) ;Scroll flyspell
-;; (electric-indent-mode 1) ;Enabled Out of the box now
-
-;; No stupid #*# autosave files everywhere
-(setq auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))
-
-;; Three characters is too much typing
-(defalias 'yes-or-no-p 'y-or-n-p)
-
-;; Set font
-(add-to-list 'default-frame-alist '(font . "Deja Vu Sans Mono-10"))
-
-;; Set the color theme
-(load-theme 'zenburn t)
-
-;; Use mail mode when composing email in mutt
-(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
-
-(global-set-key "\C-x\C-b" 'ibuffer)
-(ido-mode 1)
-
-;; Indent region or indent the buffer if no region is selected
-;; http://emacsredux.com/blog/2013/03/27/indent-region-or-buffer/
-(defun indent-buffer ()
-  "Indent the currently visited buffer."
-  (interactive)
-  (indent-region (point-min) (point-max)))
-
-(defun indent-region-or-buffer ()
-  "Indent a region if selected, otherwise the whole buffer."
-  (interactive)
-  (save-excursion
-    (if (region-active-p)
-        (progn
-          (indent-region (region-beginning) (region-end))
-          (message "Indented selected region."))
-      (progn
-        (indent-buffer)
-        (message "Indented buffer.")))))
-
-(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)
-
-(setq browse-url-browser-function 'w3m-browse-url)
-(autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t)
-;; optional keyboard short-cut
-(global-set-key "\C-xm" 'browse-url-at-point)
-(setq w3m-use-cookies t)
-
-;;https://sites.google.com/site/steveyegge2/effective-emacs
-(global-set-key "\C-w" 'backward-kill-word)
-(global-set-key "\C-x\C-k" 'kill-region)
-(global-set-key "\C-x\C-m" 'execute-extended-command)
-
-(define-key isearch-mode-map (kbd "C-o") 'isearch-occur)
-
-;; Hilight colums over 80 characters when whitespace mode is enabled
-(setq whitespace-line-column 80
-      whitespace-style '(face tabs trailing lines-tail))
-
-;; Spellcheck buffer when enabling flyspell mode
-(add-hook 'flyspell-mode-hook 'flyspell-buffer)
-
-;; Prettify whitespace before saving
-;; http://ruslanspivak.com/2010/10/11/nuke-whitespaces-on-file-saving/
-(add-hook 'before-save-hook 'whitespace-cleanup)
-
-
-;;;-----------------------------------------------------------------------------
-;;; Smex setup
-;;;-----------------------------------------------------------------------------
-(global-set-key (kbd "M-x") 'smex)
-(global-set-key (kbd "M-X") 'smex-major-mode-commands)
-;; This is your old M-x.
-(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
-
-;;;-----------------------------------------------------------------------------
-;;; auto-complete setup
-;;;-----------------------------------------------------------------------------
-(require 'auto-complete-config)
-(ac-config-default)
-
-;;;---------------------------------------------------------------------
-;;; Cider Mode
-;;;---------------------------------------------------------------------
-(add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
-
-(setq nrepl-hide-special-buffers t)
-(setq cider-repl-tab-command 'indent-for-tab-command)
-(setq cider-repl-pop-to-buffer-on-connect nil)
-(setq cider-popup-stacktraces nil)
-(setq cider-repl-popup-stacktraces t)
-(setq cider-auto-select-error-buffer t)
-(setq nrepl-buffer-name-separator "-")
-(setq nrepl-buffer-name-show-port t)
-(setq cider-repl-display-in-current-window t)
-
-(add-hook 'cider-repl-mode-hook 'smartparens-strict-mode)
-(add-hook 'cider-repl-mode-hook 'rainbow-delimiters-mode)
-(add-hook 'cider-repl-mode-hook 'subword-mode)
-(add-hook 'cider-mode-hook 'subword-mode)
-(add-hook 'cider-mode-hook 'rainbow-delimiters-mode)
-(add-hook 'cider-mode-hook 'smartparens-strict-mode)
-
-;;;-----------------------------------------------------------------------------
-;;; Smartparens
-;;;-----------------------------------------------------------------------------
-(require 'smartparens-config)
-(sp-pair "'" nil :actions :rem) ; WHY WOULD YOU DO THIS?
-
-;;;-----------------------------------------------------------------------------
-;;; Rainbow Delimiters
-;;;-----------------------------------------------------------------------------
-;; use colors stronger than default. more saturated, i.e., less gray.
-;; http://yoo2080.wordpress.com/2013/09/08/living-with-rainbow-delimiters-mode/
-;(require 'cl-lib)
-;(require 'color)
-;(cl-loop
-; for index from 1 to rainbow-delimiters-max-face-count
-; do
-; (let ((face (intern (format "rainbow-delimiters-depth-%d-face" index))))
-;   (cl-callf color-saturate-name (face-foreground face) 30)))
-
-;;;-----------------------------------------------------------------------------
-;;; auto-complete setup for cider
-;;;-----------------------------------------------------------------------------
-(require 'ac-nrepl)
-(add-hook 'cider-repl-mode-hook 'ac-nrepl-setup)
-(add-hook 'cider-mode-hook 'ac-nrepl-setup)
-(eval-after-load "auto-complete"
-  '(add-to-list 'ac-modes 'cider-repl-mode))
-
-(defun set-auto-complete-as-completion-at-point-function ()
-  (setq completion-at-point-functions '(auto-complete)))
-(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
-
-(add-hook 'cider-repl-mode-hook 'set-auto-complete-as-completion-at-point-function)
-(add-hook 'cider-mode-hook 'set-auto-complete-as-completion-at-point-function)
-
-(eval-after-load "cider"
-  '(define-key cider-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc))
-
-;;;---------------------------------------------------------------------
-;;; Org-Mode Configuration
-;;;---------------------------------------------------------------------
-(global-set-key "\C-cl" 'org-store-link)
-(global-set-key "\C-cc" 'org-capture)
-(global-set-key "\C-ca" 'org-agenda)
-(global-set-key "\C-cb" 'org-iswitchb)
-
-(setq org-directory "~/doc/org")
-(setq org-default-notes-file (concat org-directory "/notes.org"))
-
-(org-babel-do-load-languages
- 'org-babel-load-languages
- '((emacs-lisp . t)
-   (ruby . t)
-   (perl . t)
-   (makefile . t)
-   (sh . t)
-   (lisp . t)
-   (ledger . t)
-   (java . t)
-   (latex . t)
-   (gnuplot . t)
-   (ditaa . t)
-   (css . t)
-   (calc . t)
-   (clojure . t)
-   (C . t)
-   (sql . t)))
-
-;;;-----------------------------------------------------------------------------
-;;; kibit configuration
-;;;-----------------------------------------------------------------------------
-;; Teach compile the syntax of the kibit output
-(require 'compile)
-(add-to-list 'compilation-error-regexp-alist-alist
-         '(kibit "At \\([^:]+\\):\\([[:digit:]]+\\):" 1 2 nil 0))
-(add-to-list 'compilation-error-regexp-alist 'kibit)
-
-;; A convenient command to run "lein kibit" in the project to which
-;; the current emacs buffer belongs to.
-(defun kibit ()
-  "Run kibit on the current project.
-   Display the results in a hyperlinked *compilation* buffer."
-  (interactive)
-  (compile "lein kibit"))
-
-(defun kibit-current-file ()
-  "Run kibit on the current file.
-   Display the results in a hyperlinked *compilation* buffer."
-  (interactive)
-  (compile (concat "lein kibit " buffer-file-name)))
-
-
-;;;-----------------------------------------------------------------------------
-;;; Windows configuration (i.e. WINDOWS BLOWS)
-;;;-----------------------------------------------------------------------------
-(when (eq system-type 'windows-nt)
-  (require 'tramp)
-  (setq tramp-default-method "plink"
-	ispell-program-name "hunspell.exe"
-	ispell-dictionary-alist
-	'((nil "[A-Za-z]" "[^A-Za-z]" "[']" t ("-d" "en_US") nil utf-8))))
-
-;;;---------------------------------------------------------------------
-;;; Emacs ledger mode
-;;;---------------------------------------------------------------------
-(add-to-list 'auto-mode-alist '("\\.ledger$" . ledger-mode))
-
-;; MISC BINDINGS
-(global-set-key (kbd "C-x C-z") 'magit-status)
-
-;; What?
-(autoload 'window-number-mode "window-number" t)
+*** Clojure
+
+    #+BEGIN_SRC emacs-lisp :tangle yes
+      (add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
+
+      (setq nrepl-hide-special-buffers t
+            cider-repl-tab-command 'indent-for-tab-command
+            cider-repl-pop-to-buffer-on-connect nil
+            cider-popup-stacktraces nil
+            cider-repl-popup-stacktraces t
+            cider-auto-select-error-buffer t
+            nrepl-buffer-name-separator "-"
+            nrepl-buffer-name-show-port t
+            cider-repl-display-in-current-window t)
+
+      (add-hook 'cider-repl-mode-hook 'smartparens-strict-mode)
+
+      (add-hook 'cider-repl-mode-hook 'rainbow-delimiters-mode)
+      (add-hook 'cider-repl-mode-hook 'subword-mode)
+      (add-hook 'cider-mode-hook 'subword-mode)
+      (add-hook 'cider-mode-hook 'rainbow-delimiters-mode)
+      (add-hook 'cider-mode-hook 'smartparens-strict-mode)
+
+      (require 'ac-nrepl)
+      (add-hook 'cider-repl-mode-hook 'ac-nrepl-setup)
+      (add-hook 'cider-mode-hook 'ac-nrepl-setup)
+      (eval-after-load "auto-complete"
+        '(add-to-list 'ac-modes 'cider-repl-mode))
+
+      (defun set-auto-complete-as-completion-at-point-function ()
+        (setq completion-at-point-functions '(auto-complete)))
+      (add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
+
+      (add-hook 'cider-repl-mode-hook 'set-auto-complete-as-completion-at-point-function)
+      (add-hook 'cider-mode-hook 'set-auto-complete-as-completion-at-point-function)
+
+      (eval-after-load "cider"
+        '(define-key cider-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc))
+    #+END_SRC