Skip to content

Instantly share code, notes, and snippets.

@jkachmar
Created May 11, 2020 02:08
Show Gist options
  • Save jkachmar/555f959d5141804b37a42ab085c02b44 to your computer and use it in GitHub Desktop.
Save jkachmar/555f959d5141804b37a42ab085c02b44 to your computer and use it in GitHub Desktop.
Emacs config
;;; init.el --- jkachmar's Emacs setup. -*- lexical-binding: t; -*-
;;
;;; Commentary:
;; This file loads use-package, org-mode, and compiles and executes readme.org
;;
;;; Code:
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package)
)
;; Top-level defaults
(setq lexical-binding t) ;; Proper lexical scoping for elisp.
;; Make Emacs shell-aware.
(use-package exec-path-from-shell :ensure t
:config (exec-path-from-shell-initialize)
)
;; ----------------------------------------------------------------------------
;; Emacs is broken by default, fix things up a bit...
;; ----------------------------------------------------------------------------
;; Set Emacs to use a font I prefer.
(ignore-errors (set-frame-font "Fira Code-12")) ;
(mac-auto-operator-composition-mode) ;; Mac-only ligature support
;; Basic UI/UX stuff
(setq
;; GNU propaganda is still propaganda.
inhibit-startup-screen t
;; No need to remind me what a scratch buffer is.
initial-scratch-message nil
;; Microsoft Word now flags two spaces after a period as an error, who am
;; I to disagree?
sentence-end-double-space nil
;; My phone's ringer is always turned off and so is my editor's.
ring-bell-function 'ignore
;; Prompts should go in the minibuffer, not in a GUI.
use-dialog-box nil
;; Fix undo in commands affecting the mark.
mark-even-if-inactive nil
;; Let C-k delete the whole line.
kill-whole-line t
;; search should be case-sensitive by default
case-fold-search nil
)
(unbind-key "<mouse-2>") ;; Disable middle-mouse-click to paste.
(setq-default indent-tabs-mode nil) ;; Tabs are verboten.
(defalias 'yes-or-no-p 'y-or-n-p) ;; 'y' is a reasonable substitute for 'yes'.
(set-fill-column 80) ;; 80 columns is a good default for most things.
(delete-selection-mode t) ;; This should _really_ be on by default.
(global-display-line-numbers-mode t) ;; Line numbers are obviously good.
(column-number-mode)
(show-paren-mode) ;; Matching parens should be highlighted.
(setq scroll-conservatively 101) ;; Don't recenter the cursor when scrolling offscreen.
(setq scroll-margin 5) ;; Margin from the bottom/top of the cursor for when to scroll.
;; UTF-8 encoding.
(set-charset-priority 'unicode)
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
;; Highlight the current line, but disable it in areas where it might slow
;; things down
(require 'hl-line)
(add-hook 'prog-mode-hook #'hl-line-mode)
(add-hook 'text-mode-hook #'hl-line-mode)
(set-face-attribute 'hl-line nil :background "gray26")
;; Disable the useless automatic backup files.
(setq
make-backup-files nil
auto-save-default nil
create-lockfiles nil)
;; Disable the custom-file and fix the warnings that this causes for themes.
(setq custom-file (make-temp-file ""))
(setq custom-safe-themes t)
;; Don't show stuff from elpa in the recent files
(require 'recentf)
(add-to-list 'recentf-exclude "\\elpa")
;; Bindings I'd rather not accidentally trigger
(unbind-key "C-x C-f") ;; find-file-read-only
(unbind-key "C-x C-d") ;; list-directory
(unbind-key "C-z") ;; suspend-frame
(unbind-key "M-o") ;; facemenu-mode
;; Delete trailing whitespace and ensure all files have newline.
(add-hook 'before-save-hook #'delete-trailing-whitespace)
(setq require-final-newline t)
;; SSH should work with the system keychain.
(use-package keychain-environment :ensure t
:config
(keychain-refresh-environment)
)
;; Ensure diminish and delight are installed (so that use-package may take
;; advantage of them).
(use-package diminish :ensure t
:config (diminish 'eldoc-mode)
)
(use-package delight :ensure t)
;; ----------------------------------------------------------------------------
;; Evil and co. (keymapping)
;; ----------------------------------------------------------------------------
;; Evil requires undo-tree
(use-package undo-tree :ensure t
:config (undo-tree-mode)
)
;; EVIL IS THE BETTER DEFAULT!
(use-package evil :ensure t
:config (evil-mode 1)
)
;; Displays key bindings that follow from a currently-entered command fragment.
(use-package which-key :ensure t
:config
(which-key-mode)
(which-key-setup-side-window-bottom)
(setq which-key-sort-order 'which-key-key-order-alpha
which-key-side-window-max-width 0.33
which-key-idle-delay 1)
)
(use-package general :ensure t
:config
(general-evil-setup)
(setq general-default-keymaps 'evil-normal-state-map)
(general-define-key :keymaps 'dired-mode-map "SPC" nil)
(general-define-key
:keymaps 'visual
"SPC ;" 'comment-or-uncomment-region
)
;; Super basic shit.
(general-define-key
"C--" 'text-scale-decrease
"C-0" '(lambda() (interactive) (text-scale-set 0))
"C-=" 'text-scale-increase
"M-x" 'helm-M-x
"SPC ; ;" 'comment-line
)
;; Buffer shit.
(general-define-key
"SPC b b" 'helm-buffers-list
"SPC b d" 'jwoo-kill-this-buffer
)
;; File shit.
(general-define-key
"SPC f f" 'helm-find-files
)
;; Window management shit.
(general-define-key
"SPC w /" 'split-window-right
"SPC w -" 'split-window-below
"SPC w d" 'delete-window
"SPC w h" 'windmove-left
"SPC w j" 'windmove-down
"SPC w k" 'windmove-up
"SPC w l" 'windmove-right
)
)
;; Stolen from Justin's dotfiles.
(defun jwoo-kill-this-buffer ()
"Why the fuck does kill-this-buffer require menu"
(interactive)
(kill-buffer (current-buffer))
)
;; ----------------------------------------------------------------------------
;; Helm
;; ----------------------------------------------------------------------------
;; Needs must.
(use-package helm :ensure t
:init
(setq
helm-M-x-fuzzy-match t
helm-mode-fuzzy-match t
helm-buffers-fuzzy-matching t
helm-recentf-fuzzy-match t
helm-locate-fuzzy-match t
helm-semantic-fuzzy-match t
helm-imenu-fuzzy-match t
helm-completion-in-region-fuzzy-match t
helm-candidate-number-list 80
helm-split-window-in-side-p t
helm-move-to-line-cycle-in-source t
helm-echo-input-in-header-line t
helm-autoresize-max-height 0
helm-autoresize-min-height 20
)
:config
;; I want tab to do the smart things, not the dumb things
(define-key helm-map (kbd "<tab>") #'helm-execute-persistent-action)
(define-key helm-map (kbd "C-z") #'helm-select-action)
(helm-mode 1)
)
;; Helm should use ripgrep
(use-package helm-rg :ensure t)
;; ----------------------------------------------------------------------------
;; Git
;; ----------------------------------------------------------------------------
;; ----------------------------------------------------------------------------
;; Themes and other visual modifications
;; ----------------------------------------------------------------------------
;; Disable all of Emacs default window chrome.
(when (window-system)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(tooltip-mode -1)
(fringe-mode -1)
)
;; Pull in some nicer icons and configure dired to work with them.
(use-package all-the-icons :ensure t)
(use-package all-the-icons-dired :ensure t
:after all-the-icons
:hook (dired-mode . all-the-icons-dired-mode)
)
;; Prefer Doom's modline (it's quite nice).
(use-package doom-modeline :ensure t
:config (doom-modeline-mode)
)
;; Gruvbox has been my theme-of-choice for years now, and Doom's version is
;; quite nice.
(use-package doom-themes :ensure t
:config
(let ((chosen-theme 'doom-gruvbox))
(doom-themes-visual-bell-config)
(doom-themes-org-config)
(setq doom-gruvbox-brighter-comments t)
(load-theme chosen-theme)
)
)
;; ----------------------------------------------------------------------------
;; Language and IDE shit
;; ----------------------------------------------------------------------------
;; Haskell
(use-package haskell-mode :ensure t
:mode "\\.hs\\'"
)
;;; init.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment