Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
721 lines (591 sloc) 20.7 KB

General Emacs Settings

This section configures base settings for emacs.

backup files

Don’t crap ~ files everywhere.

(setq
 backup-by-copying t
 backup-directory-alist
 '(("." . "~/.saves"))
 delete-old-versions t
 kept-new-versions 6
 kept-old-versions 2
 version-control t)

load path

Packages that are not available through elpa/melpa can be put into ~/.emacs.d/local/. This adds that to the emacs loadpath.

(add-to-list 'load-path "~/.emacs.d/local/")

pragmata pro font

(set-default-font "PragmataPro Mono-13")
(load "pragmatapro-prettify-symbols")
(defun pragmata-ligatures ()
  (add-pragmatapro-prettify-symbols-alist)
  (prettify-symbols-mode))
(add-hook 'prog-mode-hook 'pragmata-ligatures)

aliases

This section defines aliases.

;; Use ibuffer whenever list-buffer is called.
(defalias 'list-buffer 'ibuffer)

keybindings

This section defines some global keybindings.

;; Install the default keybindings for windmove.
(windmove-default-keybindings)

;; Ingore C-z because why would I ever want that?!
(global-unset-key (kbd "C-z"))

interface tweaks

This section tweaks various aspects of the emacs interface.

;; Turn off a bunch of annoying things.
(setq inhibit-startup-message t)
(tool-bar-mode -1)
(menu-bar-mode -1)
(toggle-scroll-bar -1)
(blink-cursor-mode 0)
(fset 'yes-or-no-p 'y-or-n-p)

;; highlight current line, except in certain modes
(global-hl-line-mode t)
(make-variable-buffer-local 'global-hl-line-mode)
(defvar my-ghd-modes '(
                       shell-mode-hook
                       git-commit-mode-hook
                       term-mode-hook
                       )
  "Modes to ensure global-hl-line-mode is disabled for.")
(dolist (m my-ghd-modes)
  (add-hook m (lambda () (setq global-hl-line-mode nil))))

;; Use linum-mode when we're in a programming mode.
(add-hook 'prog-mode-hook 'linum-mode)

;; Manually diminish things that can't be diminished via use-package.
(diminish 'auto-revert-mode)

set up packages with melpa

This section sets up emacs for using pcakges and bootstraps use-package.

(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

;; Bootstrap 'use-package'
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

Installed Packages

This section sets up all the various packages, primarily using use-package.

ace window

ace-window provides a quick and easy way to switch between windows.

This configuration steals the keybinding for other-window (C-x o) and uses it for ace-window. I prefer ace-window to scope to the frame, rather than globally.

Invoke ace-window with `C-x o`, as normal. If there are only two windows, you’ll jump to the other window. If there are more than two windows, each window will get a numeric overlay. Type the number to jump to the desired window.

Using a `C-u` prefix will swap windows. `C-u C-u` will delete the selected window.

Once ace-window is active, other options can be taken:

  • `x` - delete window
  • `m` - swap (move) window
  • `c` - split window fairly
  • `v` - split window vertically
  • `b` - split window horizontally
  • `n` - select the previous window
  • `i` - maximize selected window
  • `o` - maximize current window
(use-package ace-window
  :init
  (global-set-key [remap other-window] 'ace-window)
  (setq aw-scope 'frame)
  (custom-set-faces
   '(aw-leading-char-face
     ((t (:inherit ace-jump-face-foreground :height 3.0))))))

auto complete

This just sets up the general auto-complete package.

(use-package auto-complete
  :diminish auto-complete-mode
  :init
  (ac-config-default)
  (setq ac-auto-start nil)
  (define-key ac-mode-map (kbd "M-TAB") 'auto-complete)
  (global-auto-complete-mode t))

counsel

counsel is used by the swiper package.

(use-package counsel
  :bind
  (("M-y" . counsel-yank-pop)
   :map ivy-minibuffer-map
   ("M-y" . ivy-next-line)))

deft

deft makes it easy to manage and navigate notes files

(use-package deft
  :init
  (setq deft-extension "org")
  (setq deft-extensions '("org"))
  (setq deft-text-mode 'org-mode)
  (setq deft-directory "~/Dropbox/org")
  (setq deft-auto-save-interval 0)
  (setq deft-recursive t)
  :bind
  (("\C-x C-g" . deft-find-file)))

direx

direx is a general purpose directory/tree package. I use this for go-direx.

(use-package direx)

elfeed

elfeed is an RSS reader, because google killed RSS.

(use-package elfeed
  :config
  (global-set-key (kbd "C-x w") 'elfeed))

emamux

emamux controls tmux from emacs. Most of the funcationality seems to be around running emacs from within tmux, which I do not do. However, emamux:send-command is very useful for sending commands to a tmux session. This can be triggered with C-z C-s.

(use-package emamux
  :config
  (global-set-key (kbd "C-z") emamux:keymap))

flycheck

flycheck is used for syntax checking in various languages.

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

go packages

This section contains all the packages related to Go programming.

Packages to look at

I’m not currently using these packages, but they look interesting.

go-mode

go-mode is the base package for working with Go.

(setenv "PATH" (concat (getenv "PATH") ":/home/scott/src/go/bin"))
(add-to-list 'exec-path "/home/scott/src/go/bin")
(use-package go-mode
  :config
  (setq gofmt-command "goimports")
  (add-hook 'before-save-hook 'gofmt-before-save)
  (add-hook 'go-mode-hook 'setup-go-mode-compile)
  (setenv "GOROOT" "/usr/lib/go")
  (setenv "GOPATH" "/home/scott/src/go")
  (add-hook 'go-mode-hook 'flycheck-mode))    

;; Run linters on save
(defun setup-go-mode-compile ()
  (if (not (string-match "go" compile-command))
      (set (make-local-variable 'compile-command)
           "gometalinter --deadline 1s && go vet")))

auto complete

This sets up go-autocomplete, which uses `gocode` for auto completion.

(require 'go-autocomplete)
(require 'auto-complete-config)

linting

This adds various linters to flycheck.

Dependancies:

  • gometalinter `go get github.com/alecthomas/gometalinter`
  • sub-linters `gometalinter –install`
(use-package flycheck-gometalinter
  :config
  (flycheck-gometalinter-setup)
  ;; skip linting vendor dirs
  (setq flycheck-gometalinter-vendor t)
  ;; use in test files
  (setq flycheck-gometalinter-test t)
  ;; only fast linters
  (setq flycheck-gometalinter-fast t)
  ;; disable gotype
  (setq flycheck-gometalinter-disable-linters '("gotype")))

go-add-tags

go-add-tags helps manage tags on struct fields.

(use-package go-add-tags)

go-eldoc

go-eldoc formats go documentation for emacs and displays it in the status bar.

(use-package go-eldoc
  :diminish eldoc-mode
  :config (add-hook 'go-mode-hook 'go-eldoc-setup))

go-direx

This package views go code in a tree style viewer. Page Depends on direx package. Need to install gotags with `go get -u github.com/jstemmer/gotags`

(use-package go-direx)
(define-key go-mode-map (kbd "C-c C-x") 'go-direx-pop-to-buffer)

go-guru

(use-package go-guru)
(add-hook 'go-mode-hook 'go-guru-hl-identifier-mode)

go-impl

go-impl adds impl to emacs.

(use-package go-impl
  :config 
  (custom-set-variables
   '(go-impl-aliases-alist '(("hh" . "http.Handler")
                             ("irw" . "io.ReadWriter")))))

magit

magit is the best git interface known to humankind.

I also use and configure magit-gh-pulls here.

(use-package magit
  :bind (("C-x g" . magit-status)))

(use-package magit-gh-pulls
  :config
  (add-hook 'magit-mode-hook 'turn-on-magit-gh-pulls))

markdown

markdown-mode is a mode for markdown.

(use-package markdown-mode
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "multimarkdown"))

mu4e

mu4e is part of mu, an email indexing and reading system.

(add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e")
(require 'mu4e)
(setq mu4e-maildir "~/.mail")
(setq mu4e-contexts
      `( ,(make-mu4e-context
           :name "Personal"
           :enter-func (lambda () (message "Entering Personal context"))
           :leave-func (lambda () (mu4e-message "Leaving Personal context"))
           :match-func (lambda (msg)
                         (when msg
                           (string-prefix-p "/barron" (mu4e-message-field msg :maildir))))
           :vars '( ( user-mail-address  . "scott@barron.io" )
                    ( user-full-name     . "Scott Barron" )
                    ( mu4e-trash-folder  . "/barron/trash" )
                    ( mu4e-refile-folder . "/barron/all" )
                    ( mu4e-sent-folder   . "/barron/sent" )
                    ( mu4e-drafts-folder . "/barron/drafts" )))

         ,(make-mu4e-context
           :name "GMail"
           :enter-func (lambda () (message "Switch to GMail context"))
           :match-func (lambda (msg)
                         (when msg
                           (string-prefix-p "/gmail" (mu4e-message-field msg :maildir))))
           :vars '( ( user-mail-address  . "scott.a.barron@gmail.com" )
                    ( user-full-name     . "Scott Barron" )
                    ( mu4e-trash-folder  . "/gmail/trash" )
                    ( mu4e-refile-folder . "/gmail/all" )
                    ( mu4e-sent-folder   . "/gmail/sent" )
                    ( mu4e-drafts-folder . "/gmail/drafts" )))

         ,(make-mu4e-context
           :name "GitHub"
           :enter-func (lambda () (mu4e-message "Switch to GitHub context"))
           :match-func (lambda (msg)
                         (when msg
                           (string-prefix-p "/github" (mu4e-message-field msg :maildir))))
           :vars '( ( user-mail-address . "rubyist@github.com" )
                    ( user-full-name    . "Scott Barron" )
                    ( mu4e-trash-folder . "/github/trash" )
                    ( mu4e-refile-folder . "/github/all" )
                    ( mu4e-sent-folder   . "/github/sent" )
                    ( mu4e-drafts-folder . "/gmail/drafts" )))))
(setq mu4e-bookmarks
      `( ,(make-mu4e-bookmark
           :name "Unread Messages"
           :query "flag:unread AND NOT flag:trashed"
           :key ?u)
         ,(make-mu4e-bookmark
           :name "Mention"
           :query "cc:mention AND NOT flag:trashed AND NOT maildir:/barron/all AND NOT maildir:/github/all"
           :key ?m)
         ,(make-mu4e-bookmark
           :name "Review Requests"
           :query "cc:review_requested AND NOT flag:trashed AND NOT maildir:/barron/all AND NOT maildir:/github/all"
           :key ?r)
         ,(make-mu4e-bookmark
           :name "Team Mentions"
           :query "cc:team_mention AND NOT flag:trashed AND NOT maildir:/barron/all AND NOT maildir:/github/all"
           :key ?t)
         ,(make-mu4e-bookmark
           :name "Today's Messages"
           :query "date:today..now"
           :key ?n)))

(setq mu4e-context-policy 'pick-first)
(setq mu4e-change-filenames-when-moving t)
(setq mu4e-update-interval 60)
(setq mu4e-hide-index-messages t)

org mode

Org mode is org mode.

(use-package org
  :config
  (setq org-src-preserve-indentation t)
  (setq org-ditaa-jar-path "/usr/share/java/ditaa/ditaa-0_10.jar")
  (setq org-confirm-babel-evaluate nil)
  (setq org-directory "~/Dropbox/org")
  (setq org-default-notes-file (concat org-directory "/notes.org"))
  (setq org-export-html-postamble nil)
  (setq org-startup-folded (quote overview))
  (setq org-startup-indented t)
  (setq org-file-apps (append '(
				("\\.pdf\\'" . "evince %s")
				) org-file-apps ))

  (setq org-capture-templates
	'(("a" "Appointment" entry (file "~/Dropbox/org/gcal.org" "Appointments")
	   "* TODO %?\n:PROPERTIES:\n\n:END:\nDEADLINE: %^T \n %i\n")
	  ("t" "Todo" entry (file+headline "~/Dropbox/org/todo.org" "Tasks")
	   "* TODO [#A] %?\nSCHDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n%a\n")))

  (defadvice org-capture-finalize
      (after delete-capture-frame activate)
    "Advise capture-finalize to close the frame"
    (if (equal "capture" (frame-parameter nil 'name))
	(delete-frame)))

  (defadvice org-capture-destroy
      (after delete-capture-frame activate)
    "Advise catpure-destroy to close the frame"
    (if (equal "capture" (frame-parameter nil 'name))
	(delete-frame)))

  (defadvice org-capture-kill
      (after delete-capture-frame activate)
    "Advise capture-kill to close the frame"
    (if (equal "capture" (frame-parameter nil 'name))
	(delete-frame)))

  (eval-after-load "org"
    '(require 'ox-md nil t))

  (org-babel-do-load-languages
   'org-babel-load-languages
   '((ditaa . t)))

  :bind
  (("\C-c c" . org-capture)
   ("\C-c a" . org-agenda)))

(use-package noflet
  :config
  (defun make-capture-frame ()
    "Create a new frame and run org-capture"
    (interactive)
    (select-frame-by-name "capture")
    (delete-other-windows)
    (noflet ((switch-to-buffer-other-window (buf) (switch-to-buffer buf)))
      (org-capture))))

org bullets

org-bullets makes org mode look nice.

(use-package org-bullets
  :config
  (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

org reveal

org-reveal will build reveal.js presentations from org mode files.

(use-package ox-reveal
  :ensure ox-reveal)

(setq org-reveal-root "http://cdn.jsdelivr.net/reveal.js/3.0.0/")
(setq org-reveal-mathjax t)

(use-package htmilize)

org mu4e

This mode links mu4e and org

(use-package org-mu4e
  :config
  (setq org-mu4e-link-query-in-headers-mode nil))

ob-http

ob-http is an org-babel extension that can make HTTP requests and stuff the output into RESULTS blocks. Example:

GET https://api.github.com/repos/rubyist/circuitbreaker/languages
(use-package ob-http)

ob-restclient

ob-restclient is another org-babel extension that can make HTTP requests and stuff the output into RESULT blocks. It uses restclient which has some extra features ob-http might not have. Example:

GET https://api.github.com/repos/rubyist/circuitbreaker/languages
User-Agent: ob-restclient

One thing to note here is that ob-restclient does not include a user agent header by default. Some things, like the GitHub API, don’t like that.

(use-package ob-restclient)

ox-hugo

(use-package ox-hugo
  :after ox)

projectile

projectile helps navigate to and within projects. This also sets up counsel-projectile.

The primary interactions I use here are:

  • `C-c p f` - find file in project
  • `C-c p T` - find test file in project
  • `C-c p b` - find buffer in project
(use-package projectile
  :config
  (projectile-global-mode)
  (setq projectile-completion-system 'ivy)
  (setq projectile-mode-line '(:eval (format " P[%s]" (projectile-project-name)))))

(use-package counsel-projectile
  :config
  (counsel-projectile-on))

protobuf

Mode for working with protocol buffers proto files.

(use-package protobuf-mode)

rainbow delimiters

(use-package rainbow-delimiters)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)

restclient

restclient is a tool for exploring REST APIs from within emacs.

(use-package restclient)

rjsx mode

This is dank for doing jsx in react.

(use-package rjsx-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . rjsx-mode))

swiper

swiper is an ivy-based alternative to isearch.

(use-package swiper
  :diminish ivy-mode
  :config
  (ivy-mode 1)
  (setq ivy-use-virtual-buffers t)
  :bind (("\C-s" . swiper)
         ("C-c C-r" . ivy-resume)
         ("M-x" . counsel-M-x)
         ("C-x C-f" . counsel-find-file)
         ("C-c g" . counsel-git)
         ("C-c j" . counsel-git-grep)
         ("C-c k" . counsel-ag)
         (:map read-expression-map ("C-r" . counsel-expression-history))))

theme

The theme.

(use-package dracula-theme
:init
(load-theme 'dracula t)
:ensure t)

try

try lets you try a package without installing it.

(use-package try)

undo tree

undo-tree provides a convenient way to navigate the undo ring.

(use-package undo-tree
  :diminish undo-tree-mode
  :init
  (global-undo-tree-mode))

which key

which-key figures out what a key does.

(use-package which-key
  :diminish which-key-mode
  :config
  (which-key-mode))

wsd-mode

wsd-mode is a major mode supporting web sequence diagrams syntax and rendering. It also works in org-mode code blocks.

(use-package wsd-mode)

yasnippet

yasnippet provides snippets.

(use-package yasnippet
  :diminish yas-minor-mode
  :init
  (yas-global-mode 1))

(add-to-list 'yas-snippet-dirs "~/.emacs.d/local/yasnippet-go")
(yas-reload-all)