You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

490 lines
17 KiB

;;--------------------------------------------------------------------------------------
;;
;; 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)
;;--------------------------------------------------------------------------------------
(menu-bar-mode -1)
;;--------------------------------------------------------------------------------------
;; Hide Startup Message
;;--------------------------------------------------------------------------------------
(setq inhibit-startup-message t)
;;--------------------------------------------------------------------------------------
;; Always follow symbolic links to version controlled files
;;
;; I prefer this option because I generally only get this message when I edit
;; a dotfile under version control, and repeatedly typing "yes" is annoying.
;;--------------------------------------------------------------------------------------
(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
;;--------------------------------------------------------------------------------------
(require 'org)
;; Stuff all of the org files you want under ~/org and they will be loaded automatically
;; and have their TODO items accessible by typing C-c a t
(setq org-agenda-files '("~/org"))
(setq org-log-done t)
;;--------------------------------------------------------------------------------------
;; Prefer unix style line endings
;;--------------------------------------------------------------------------------------
(set-buffer-file-coding-system 'unix)
;;--------------------------------------------------------------------------------------
;; Enable auto-refresh to keep buffers up to date when git or another program
;; modifies them
;;--------------------------------------------------------------------------------------
(global-auto-revert-mode t)
;;--------------------------------------------------------------------------------------
;; IBuffer configurations (C-x C-b)
;;--------------------------------------------------------------------------------------
(setq ibuffer-saved-filter-groups
'(("default"
("Emacs Configuration" (or (filename . ".emacs.d")
(filename . "init.el")
(filename . "package.el")
(filename . "private.el")
(filename . "emacs.d")))
("Org" (or (mode . org-mode)
(filename . "OrgMode")))
("Magit" (name . "magit"))
("Help" (or (name . "\*Help\*")
(name . "\*Apropos\*")
(name . "\*info\*")))
("Dired" (mode . dired-mode))
;; Dev has groups for all languages you program in
("Dev" (or (mode . cc-mode)
(filename . ".c")
(filename . ".cpp")
(filename . ".hpp")
(filename . ".h")
(filename . ".java")
(filename . ".properties")
(filename . ".gradle")
(filename . ".am")
(mode . yaml-mode))
)
("Text" (or (filename . ".csv")
(filename . ".tsv")
(filename . ".txt")
(filename . ".log")
(filename . ".json")))
("Emacs" (or (name . "^\\*scratch\\*$")
(name . "^\\*Messages\\*$")))
("Gnus" (or (mode . message-mode)
(mode . bbdb-mode)
(mode . mail-mode)
(mode . gnus-group-mode)
(mode . gnus-summary-mode)
(mode . gnus-article-mode)
(name . "^\\.bbdb$")
(name . "^\\.newsrc-dribble")))
)))
;; Automatically keep buffers up to date and load the filter
(add-hook 'ibuffer-mode-hook
'(lambda ()
(ibuffer-auto-mode 1)
(ibuffer-switch-to-saved-filter-groups "default")))
;; Disable eager line numbering
(add-hook 'ibuffer-mode-hook 'nolinum)
(setq ibuffer-expert t)
(setq ibuffer-show-empty-filter-groups nil)
;;--------------------------------------------------------------------------------------
;; Enable MELPA
;;--------------------------------------------------------------------------------------
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
;; This will force any out of date packages to update automatically
(when (not package-archive-contents)
(package-refresh-contents))
;;--------------------------------------------------------------------------------------
;; Install and load Packages
;;--------------------------------------------------------------------------------------
(load-file "~/.emacs.d/package.el")
;;--------------------------------------------------------------------------------------
;; Enable ParEdit for Emacs lisp modes
;;--------------------------------------------------------------------------------------
(autoload 'enable-paredit-mode "paredit" 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)))
;;--------------------------------------------------------------------------------------
;; Expand region settings
;;--------------------------------------------------------------------------------------
(require 'expand-region)
(pending-delete-mode t) ; Selected region contents are replaced on typing
;;--------------------------------------------------------------------------------------
;; Line Numbering - Note: Might not look good with files with 10,000 or more lines
;;--------------------------------------------------------------------------------------
;; NOTE: Line numbers are toggled with C-s n
(defvar linum-format)
(setq linum-format "%4d \u2502")
;; TODO: Figure out a way to make linum-relative keep the same linum-mode styles
;;--------------------------------------------------------------------------------------
;; Hook framemove into windmove for seamless window to frame transitions
;;--------------------------------------------------------------------------------------
(setq framemove-hook-into-windmove t)
;;--------------------------------------------------------------------------------------
;; 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)
;;-------------------------------------------------------------------------------------
;; 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 4) ;; NASA Style Guide says 4 spaces is optimal
(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)
)
(add-hook 'java-mode-hook 'my-java-mode-hook)
;;-------------------------------------------------------------------------------------
;; 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") nil)
(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-c r") nil)
(global-set-key (kbd "C-c n") nil)
(global-set-key (kbd "C-h C-k") nil)
;; Pane navigation
(global-set-key (kbd "M-h") 'windmove-left)
(global-set-key (kbd "M-j") 'windmove-down)
(global-set-key (kbd "M-k") 'windmove-up)
(global-set-key (kbd "M-l") 'windmove-right)
;; Delete surrounding
(global-set-key (kbd "C-d s") 'delete-pair)
;; 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 (kbd "C-c n") 'linum-mode)
;; Relative line numbering
(global-set-key (kbd "C-c r") 'linum-relative-toggle)
;; 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
;;--------------------------------------------------------------------------------------
(set-frame-parameter nil 'background-mode 'dark)
(set-terminal-parameter nil 'background-mode 'dark)
(load-theme 'material t)
;; 10 pt font
(set-frame-font "inconsolata")
(set-face-attribute 'default nil :height 100)
(powerline-center-theme)
(custom-set-variables
;; custom-set-variables 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.
'(package-selected-packages
(quote
(counsel zenburn-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))))
(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.
)