From 88d04aa1630279ef528edf013f529cd192e5184d Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Thu, 9 Jan 2020 09:46:42 -0800 Subject: [PATCH] Refactor emacs dotfile --- dotfiles/emacs.d/init.el | 389 +++++--------------------------------------- dotfiles/emacs.d/package.el | 12 +- 2 files changed, 40 insertions(+), 361 deletions(-) diff --git a/dotfiles/emacs.d/init.el b/dotfiles/emacs.d/init.el index a39a29f..864eb60 100644 --- a/dotfiles/emacs.d/init.el +++ b/dotfiles/emacs.d/init.el @@ -1,30 +1,16 @@ -;;-------------------------------------------------------------------------------------- -;; -;; EMACS Configuration file -;; -;;-------------------------------------------------------------------------------------- - (require 'package) ;;-------------------------------------------------------------------------------------- -;; Generic line numbering disabler -;;-------------------------------------------------------------------------------------- - -(defun nolinum () - (linum-mode 0) -) - -;;-------------------------------------------------------------------------------------- -;; Hide menu bar (Opens up frame real estate in console mode) +;; Turn off the startup screen ;;-------------------------------------------------------------------------------------- -(menu-bar-mode -1) +(setq inhibit-startup-screen t) ;;-------------------------------------------------------------------------------------- -;; Hide Startup Message +;; Display battery life in modeline ;;-------------------------------------------------------------------------------------- -(setq inhibit-startup-message t) +(display-battery-mode 1) ;;-------------------------------------------------------------------------------------- ;; Always follow symbolic links to version controlled files @@ -36,32 +22,6 @@ (setq vc-follow-symlinks t) ;;-------------------------------------------------------------------------------------- -;; Small fix for keyboard internationalization problems -;;-------------------------------------------------------------------------------------- - -(set-keyboard-coding-system nil) - -;;-------------------------------------------------------------------------------------- -;; Disable Splash Screen -;;-------------------------------------------------------------------------------------- - -(defvar Inhibit-Splash-Screen) -(setq Inhibit-Splash-Screen t) - -;;-------------------------------------------------------------------------------------- -;; Prefer UTF-8 For Buffers -;;-------------------------------------------------------------------------------------- - -(prefer-coding-system 'utf-8) -(set-terminal-coding-system 'utf-8) - -(defun set-buffer-utf8 () - (set-buffer-process-coding-system 'utf-8 'utf-8) -) - -(add-hook 'eshell-mode-hook 'set-buffer-utf8) - -;;-------------------------------------------------------------------------------------- ;; Enable Org-mode and set agenda files ;;-------------------------------------------------------------------------------------- @@ -147,6 +107,7 @@ (setq ibuffer-show-empty-filter-groups nil) + ;;-------------------------------------------------------------------------------------- ;; Enable MELPA ;;-------------------------------------------------------------------------------------- @@ -164,341 +125,56 @@ (package-refresh-contents)) ;;-------------------------------------------------------------------------------------- -;; Install and load Packages +;; Theming ;;-------------------------------------------------------------------------------------- -(load-file "~/.emacs.d/package.el") - -;;-------------------------------------------------------------------------------------- -;; Jedi Completion for Python -;;-------------------------------------------------------------------------------------- - -(add-hook 'python-mode-hook 'jedi:setup) -(setq jedi:complete-on-dot t) - -(defun my/python-mode-hook () - (add-to-list 'company-backends 'company-jedi)) - -(add-hook 'python-mode-hook 'my/python-mode-hook) +(load-theme 'material t) ;;-------------------------------------------------------------------------------------- -;; Ensure Shell Variables Look the Same in Emacs (OS X and Linux) +;; Default modes ;;-------------------------------------------------------------------------------------- -(when (memq window-system '(mac ns x)) - (exec-path-from-shell-initialize)) - -;;-------------------------------------------------------------------------------------- -;; Enable ParEdit for Emacs lisp modes -;;-------------------------------------------------------------------------------------- +(ivy-mode 1) -(autoload 'enable-paredit-mode "paredit" t) +;; Enable paredit for lisp +(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t) (add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode) (add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode) (add-hook 'ielm-mode-hook #'enable-paredit-mode) (add-hook 'lisp-mode-hook #'enable-paredit-mode) (add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode) (add-hook 'scheme-mode-hook #'enable-paredit-mode) -(add-hook 'clojure-mode-hook #'enable-paredit-mode) - -;;-------------------------------------------------------------------------------------- -;; handy editor stuff -;;-------------------------------------------------------------------------------------- - -(require 'ws-butler) -(ws-butler-global-mode t) - -;; Comment this if you dont mind git diffs complaining about missing ending newlines. -(setq require-final-newline t) - -;; Add new line if using C-n navigates to the end of the buffer -(setq next-line-add-newlines t) - -(require 'whitespace) -(setq whitespace-style '(face lines-tail)) -(add-hook 'prog-mode-hook 'whitespace-mode) -;;-------------------------------------------------------------------------------------- -;; If python.el is loaded, change the rule column to 80 characters. -;;-------------------------------------------------------------------------------------- - -(eval-after-load "python" - '(progn - (setq whitespace-line-column 80))) +(require 'rainbow-delimiters) -;;-------------------------------------------------------------------------------------- -;; Expand region settings -;;-------------------------------------------------------------------------------------- - -(require 'expand-region) -(pending-delete-mode t) ; Selected region contents are replaced on typing +(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode) +(add-hook 'lisp-mode-hook 'rainbow-delimiters-mode) +(add-hook 'scheme-mode-hook 'rainbow-delimiters-mode) +(add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode) +;; Only enable aggressive indent on lisp-likes +(add-hook 'emacs-lisp-mode-hook #'aggressive-indent-mode) +(add-hook 'lisp-mode-hook #'aggressive-indent-mode) +(add-hook 'scheme-mode-hook #'aggressive-indent-mode) +(add-hook 'clojure-mode-hook #'aggressive-indent-mode) ;;-------------------------------------------------------------------------------------- -;; Line Numbering - Note: Might not look good with files with 10,000 or more lines +;; Save hooks ;;-------------------------------------------------------------------------------------- -;; NOTE: Line numbers are toggled with C-c n - -(defvar linum-format) -(setq linum-format "%4d \u2502") - -;; TODO: Figure out a way to make linum-relative keep the same linum-mode styles +(add-hook 'before-save-hook 'delete-trailing-whitespace) ;;-------------------------------------------------------------------------------------- -;; Hook framemove into windmove for seamless window to frame transitions +;; Keybinds ;;-------------------------------------------------------------------------------------- -(setq framemove-hook-into-windmove t) +(global-set-key "\C-s" 'swiper) ;;-------------------------------------------------------------------------------------- -;; Highlight matching parentheses when cursor is over one -;;-------------------------------------------------------------------------------------- - -(show-paren-mode 1) - -;;-------------------------------------------------------------------------------------- -;; Ivy Configuration -;;-------------------------------------------------------------------------------------- - -(ivy-mode 1) - -;(setq projectile-completion-system 'ivy) -(setq magit-complete-read-function 'ivy-completing-read) -(setq ivy-use-virtual-buffers t) - -;;------------------------------------------------------------------------------------- -;; Use Grizzl with Projectile -;;------------------------------------------------------------------------------------- - -(setq projectile-completion-system 'grizzl) - -;;------------------------------------------------------------------------------------- -;; ZSH script detection -;;------------------------------------------------------------------------------------ - -(add-hook 'sh-mode-hook - (lambda () - (if (string-match "\\.zsh$" buffer-file-name) - (sh-set-shell "zsh")))) - -;;------------------------------------------------------------------------------------- -;; Enable and Configure `company-mode` -;;------------------------------------------------------------------------------------ - -(global-company-mode t) -(add-hook 'after-init-hook 'global-company-mode) - -(defun company/python-mode-hook () - (add-to-list 'company-backends 'company-jedi)) - -(add-hook 'python-mode-hook 'company/python-mode-hook) - -;;------------------------------------------------------------------------------------- -;; Alignment -;;------------------------------------------------------------------------------------- - -(setq-default indent-tabs-mode nil) -(setq-default tab-width 2) - -;; Make sure the tab key only indents (rather than also doing completion) -(setq tab-always-indent t) - -;; Make return key also indent -(electric-indent-mode 1) - -;;------------------------------------------------------------------------------------- -;; Flycheck -;;------------------------------------------------------------------------------------- - -(add-hook 'after-init-hook #'global-flycheck-mode) -(with-eval-after-load 'flycheck - (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))) - -;;------------------------------------------------------------------------------------- -;; Projectile Configuration -;;------------------------------------------------------------------------------------- - -(projectile-global-mode) - -;;------------------------------------------------------------------------------------- -;; Neotree Configuration -;;------------------------------------------------------------------------------------- - -(setq neo-theme 'ascii) -(setq neo-vc-integration '(char)) -(setq neo-persist-show t) - -(add-hook 'neo-enter-hook 'redraw-display) - -;;------------------------------------------------------------------------------------- -;; 2 Space Region Indenting Functions -;;------------------------------------------------------------------------------------- - -(defun my-indent-region (N) - (interactive "p") - (if (use-region-p) - (progn (indent-rigidly (region-beginning) (region-end) (* N 2)) - (setq deactivate-mark nil)) - (self-insert-command N))) - -(defun my-unindent-region (N) - (interactive "p") - (if (use-region-p) - (progn (indent-rigidly (region-beginning) (region-end) (* N -2)) - (setq deactivate-mark nil)) - (self-insert-command N))) - -;;-------------------------------------------------------------------------------------- -;; CC-Mode Settings -;;------------------------------------------------------------------------------------- - -;; Keep character limit to 80 -(eval-after-load "c-mode" - '(progn - (setq whitespace-line-column 80))) - -(eval-after-load "c++-mode" - '(progn - (setq whitespace-line-column 80))) - - -(setq-default c-basic-offset 2) ;; Default 2 spaces -(setq-default c++-basic-offset 4) ;; -(setq-default c-default-style "linux") ;; Use Linux code style -(setq-default c++-default-style "linux") ;; - -(add-hook 'c-mode-hook 'irony-mode) -(add-hook 'c++-mode-hook 'irony-mode) - -;; Backend for Company -(defun my-c-mode-hook () - (eval-after-load 'company - '(add-to-list 'company-backends 'company-irony))) - -(defun my-c++-mode-hook () - (eval-after-load 'company - '(add-to-list 'company-backends 'company-irony))) - -(add-hook 'c-mode-hook 'my-c-mode-hook) -(add-hook 'c++-mode-hook 'my-c++-mode-hook) - -;; I use meson mostly for C/C++ development so this hook lives here -(add-hook 'meson-mode-hook 'company-mode) - -;;-------------------------------------------------------------------------------------- -;; Java Mode Setup -;;------------------------------------------------------------------------------------- - -(defun my-java-mode-hook () - (require 'eclim) - (eclim-mode t) - (require 'company-emacs-eclim) - (company-emacs-eclim-setup) - ) - -(eval-after-load "java-mode" - '(progn - setq whitespace-line-column 120)) -(add-hook 'java-mode-hook 'my-java-mode-hook) - -;;------------------------------------------------------------------------------------- -;; General Editor Utility -;;------------------------------------------------------------------------------------- - -(autopair-global-mode) - -;;------------------------------------------------------------------------------------- -;; Key Bindings -;;------------------------------------------------------------------------------------- - -;; Try to force alt to be the meta key -(setq x-alt-keysym 'meta) - -;; Neotree -(global-set-key [f8] 'neotree-toggle) - -(global-set-key (kbd "C-d") 'delete-char) -(global-set-key (kbd "C-m") nil) -(global-set-key (kbd "RET") nil) - -;; Unbind C-s from Isearch to make room for swiper -(global-set-key (kbd "C-s") nil) - -(global-set-key (kbd "C-x C-b") nil) - -(global-set-key (kbd "C-x C-f") nil) - -(global-set-key (kbd "C-h C-k") nil) - -;; Pane navigation -;; Adjusted 8/4/2019 to move to arrow keys -;; Vim is good for Vim but since there is no stigma to arrow -;; keys in Emacs, why not use them? -(global-set-key (kbd "M-") 'windmove-left) -(global-set-key (kbd "M-") 'windmove-down) -(global-set-key (kbd "M-") 'windmove-up) -(global-set-key (kbd "M-") 'windmove-right) - -;; Git utility -(global-set-key (kbd "C-x g s") 'magit-status) -(global-set-key (kbd "C-x g b") 'magit-blame-popup) -(global-set-key (kbd "C-x g p") 'magit-dispatch-popup) -(global-set-key (kbd "C-x g f") 'magit-file-popup) - -;; Fix RET -(global-set-key (kbd "RET") 'newline-and-indent) - -;; Ivy Bindings -(global-set-key (kbd "C-x C-f") 'counsel-find-file) - -;; Swiper -(global-set-key (kbd "C-s") 'swiper) - -;; Better M-x -;;(global-set-key (kbd "M-x") 'counsel-M-x) - -;; IBuffer -(global-set-key (kbd "C-x C-b") 'ibuffer) - -;; Line number toggle -(global-set-key [f9] 'linum-mode) - -;; Expand region -(global-set-key (kbd "C-h C-k") 'er/expand-region) - -;; Org mode specific keybinds -(global-set-key (kbd "C-c l") 'org-store-link) -(global-set-key (kbd "C-c a") 'org-agenda) - -;; More convenient region indenting -(global-set-key (kbd "M->") 'my-indent-region) -(global-set-key (kbd "M-<") 'my-unindent-region) - -;;-------------------------------------------------------------------------------------- -;; Theme +;; Install and load Packages ;;-------------------------------------------------------------------------------------- -(set-frame-parameter nil 'background-mode 'dark) -(set-terminal-parameter nil 'background-mode 'dark) -(load-theme 'material t) - -;; 12 pt font -(set-frame-font "inconsolata") -(set-face-attribute 'default nil :height 120) - -(powerline-center-theme) - - - - - - - - - - - +(load-file "~/.emacs.d/package.el") (custom-set-variables @@ -508,10 +184,19 @@ ;; If there is more than one, they won't work right. '(package-selected-packages (quote - (counsel material-theme wrap-region swiper stylus-mode smex slim-mode scss-mode sass-mode rust-mode rspec-mode robe rainbow-delimiters projectile powerline paredit neotree magit livescript-mode linum-relative less-css-mode jsx-mode js2-mode jade-mode grizzl golden-ratio gitignore-mode flymake-ruby flycheck-rust flycheck-pos-tip flycheck-haskell flycheck-clojure fill-column-indicator feature-mode expand-region esh-help enh-ruby-mode coffee-mode circe ag ac-inf-ruby)))) + (projectile smex grizzl flycheck-pos-tip flycheck material-theme expand-region wrap-region rainbow-delimiters powerline linum-relative golden-ratio fill-column-indicator autopair exec-path-from-shell ws-butler yaml-mode python-mode protobuf-mode paredit nasm-mode meson-mode markdown-mode magit gradle-mode gitignore-mode feature-mode counsel company-jedi jedi-core company-emacs-eclim company-irony company ag))) + + ;; Not technically a mode but mode enough. This forces emacs to ident common lisp + ;; like common lisp instead of like emacs lisp, which has unlimited else clauses in + ;; the if statement (implicit progn) and as such indents it funny. + '(lisp-indent-function 'common-lisp-indent-function)) + (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) + +;; Autoload the indent function +(autoload 'common-lisp-indent-function "cl-indent" "Common Lisp indent.") diff --git a/dotfiles/emacs.d/package.el b/dotfiles/emacs.d/package.el index 65bb9ae..d48f4a5 100644 --- a/dotfiles/emacs.d/package.el +++ b/dotfiles/emacs.d/package.el @@ -35,10 +35,6 @@ yaml-mode ;;;;;;;;;;;;;;;;;;;; - ;; Navigation - neotree - ;;;;;;;;;;;;; - ;; Cleanup ws-butler ;;;;;;;;;; @@ -49,6 +45,9 @@ ;; Editing Utility autopair + + ;; Keeps things indented even when you don't want it to + aggressive-indent ;;;;;;;;;;;;;;;;;; ;; UI @@ -57,7 +56,6 @@ linum-relative powerline rainbow-delimiters - zenburn-theme wrap-region expand-region wrap-region @@ -89,7 +87,3 @@ (package-install p)))) - - - -