Permalink
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

Configuration based on Aaron Bedra’s https://github.com/abedra/emacs.d

Configuration improved from joedicastro’s https://github.com/joedicastro/dotfiles/tree/master/emacs

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 "hello@javaguirre.net")

Package Management

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

(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("melpa" . "http://melpa.org/packages/")
                         ("melpa-stable" . "http://stable.melpa.org/packages/")
                         ("org" . "http://orgmode.org/elpa/")))

;; 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)

(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

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

(eval-when-compile
  (require 'use-package))

Environment

Set PATH for Emacs

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

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)

(toggle-indicate-empty-lines)

(show-paren-mode 1)

Font

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)

Indentation

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)

Themes

(use-package material-theme
 :ensure t
 :config
 (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
	  :config
	  (progn
	    (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)
			  tags-file-name
			  register-alist)))
	    (desktop-save-mode 1)))

HideShow mode

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

Which func mode

(which-function-mode t)

Auto revert buffer

(global-auto-revert-mode)
(setq auto-revert-verbose nil)

External packages

Org mode

(use-package org
  :ensure t
  :config
  (progn
    (setq org-src-fontify-natively t)
    (setq org-src-tab-acts-natively t)
    (setq org-time-clocksum-format
      (quote
       (: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)))

Magit

(use-package magit
  :ensure t)

Higlight indentation

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

Highlight

Better highlight when searching, like hlsearch in vim

(use-package highlight
  :ensure t)

Evil

Evil mode

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

Evil leader

(use-package evil-leader
  :ensure t
  :config
  (progn
    (global-evil-leader-mode)

    (evil-leader/set-key
     "b"  'helm-buffers-list
     "c"  'delete-trailing-whitespace
	       "e"  '(lambda ()
	              (interactive)
	              (eval-buffer)
	              (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
  :config
  (progn
    (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
       :config
	(progn
         (smartparens-global-mode t)
         (add-hook 'smartparens-enabled-hook #'evil-smartparens-mode)))

Powerline

(use-package powerline
  :ensure t
  :config
  (powerline-default-theme))

Nyan

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

Paradox

Modern Emacs Package Menu

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

Shell

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)))
		ad-do-it
		(kill-buffer buffer))
	    ad-do-it))
     (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()
  (goto-address-mode)
  (yas-minor-mode -1)
  (setq-default show-trailing-whitespace nil)))

Recent files

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

Guide key

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

Yasnippet

(use-package yasnippet
  :ensure t
  :config
  (progn
    (yas-global-mode)
    (add-to-list 'yas-snippet-dirs
      "~/.emacs.d/snippets")))

OSX Clipboard

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

Fill column indicator

Adds a vertical line to control line width

(use-package fill-column-indicator
  :ensure t
  :config
  (progn
    (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)))

Flycheck

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

Projectile

   (use-package projectile
     :ensure t
     :config
     (progn
	  (projectile-global-mode)
       (setq projectile-enable-caching t)
	  (evil-leader/set-key
        "a" 'helm-projectile-ag
        "t" 'projectile-find-tag
        "f" 'helm-projectile-find-file-dwim)
	  (setq
	    projectile-tags-command
	    "/usr/local/bin/ctags -Re \
            --langmap=php:.inc.module.install.php \
            --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")))

Helm

 (use-package helm
   :ensure t
   :config
   (progn
     (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)
     (custom-set-variables
	    '(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
      :config
      (progn
	 (evil-leader/set-key
	  "d" 'dumb-jump-go)
	 (evil-leader/set-key
	  "q" 'dumb-jump-quick-look)))

Git Gutter

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

Rainbow delimiters

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

Ido

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)

Linum

(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
 :config
 (centered-window-mode t))

Company mode

Company mode

(use-package company
  :ensure t
  :config
  (progn
    (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
  :config
  (progn
    (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 ()
  (interactive)
  (untabify (point-min) (point-max)))

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

(defun cleanup-buffer ()
  "Perform a bunch of operations on the whitespace content of a buffer."
  (interactive)
  (indent-buffer)
  (untabify-buffer)
  (delete-trailing-whitespace))

(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)

flyspell

(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

Python

(use-package jedi
 :ensure t
 :config
 (progn
  (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))

Web

    (use-package web-mode
      :ensure t
      :mode ("\\.html?\\'" . web-mode)
      :mode ("\\.html\\.twig?\\'" . web-mode)
      :mode ("\\.tpl\\.php?\\'" . web-mode)
      :mode ("\\.jsx?\\'" . web-mode)
      :config
      (progn
	 (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))))))

Javascript

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

Multi-term

(use-package multi-term
  :ensure t)

PHP

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

Vagrant

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

YAML

Add additional file extensions that trigger yaml-mode.

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

HAML

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
  :config
  (progn
	   (defun coffee-custom ()
	    "coffee-mode-hook"
	    (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
	  :config
	  (progn
	    (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

Workaround

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

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

NeoTree

	(use-package neotree
	 :ensure t
        :config
        (progn
         (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)))