Add melpa to the package list and initialize our packages
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)
Set up use-package
which is a nicer way of organizing config.
;; Ensure use-package is installed
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
;; Configure and load use-package
(setq use-package-always-ensure t)
(require 'diminish)
(eval-when-compile
(defvar use-package-verbose t)
(require 'use-package))
Load a theme
(load-theme 'tango-dark)
(use-package monokai-theme
:disabled t
:config
(load-theme 'monokai t))
Set a font if we’re in a gui.
(if (window-system)
(set-frame-font "Source Code Pro 10"))
Add column and line numbers to the modeline
(column-number-mode 1)
(line-number-mode 1)
This simply changes the name of some of the major modes in the modeline so we don’t need to see the whole thing.
(defmacro diminish-major-mode (mode new-name)
`(add-hook (intern (concat (symbol-name ,mode) "-hook"))
'(lambda () (setq mode-name ,new-name))))
(diminish-major-mode 'lisp-interaction-mode "λ»")
(diminish-major-mode 'emacs-lisp-mode "Eλ")
(diminish-major-mode 'lisp-mode "λ")
Disable all the extra menus and crap
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
smart-mode-line
is a simple modeline which is a huge improvement
over the default
(use-package smart-mode-line
:config
(setq sml/no-confirm-load-theme t
sml/theme 'dark)
(sml/setup))
ido, or interactively-do, is a nice replacement for most internal prompts.
(use-package ido
:config
;; smex is a better replacement for M-x
(use-package smex
:bind
("M-x" . smex)
("M-X" . smex-major-mode-commands))
;; Use ido everywhere we can
(use-package ido-ubiquitous
:config
(ido-ubiquitous-mode 1))
;; This makes ido work vertically
(use-package ido-vertical-mode
:config
(setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right
ido-vertical-show-count t)
(ido-vertical-mode 1))
;; This adds flex matching to ido
(use-package flx-ido
:config
(flx-ido-mode 1)
(setq ido-enable-flex-matching t
flx-ido-threshold 1000))
;; Turn on ido everywhere we can
(ido-mode 1)
(ido-everywhere 1)
(setq resize-mini-windows t
ido-use-virtual-buffers t
ido-auto-merge-work-directories-length -1))
Project based navigation is really nice. All key binds for projectile are prefixed with C-p p.
(use-package projectile
:diminish projectile-mode
:config (projectile-global-mode))
This makes it so when you get to the top or the bottom it will only scroll by a few lines, rather than a page at a time.
(use-package smooth-scrolling
:config
(setq smooth-scroll-margin 5
scroll-conservatively 101
scroll-preserve-screen-position t
auto-window-vscroll nil
scroll-margin 5)
(smooth-scrolling-mode 1))
undo-tree
improves undos so you can actually undo more than the
directly previous action.
(use-package undo-tree
:diminish undo-tree-mode
:config
(global-undo-tree-mode 1))
Which-key will make it easier to find commands when they’re partially typed in.
(use-package which-key
:diminish which-key-mode
:config
(which-key-mode 1)
(setq which-key-idle-delay 0.5
which-key-popup-type 'side-window
which-key-side-window-location 'right))
VCS stuff, like status in the gutter and reverting of buffers if they’ve changed on disk (like during a checkout) and haven’t been modified in emacs.
(use-package diff-hl
:config
;; We only need diff-hl-margin-mode if we're in a terminal.
(global-diff-hl-mode 1)
(unless (window-system)
(diff-hl-margin-mode 1)))
;; Revert buffers if they've changed on disk
(global-auto-revert-mode 1)
(setq auto-revert-verbose nil)
General programming settings and hooks
;;; Programming stuff
(which-function-mode 1)
;; Most programming modes are derived from prog-mode, so common hooks
;; can go here
(add-hook 'prog-mode-hook
(lambda ()
(linum-mode 1)
(setq show-trailing-whitespace)))
;; We only want to set the linum-format if we're in a terminal.
(unless (window-system)
(setq linum-format "%4d\u2502"))
This will make sure things like TODO, FIXME, and XXX are noticed
(use-package fic-mode
:diminish fic-mode
:config
(add-hook 'prog-mode-hook 'fic-mode))
Random syntax things
(use-package web-mode
:mode
"\\.jinja\\'"
"\\.html\\'")
(use-package less-css-mode
:mode "\\.less\\'")
(use-package js2-mode
:mode "\\.js\\'")
(use-package cmake-mode
:mode
"CMakeLists\\.txt\\'"
"\\.cmake\\'")
(use-package json-mode
:mode "\\.json\\'")
(use-package lua-mode
:mode "\\.lua\\'")
(use-package markdown-mode
:mode ("\\.md\\'" . gfm-mode))
(use-package php-mode
:mode "\\.php\\'")
(use-package racket-mode
:mode "\\.rkt\\'")
(use-package ruby-mode
:mode
"Rakefile"
"\\.rb\\'")
(use-package systemd
:mode ("\\.service\'" . systemd-mode))
General annoyances. (salute)
;; Ensure backups make it to a different folder so we don't litter all
;; our directories with them.
(setq save-place-file (concat user-emacs-directory "places")
backup-directory-alist `(("." . ,(concat user-emacs-directory
"backups"))))
;; Improve buffer names when duplicate files are opened
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; Show parens
(show-paren-mode 1)
;; Make it so you only need to type 'y' or 'n' not 'yes' or 'no'
(fset 'yes-or-no-p 'y-or-n-p)
;; Damn visual bell
(setq ring-bell-function 'ignore)
;; Support the mouse and colors in the terminal
(xterm-mouse-mode 1)
;; We don't care about the startup screen. Just give us a scratch buffer.
(setq initial-buffer-choice t
inhibit-startup-screen t)
Thanks