Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
758 lines (717 sloc) 21.9 KB

Javier Aguirre’s Emacs 25 Configuration


Configuration based on Aaron Bedra’s

Configuration improved from joedicastro’s

User details

Emacs will normally pick this up automatically, but this way I can be sure the right information is always present.

(setq user-full-name "Javier Aguirre")
(setq user-mail-address "")

Package Management

We use use-package to install packages and manage the configuration

(setq package-archives '(("gnu" . "")
                         ("melpa" . "")
                         ("melpa-stable" . "")
                         ("org" . "")))

;; avoid problems with files newer than their byte-compiled counterparts
;; it's better a lower startup than load an outdated and maybe bugged package
(setq load-prefer-newer t)


(when (not package-archive-contents)

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

  (require 'use-package))


Set PATH for Emacs

(use-package exec-path-from-shell
 :ensure t
  (when (memq window-system '(mac ns))

Default startup options

Start with scratch and other default options
(setq inhibit-splash-screen t
      inhibit-startup-screen t
      window-combination-resize t
      visible-bell nil
      ring-bell-function 'ignore
      echo-keystrokes 0.1
      use-dialog-box nil
      apropos-do-all t
      initial-scratch-message nil)

(blink-cursor-mode -1)

;; delete the previous selection when overrides it with a new insertion.
(delete-selection-mode t)

(defalias 'list-buffers 'ibuffer)


(show-paren-mode 1)


Font selection

(setq javaguirre-font  "Operator Mono Book-14")
(add-to-list 'default-frame-alist `(font . ,javaguirre-font))
(set-face-attribute 'default t :font javaguirre-font)

Garbage collector threshold

Emacs for OS X crashes a lot, let see if increasing garbage collector solves the issue

The threshold is in bytes

(defun my-minibuffer-setup-hook ()
 (setq gc-cons-threshold most-positive-fixnum))

(defun my-minibuffer-exit-hook ()
 (setq gc-cons-threshold 800000))

(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook)

Remove all bars

Emacs starts up with way too much enabled. Turn off the scroll bar, menu bar, and tool bar. There isn’t really a reason to have them on.

(if (display-graphic-p)
 (scroll-bar-mode -1))
(tool-bar-mode -1)
(menu-bar-mode -1)
(tooltip-mode -1)


There’s nothing I dislike more than tabs in my files. Make sure I don’t share that discomfort with others.

(setq-default indent-tabs-mode nil)
(setq tab-width 4)

Backup files

Some people like to have them. I don’t. Rather than pushing them to a folder, never to be used, just turn the whole thing off.

(setq make-backup-files nil)

Yes and No

Nobody likes to have to type out the full yes or no when Emacs asks. Which it does often. Make it one character.

(defalias 'yes-or-no-p 'y-or-n-p)


(use-package material-theme
 :ensure t
 (load-theme 'material t))
(use-package ample-theme
 :disabled t
 :ensure t)

Internal modes

Configuration for Emacs internal modules

Desktop mode

	(use-package desktop
         :disabled t
	    (setq desktop-path '("~/.emacs.d/tmp/"))
	    (setq desktop-dirname "~/.emacs.d/tmp/")
	    (setq desktop-base-file-name "emacs-desktop")
	    (setq desktop-globals-to-save
		(append '((extended-command-history . 50)
			  (file-name-history . 200)
			  (grep-history . 50)
			  (compile-history . 50)
			  (minibuffer-history . 100)
			  (query-replace-history . 100)
			  (read-expression-history . 100)
			  (regexp-history . 100)
			  (regexp-search-ring . 100)
			  (search-ring . 50)
			  (shell-command-history . 50)
	    (desktop-save-mode 1)))

HideShow mode

(add-hook 'prog-mode-hook #'hs-minor-mode)

Which func mode

(which-function-mode t)

Auto revert buffer

(setq auto-revert-verbose nil)

External packages

Org mode

(use-package org
  :ensure t
    (setq org-src-fontify-natively t)
    (setq org-src-tab-acts-natively t)
    (setq org-time-clocksum-format
       (:hours "%d" :require-hours t :minutes ":%02d" :require-minutes t)))
    (setq org-pretty-entities t)
    (setq org-src-preserve-indentation t)
    (setq org-startup-folded nil)
    (setq org-src-tab-acts-natively t)))


(use-package magit
  :ensure t)

Higlight indentation

(use-package highlight-indentation
  :ensure t
   (set-face-background 'highlight-indentation-face "#e3e3d3")
   (set-face-background 'highlight-indentation-current-column-face "#e3e3d3")
   (add-hook 'prog-mode-hook 'highlight-indentation-mode)))


Better highlight when searching, like hlsearch in vim

(use-package highlight
  :ensure t)


Evil mode

(use-package evil
  :ensure t
  (evil-mode 1))
(use-package evil-surround
  :ensure t)
(use-package evil-magit
  :ensure t)
(use-package evil-nerd-commenter
  :ensure t
(use-package evil-smartparens
  :ensure t)
(use-package evil-search-highlight-persist
  :ensure t
    (global-evil-search-highlight-persist t)
    (setq evil-search-highlight-string-min-len 3)))
(use-package evil-surround
  :ensure t

Evil leader

(use-package evil-leader
  :ensure t

     "b"  'helm-buffers-list
     "c"  'delete-trailing-whitespace
	       "e"  '(lambda ()
	              (message "Buffer evaluated"))
     "n"  'next-error
     "m"  'helm-M-x
     "r"  'helm-recentf
     "s"  'magit-status
     "v"  'magit-blame
     "w"  'ffap-other-window
     "\\" 'evilnc-comment-operator
     "|"  'split-window-right
     "-"  'split-window-below
     "+"  'text-scale-increase
     "-"  'text-scale-decrease
     "z"  'hs-toggle-hiding
     "x"  'helm-semantic-or-imenu)

    ;; ORG
    (evil-leader/set-key-for-mode 'org
     "d" 'org-time-stamp
     "i" 'org-clock-in
     "o" 'org-clock-out)))

Key chord

I am using jk to move back to normal mode

(use-package key-chord
  :ensure t
    (setq key-chord-two-keys-delay 0.5)
    (key-chord-define evil-insert-state-map "jk" 'evil-normal-state)
    (key-chord-mode 1)))

Rest client

(use-package restclient
  :ensure t)

Smart parentheses

     (use-package smartparens
       :ensure t
         (smartparens-global-mode t)
         (add-hook 'smartparens-enabled-hook #'evil-smartparens-mode)))


(use-package powerline
  :ensure t


(use-package nyan-mode
  :ensure t
;;  :disabled t
  (when (display-graphic-p)
    (nyan-mode t)))


Modern Emacs Package Menu

(use-package paradox
  :ensure t
  (setq paradox-execute-asynchronously t))


Ansi-term. Set default shell to ZSH, killing buffer when exiting

     (setq term-ansi-default-program "/bin/zsh")

     (defadvice term-sentinel (around my-advice-term-sentinel (proc msg))
	(if (memq (process-status proc) '(signal exit))
	    (let ((buffer (process-buffer proc)))
		(kill-buffer buffer))
     (ad-activate 'term-sentinel)

Use zsh without asking which program to run

(defadvice ansi-term (before force-bash)
  (interactive (list term-ansi-default-program)))
(ad-activate 'ansi-term)

We disable variables and mode clashing with It

(add-hook 'term-mode-hook (lambda()
  (yas-minor-mode -1)
  (setq-default show-trailing-whitespace nil)))

Recent files

(use-package recentf
  :ensure t
    (recentf-mode 1)
    (setq recentf-max-menu-items 200)))

Guide key

(use-package guide-key
  :ensure t
    (setq guide-key/guide-key-sequence
     '("C-x r" "C-x 4" "C-x v"))
    (guide-key-mode 1)))


(use-package yasnippet
  :ensure t
    (add-to-list 'yas-snippet-dirs

OSX Clipboard

(use-package osx-clipboard
  :ensure t
  (osx-clipboard-mode +1))

Fill column indicator

Adds a vertical line to control line width

(use-package fill-column-indicator
  :ensure t
    (setq fci-rule-column 80)
    (setq fci-rule-character-color "dimgray")
    (setq fci-rule-color "dimgray")
    (setq fci-rule-use-dashes t)
    (add-hook 'prog-mode-hook 'fci-mode)))


(use-package flycheck
  :ensure t
  :init (global-flycheck-mode))


   (use-package projectile
     :ensure t
       (setq projectile-enable-caching t)
        "a" 'helm-projectile-ag
        "t" 'projectile-find-tag
        "f" 'helm-projectile-find-file-dwim)
	    "/usr/local/bin/ctags -Re \
            --extra=+fq \
            --exclude=.git --exclude=.vagrant \
            --exclude=locale --exclude=node_modules \
            --exclude=.venv --exclude=media --exclude=test-data \
            --exclude=vendor --exclude=dist \
            --exclude=CACHE \
            --totals=yes --exclude=vendor -f TAGS")))


 (use-package helm
   :ensure t
     (helm-mode 1)
     (global-set-key (kbd "M-x") 'helm-M-x)
     (global-set-key (kbd "C-x C-f") 'helm-find-files)
     (global-set-key (kbd "C-x b") 'helm-buffers-list)
	    '(helm-ag-base-command "/usr/local/bin/ag --nocolor --nogroup")
	    '(helm-ag-command-option "--all-text --case-sensitive")
	    '(helm-ag-insert-at-point 'symbol))))
(use-package helm-ag
  :ensure t)
(use-package helm-projectile
  :ensure t)

Dumb Jump

    (use-package dumb-jump
      :ensure t
	  "d" 'dumb-jump-go)
	  "q" 'dumb-jump-quick-look)))

Git Gutter

   (use-package git-gutter
     :ensure t
	(global-git-gutter-mode +1)
	(setq git-gutter:modified-sign "~")
	(set-face-foreground 'git-gutter:modified "orange")
	  "g" 'git-gutter:next-hunk)))

Rainbow delimiters

(use-package rainbow-delimiters
  :ensure t
  (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))


Ido mode provides a nice way to navigate the filesystem. This is mostly just turning it on.

(ido-mode t)
(setq ido-enable-flex-matching t
      ido-use-virtual-buffers t
      ido-everywhere t)


(global-linum-mode 1)
(setq linum-format "%3d ")
(global-hl-line-mode 1)

Column number mode

Turn on column numbers.

(setq column-number-mode t)
(setq toggle-highlight-column-when-idle 0.1)

Temporary file management

Deal with temporary files. I don’t care about them and this makes them go away.

(setq backup-directory-alist `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))

Centered window mode

(use-package centered-window-mode
 :ensure t
 (centered-window-mode t))

Company mode

Company mode

(use-package company
  :ensure t
    (add-hook 'after-init-hook 'global-company-mode)

    ;; Workaround to support fci
    (defvar-local company-fci-mode-on-p nil)

    (defun company-turn-off-fci (&rest ignore)
    (when (boundp 'fci-mode)
        (setq company-fci-mode-on-p fci-mode)
        (when fci-mode (fci-mode -1))))

    (defun company-maybe-turn-on-fci (&rest ignore)
    (when company-fci-mode-on-p (fci-mode 1)))

    (add-hook 'company-completion-started-hook 'company-turn-off-fci)
    (add-hook 'company-completion-finished-hook 'company-maybe-turn-on-fci)
    (add-hook 'company-completion-cancelled-hook 'company-maybe-turn-on-fci)))

Emmet mode

(use-package emmet-mode
  :ensure t
    (add-hook 'sgml-mode-hook 'emmet-mode)
    (add-hook 'css-mode-hook  'emmet-mode)))

Indentation and buffer cleanup

This re-indents, untabifies, and cleans up whitespace. It is stolen directly from the emacs-starter-kit.

(defun untabify-buffer ()
  (untabify (point-min) (point-max)))

(defun indent-buffer ()
  (indent-region (point-min) (point-max)))

(defun cleanup-buffer ()
  "Perform a bunch of operations on the whitespace content of a buffer."

(defun cleanup-region (beg end)
  "Remove tmux artifacts from region."
  (interactive "r")
  (dolist (re '("\\\\*\n" "\W*│*"))
    (replace-regexp re "" nil beg end)))

(global-set-key (kbd "C-x M-t") 'cleanup-region)
(global-set-key (kbd "C-c n") 'cleanup-buffer)

(setq-default show-trailing-whitespace t)


(setq flyspell-issue-welcome-flag nil)
(if (eq system-type 'darwin)
    (setq-default ispell-program-name "/usr/local/bin/aspell")
  (setq-default ispell-program-name "/usr/bin/aspell"))
(setq-default ispell-list-command "list")

Language modes


(use-package jedi
 :ensure t
  (add-hook 'python-mode-hook 'jedi:setup)
   (setq jedi:complete-on-dot t)
  (add-hook 'python-mode-hook
   '(lambda () (modify-syntax-entry ?_ "w" python-mode-syntax-table)))))
(with-eval-after-load 'evil
  (defalias #'forward-evil-word #'forward-evil-symbol))


    (use-package web-mode
      :ensure t
      :mode ("\\.html?\\'" . web-mode)
      :mode ("\\.html\\.twig?\\'" . web-mode)
      :mode ("\\.tpl\\.php?\\'" . web-mode)
      :mode ("\\.jsx?\\'" . web-mode)
	 (setq web-mode-css-indent-offset 4)
	 (setq web-mode-code-indent-offset 4)
	 (add-hook 'after-change-major-mode-hook
	  (lambda () (if (string= major-mode "web-mode")
	      (turn-off-fci-mode) (turn-on-fci-mode))))))


(use-package js2-mode
  :ensure t
    (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)))


(use-package multi-term
  :ensure t)


(use-package php-mode
  :ensure t
     (add-to-list 'auto-mode-alist '("\\.inc" . php-mode))
     (add-to-list 'auto-mode-alist '("\\.module" . php-mode))
     (setq php-manual-path "~/Downloads/phpmanualen")))


(use-package vagrant
  :ensure t
  (setq vagrant-up-options "--provision"))


Add additional file extensions that trigger yaml-mode.

(use-package yaml-mode
  :ensure t
    (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
    (add-to-list 'auto-mode-alist '("\\.yaml$" . yaml-mode))
    (setq yaml-indent-offset 2)))


The template engine

(use-package haml-mode
  :ensure t)

CoffeeScript Mode

The default CoffeeScript mode makes terrible choices. This turns everything into 2 space indentations and makes it so the mode functions rather than causing you indentation errors every time you modify a file.

(use-package coffee-mode
  :ensure t
	   (defun coffee-custom ()
	    (make-local-variable 'tab-width)
	    (set 'tab-width 2))
	   (add-hook 'coffee-mode-hook 'coffee-custom)))

Markdown Mode

Enable Markdown mode and setup additional file extensions. Use pandoc to generate HTML previews from within the mode, and use a custom css file to make it a little prettier.

	(use-package markdown-mode
	  :ensure t
	    (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
	    (add-to-list 'auto-mode-alist '("\\.mdown$" . markdown-mode))
	    (add-hook 'markdown-mode-hook
             (lambda ()
             (visual-line-mode t)
             (writegood-mode t)
             (flyspell-mode t)))
	    (setq markdown-command "pandoc --smart -f markdown -t html")))

Other modes


(defun split-window-right-ignore (&optional size)
  (if (car size) size (list (/ (window-total-width) 2))))

(advice-add 'split-window-right :filter-args


	(use-package neotree
	 :ensure t
         (add-hook 'neotree-mode-hook
           (lambda ()
             (define-key evil-normal-state-local-map (kbd "TAB") 'neotree-enter)
             (define-key evil-normal-state-local-map (kbd "SPC") 'neotree-quick-look)
             (define-key evil-normal-state-local-map (kbd "q") 'neotree-hide)
             (define-key evil-normal-state-local-map (kbd "RET") 'neotree-enter)))

         (setq projectile-switch-project-action 'neotree-projectile-action)
         (setq neo-smart-open t)))