Created
February 20, 2020 05:54
-
-
Save etscrivner/d8b8e9fbb938d0b0d472959a3e66b8db to your computer and use it in GitHub Desktop.
Emacs dotfiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; init.el --- The emacs configuration entry-point | |
;;; | |
;;; Commentary: | |
;;; This is the first file executed when emacs is initialized. | |
;;; | |
;;; Code: | |
;; Determine our dotfiles directory | |
(defun get-dotfiles-directory () | |
"Returns the directory the Emacs dotfiles are in." | |
(file-name-directory (or (buffer-file-name) load-file-name))) | |
;; Helper method to be used to add other directories to load path | |
(defun add-recursively-to-load-path (root-dir dotfiles-dir) | |
"Add the given ROOT-DIR and all of its subdirectories to the | |
load path. ROOT-DIR should be a subdirectory of the | |
DOTFILES-DIR." | |
(let ((expanded-dir (expand-file-name root-dir dotfiles-dir))) | |
(add-to-list 'load-path expanded-dir) | |
(dolist (project (directory-files expanded-dir t "\\w+")) | |
(when (file-directory-p project) | |
(add-to-list 'load-path project))))) | |
;; Add third-party emacs packages and our own custom lisp directories | |
(let ((dotfiles-dir (get-dotfiles-directory))) | |
(add-recursively-to-load-path "third-party" dotfiles-dir) | |
(add-recursively-to-load-path "setup" dotfiles-dir)) | |
;; Kick-off overall setup | |
(require 'setup-packages) | |
(require 'setup-emacs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; setup-emacs.el -- Configure overall emacs setup. | |
;;; | |
;;; Commentary: | |
;;; Calls other setup and configuration scripts to provide the | |
;;; overall emacs setup. | |
;;; | |
;;; Code: | |
;; Get rid of bars of any kind, we don't need 'em | |
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1)) | |
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) | |
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) | |
;; Start the emacsclient server | |
(require 'server) | |
(unless (server-running-p) | |
(server-start)) | |
;; Get rid of the welcome screen | |
(setq inhibit-startup-message t) | |
;; One letter yes-or-no prompts | |
(defalias 'yes-or-no-p 'y-or-n-p) | |
;; Show line numbers next to lines | |
;; (global-linum-mode -1) | |
;; Highlight the current line | |
(global-hl-line-mode 1) | |
;; Interactive do mode | |
(ido-mode t) | |
;; Hide the fringes | |
(fringe-mode -1) | |
;; Show us the time | |
(display-time) | |
;; Don't blink that cursor | |
(blink-cursor-mode -1) | |
;; Overwrite selection when cutting and pasting | |
(delete-selection-mode 1) | |
;; Set the default fill column at 79 characters (not 72) | |
(setq-default fill-column 79) | |
;; Add some space to the right of the line numbers displayed | |
(defadvice linum-update-window (around linum-dynamic activate) | |
"Customize line-number formatting." | |
(let* ((w (length (number-to-string | |
(count-lines (point-min) (point-max))))) | |
(linum-format (concat "%" (number-to-string w) "d "))) | |
ad-do-it)) | |
;; Show line and column numbers in gutter | |
(setq line-number-mode t) | |
(setq column-number-mode t) | |
;; Show how big the file is in the gutter | |
(size-indication-mode t) | |
;; Show trailing whitespace at the end of a line (highlights in red by | |
;; default) | |
(setq show-trailing-whitespace t) | |
;; Never insert tabs | |
(set-default 'indent-tabs-mode nil) | |
;; Show matching parens | |
(show-paren-mode 1) | |
;; Uniquify buffer names if we have two files with same name open | |
(require 'uniquify) | |
(setq uniquify-buffer-name-style 'forward) | |
;; Automatically reload buffers that have changed on disk | |
(global-auto-revert-mode t) | |
;; Electric pair mode | |
(electric-pair-mode 1) | |
;; UTF-8 everywhere | |
(setq locale-encoding-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) | |
;; Set up a decent, basic color scheme (use customize-themes to find | |
;; new one) | |
;; (custom-set-variables | |
;; '(custom-enabled-themes (quote (wombat)))) | |
;; (require 'twilight-bright-theme) | |
;; (load-theme 'twilight-bright t) | |
(require 'doom-modeline) | |
(doom-modeline-mode 1) | |
(require 'doom-themes) | |
;; (load-theme 'doom-one t) | |
;; (load-theme 'doom-vibrant t) | |
;; (load-theme 'doom-nova t) | |
;; (load-theme 'doom-moonlight t) | |
;; (load-theme 'doom-snazzy t) | |
;; (load-theme 'doom-molokai t) | |
;; (load-theme 'doom-city-lights t) | |
;; (load-theme 'doom-sourcerer t) | |
(load-theme 'doom-nord t) | |
;; (load-theme 'doom-solarized-dark t) | |
;; Bump up the font size a bit and use a prettier fac | |
(when (display-graphic-p) | |
(cond ((member "Hack" (font-family-list)) | |
(set-face-attribute 'default nil :height 120 :font "Hack")) | |
(t (set-face-attribute 'default nil :height 120)))) | |
(set-face-attribute 'default nil :height 120 :font "Liberation Mono") | |
;; (when (display-graphic-p) | |
;; (cond ((member "Monoid" (font-family-list)) | |
;; (set-face-attribute 'default nil :height 120 :font "Monoid")) | |
;; ((member "Inconsolata" (font-family-list)) | |
;; (set-face-attribute 'default nil :height 120 :font "Inconsolata")) | |
;; ((member "ProggyCleanTTSZ" (font-family-list)) | |
;; (set-face-attribute 'default nil :height 180 :font "ProggyCleanTTSZ")) | |
;; ((member "Hack" (font-family-list)) | |
;; (set-face-attribute 'default nil :height 110 :font "Hack")) | |
;; (t (set-face-attribute 'default nil :height 180)))) | |
;; Handle backspace triggering help in terminal | |
(when (not (display-graphic-p)) | |
(normal-erase-is-backspace-mode 1)) | |
;; Score: gLives | |
;; Customize hl-line-mode coloring. This needs to come after | |
;; configuring theming as some themes override these settings. | |
;; (set-face-foreground 'highlight nil) | |
;; (set-face-background 'highlight "#333") | |
;; (set-face-underline 'highlight nil) | |
(set-face-background 'hl-line "#555") | |
;; (Un)comment region | |
(global-set-key (kbd "C-c u c") 'comment-region) | |
(global-set-key (kbd "C-c u u") 'uncomment-region) | |
;; Bind key for replacing a rectangle | |
(global-set-key (kbd "C-c u r") 'replace-rectangle) | |
;; Custom highlight keywords | |
(require 'hl-todo) | |
(add-to-list 'hl-todo-keyword-faces '("Improvement" . "#cc9393")) | |
;; Duplicate whole line | |
(global-set-key (kbd "C-c C-d") (kbd "C-a C-SPC C-n M-w C-y C-p C-e")) | |
;; Semantic mode | |
(require 'semantic/db) | |
;; Flycheck | |
;; (require 'flycheck) | |
;; (add-hook 'after-init-hook #'global-flycheck-mode) | |
;; perspective-el | |
(require 'perspective) | |
(persp-mode) | |
;; Ivy | |
(require 'ivy) | |
(require 'counsel) | |
(ivy-mode 1) | |
(counsel-mode 1) | |
(setq ivy-use-virtual-buffers t) | |
(setq enable-recursive-minibuffers t) | |
(global-set-key (kbd "C-c h o") 'swiper) | |
(global-set-key (kbd "C-c h i") 'counsel-semantic-or-imenu) | |
(global-set-key (kbd "C-c h b") 'ivy-switch-buffer) | |
;; Projectile mode | |
(projectile-global-mode) | |
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map) | |
(setq projectile-completion-system 'ivy) | |
;; Add Go to PATH | |
(setq exec-path (append exec-path '("/usr/local/go/bin" "/usr/local/bin"))) | |
(require 'hl-todo) | |
(global-hl-todo-mode 1) | |
;; Faster recompilation of files | |
(global-set-key (kbd "C-c b c") 'compile) | |
(global-set-key (kbd "C-c b b") 'recompile) | |
(global-set-key (kbd "C-M-<backspace>") (lambda () | |
(interactive) | |
(kill-line 0) | |
(indent-according-to-mode))) | |
;; C stuff | |
(defun custom-c-mode-setup () | |
(progn | |
(setq c-default-style "linux" | |
c-basic-offset 2 | |
open-parens-in-column-0-is-defun-start nil | |
open-paren-in-column-0-is-defun-start nil) | |
(c-set-offset 'defun-open 0) | |
(c-set-offset 'defun-block-intro 2) | |
(c-set-offset 'block-open 0) | |
(c-set-offset 'substatement-open 0) | |
(c-set-offset 'brace-list-intro 2) | |
(c-set-offset 'arglist-intro 2) | |
(c-set-offset 'arglist-close 0))) ;; NOTE: These variables tell Emacs to scan backwards through the whole buffer for parens rather than using heuristics which seem broken. | |
(add-hook 'c-mode-hook 'custom-c-mode-setup) | |
(add-hook 'c++-mode-hook 'custom-c-mode-setup) | |
;; Fix projectile | |
(setq projectile-indexing-method 'native) | |
;; Number windows | |
(require 'winum) | |
(winum-mode) | |
;; Allow for toggling the transparency of the window | |
(defun toggle-transparency () | |
(interactive) | |
(let ((alpha (frame-parameter nil 'alpha))) | |
(set-frame-parameter | |
nil 'alpha | |
(if (eql (cond ((numberp alpha) alpha) | |
((numberp (cdr alpha)) (cdr alpha)) | |
;; Also handle undocumented (<active> <inactive>) form. | |
((numberp (cadr alpha)) (cadr alpha))) | |
100) | |
'(95 . 95) '(100 . 100))))) | |
(global-set-key (kbd "C-c t") 'toggle-transparency) | |
;; Ace window | |
(global-set-key (kbd "C-c w") 'ace-window) | |
;;(require 'crosshairs) | |
;; doom-nova color scheme | |
;; (set-face-attribute 'col-highlight nil :background "#556873") | |
;; LSP | |
;; (require 'yasnippet) | |
;; (yas-global-mode t) | |
;;(require 'lsp) | |
;;(add-hook 'c-mode-hook #'lsp-deferred) | |
;; (add-hook 'c++-mode-hook #'lsp-deferred) | |
;; (setq lsp-ui-sideline-ignore-duplicate t) | |
;; (add-hook 'lsp-mode-hook 'lsp-ui-mode) | |
;; Fix issues with perspective and lsp-ui | |
;; (add-hook 'lsp-mode-hook | |
;; (lambda () | |
;; (when (featurep 'perspective) | |
;; (ad-deactivate 'set-window-buffer)))) | |
;; (global-set-key (kbd "C-M-i") 'lsp-ui-peek-find-references) | |
;; (require 'company-lsp) | |
;; (push 'company-lsp company-backends) | |
;; (setq company-dabbrev-downcase 0) | |
;; (setq company-idle-delay 0) | |
;; Fix splitting windows on compile? | |
(defun my-compilation-hook () | |
(when (not (get-buffer-window "*compilation*")) | |
;;(save-selected-window | |
(save-excursion | |
(let* ((w (split-window-horizontally)) | |
(h (window-height w))) | |
(select-window w) | |
(switch-to-buffer "*compilation*"))))) | |
;; (add-to-list 'same-window-buffer-names "*compilation*") | |
;; | |
;; Magit | |
;; | |
(global-set-key (kbd "C-c m s") 'magit-status) | |
(global-set-key (kbd "C-c m l") 'magit-log) | |
;; | |
;; Expansion | |
;; | |
(global-set-key (kbd "M-/") (make-hippie-expand-function | |
'(try-expand-dabbrev-visible | |
try-expand-dabbrev | |
try-expand-dabbrev-all-buffers) t)) | |
(provide 'setup-emacs) | |
;;; setup-emacs.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; setup-packages.el --- Setup for emacs package system | |
;;; | |
;;; Commentary: | |
;;; Here we provide additional package archives and automatically install | |
;;; any missing required packages. | |
;;; | |
(require 'package) | |
;;; Code: | |
;;; These are the packages we'd like installed by default | |
(defvar default-package-list | |
'(flycheck | |
ivy | |
projectile | |
perspective)) | |
;;; Add additional package archives (try to use stable ones) | |
(add-to-list 'package-archives | |
'("melpa" . "https://melpa.org/packages/") t) | |
(add-to-list 'package-archives | |
'("melpa-stable" . "https://stable.melpa.org/packages/") t) | |
;;; Handle older versions of emacs | |
(when (< emacs-major-version 24) | |
;; For important compatibility libraries like cl-lib | |
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))) | |
;;; Initialize the package management system | |
(package-initialize) | |
;;; Install any missing packages | |
(dolist (package default-package-list) | |
(unless (package-installed-p package) | |
(package-install package))) | |
(provide 'setup-packages) | |
;;; setup-packages.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment