#+TITLE: Emacs Configuration #+HTML_HEAD: #+OPTIONS: html-style:nil * Startup ** Defaults #+BEGIN_SRC emacs-lisp (setq ;; Hide the default startup screen inhibit-startup-screen t ;; Define where to store recovery files backup-directory-alist '(("." . "~/.emacs.d/backups")) ;; Use version numbers for backups. version-control t ;; Number of newest versions to keep. kept-new-versions 10 ;; Number of oldest versions to keep. kept-old-versions 0 ;; Don't ask to delete excess backup versions. delete-old-versions -1 ;; Copy all files, don't rename them. backup-by-copying t ;; Make backups files under version control. vc-make-backup-files t ;; Don't confirm following when opening a symlink vc-follow-symlinks t) ;; Save minibuffer command history (savehist-mode +1) (setq savehist-save-minibuffer-history +1 savehist-file "~/.emacs.d/savehist") (setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring)) ;; Automatically close parens when opening them (electric-pair-mode 1) ;; Show matched parens (show-paren-mode t) ;; Let y and n be good enough for yes and no questions (fset 'yes-or-no-p 'y-or-n-p) ;; Auto-refresh files changed on the file system (global-auto-revert-mode 1) #+END_SRC Use UTF-8 as the default encoding #+BEGIN_SRC emacs-lisp (set-language-environment "UTF-8") (set-default-coding-systems 'utf-8) #+END_SRC I primarily use OSes that favor unix line endings, but occasionally I use Windows. This forces the buffers to be utf-8 with unix line endings by default. #+BEGIN_SRC emacs-lisp (setq default-buffer-file-coding-system 'utf-8-unix) #+END_SRC Transient-mark-mode makes a region active only when it is highlighted. Delete-selection-mode allows you to overwrite regions with what you're typing, pasting, etc. This mimics the behavior of other editors. #+BEGIN_SRC emacs-lisp (transient-mark-mode 1) (delete-selection-mode 1) #+END_SRC Trim trailing whitespace in my all of my files. If it turns out there is a filetype that should include trailing whitespace I will whitelist it. #+BEGIN_SRC emacs-lisp (add-hook 'write-file-hooks '(lambda () (delete-trailing-whitespace))) #+END_SRC ** Look and Feel #+BEGIN_SRC emacs-lisp ;; Hide the toolbar (tool-bar-mode -1) ;; Hide the scrollbar (scroll-bar-mode -1) ;; no beep (setq ring-bell-function 'ignore visible-bell nil) ;; display the full file path in the titlebar (setq frame-title-format (list (format "%s %%S: %%j " (system-name)) '(buffer-file-name "%f" (dired-directory dired-directory "%b")))) #+END_SRC Start Emacs full screen by default. #+BEGIN_SRC emacs-lisp (toggle-frame-maximized) #+END_SRC Winner mode tracks your window layouts so you can cycle between them with =C-c = and =C-c =. It is extra handy when some other mode ruins your current window layout. #+BEGIN_SRC emacs-lisp (winner-mode 1) #+END_SRC ** Local Elisp Code Add directories where I store elisp code to the load path #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/.emacs.d/local-lib/") #+END_SRC Include my custom functions #+BEGIN_SRC emacs-lisp (require 'zzq-funcs) #+END_SRC Usernames and passwords are stored in a non-published file #+BEGIN_SRC emacs-lisp (load "~/.emacs.d/secrets" t) #+END_SRC ** Keybindings By default Emacs binds ~C-x k~ to ~kill-buffer~ which asks for the buffer you want to close. 99.9% of the time I want to kill the buffer that is active so make that the default behavior #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-x k") 'kill-this-buffer) #+END_SRC ~ibuffer~ is a better buffer list utility so redefine the default buffer list to it. #+BEGIN_SRC emacs-lisp ;; Use ibuffer for the buffer list (global-set-key (kbd "C-x C-b") 'ibuffer) #+END_SRC * Package Initalization Define the package repositories #+BEGIN_SRC emacs-lisp (setq package-archives '( ("elpa" . "http://elpa.gnu.org/packages/") ("org" . "http://orgmode.org/elpa/") ;; melpa builds git repositories and can be unstable ("melpa" . "http://melpa.org/packages/") ;; marmalade has version uploaded by the maintainers ;; ("marmalade" . "https://marmalade-repo.org/packages/") ;; melpa-stable builds from git tags but may be missing dependencies ;; ("melpa-stable" . "https://stable.melpa.org/packages/") )) (package-initialize) #+END_SRC I use jweigly's [[https://github.com/jwiegley/use-package][use-package]] to manage packages so it needs to be installed. #+BEGIN_SRC emacs-lisp ;; Packages are managed by the use-package package, so we need to make sure it's installed (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (eval-when-compile (require 'use-package)) ;; slight optimization for use-package's :bind directive (require 'bind-key) #+END_SRC * Themes [[https://github.com/synic/jbeans-emacs][jbeans]] is a jellybeans.vim clone maintained by synic #+BEGIN_SRC emacs-lisp (require 'jbeans-theme) (load-theme 'jbeans t) #+END_SRC * Auto-completion I use [[https://company-mode.github.io/][company-mode]] for autocompletion. #+BEGIN_SRC emacs-lisp (use-package company :ensure t :init (setq ;; Display the suggestion popup quickly company-idle-delay 0.4 ;; Display the suggestion popup after 1 character company-minimum-prefix-length 1) :config (add-hook 'company-mode-hook '(lambda () (progn ;; I prefer to use TAB instead of RETURN to finish completion (define-key company-active-map [return] nil) (define-key company-active-map [tab] 'company-complete-selection))))) #+END_SRC [[https://github.com/expez/company-quickhelp][Company-quickhelp]] displays documentation in a popup next to the match list #+BEGIN_SRC emacs-lisp (use-package company-quickhelp :ensure t :config (add-hook 'company-mode-hook '(lambda () (progn (company-quickhelp-mode))))) #+END_SRC * Version Control Use [[https://magit.vc/][magit]] to supplement emacs built in version control system #+BEGIN_SRC emacs-lisp (use-package magit :ensure t :commands (magit-status magit-blame magit-log-buffer-file) :bind (("C-c v s" . magit-status) ("C-c v B" . magit-blame) ("C-c v L" . magit-log-buffer-file))) #+END_SRC * Packages ** Paradox [[https://github.com/Malabarba/paradox/][Paradox]] is a better emacs package manager. #+BEGIN_SRC emacs-lisp (use-package paradox :ensure t :config (paradox-enable)) #+END_SRC ** avy [[https://github.com/abo-abo/avy][avy]] is a quick way to jump around buffers #+BEGIN_SRC emacs-lisp (use-package avy :ensure t :bind (("C-:" . avy-goto-line))) #+END_SRC ** which-key [[https://github.com/justbur/emacs-which-key][which-key]] displays a pop up with key binding hints as you press them #+BEGIN_SRC emacs-lisp (use-package which-key :ensure t :diminish which-key-mode :init (setq which-key-special-keys nil which-key-use-C-h-commands t which-key-echo-keystrokes 0.02 which-key-max-description-length 32 which-key-sort-order 'which-key-key-order-alpha) :config (which-key-mode)) #+END_SRC ** ivy/swiper [[https://github.com/abo-abo/swiper][Ivy]], swiper, and counsel are a framework for autocompleting emacs things #+BEGIN_SRC emacs-lisp (use-package ivy :ensure t :pin elpa :diminish ivy-mode :bind (("C-s" . swiper) ("M-x" . counsel-M-x) ("C-x C-f" . counsel-find-file)) :init (setq ;; Remove the ^ prefix ivy-initial-inputs-alist nil ;; Display recently opened files when switching buffers ivy-use-virtual-buffers t ;; Use ivy for magit magit-completing-read-function 'ivy-completing-read ;; Use ivy for projectile projectile-completion-system 'ivy) :config (ivy-mode 1)) #+END_SRC ** persp-mode [[https://github.com/Bad-ptr/persp-mode.el][persp-mode]] enables "workspaces" within Emacs. This is similar to how a window manager might have several desktops #+BEGIN_SRC emacs-lisp (use-package persp-mode :ensure t :bind (([f8] . persp-switch)) :init (setq persp-nil-name "Home" persp-auto-resume-time 0) ;; Adding this so that capturing process is not interrupted with annoying ;; prompts "Kill and Close" etc. (setq persp-kill-foreign-buffer-action nil ;; increase the default name length persp-lighter '(:eval (format (propertize " #%.10s" 'face (let ((persp (get-current-persp))) (if persp (if (persp-contain-buffer-p (current-buffer) persp) 'persp-face-lighter-default 'persp-face-lighter-buffer-not-in-persp) 'persp-face-lighter-nil-persp))) (safe-persp-name (get-current-persp))))) :config ;; Set the persp-mode keymap prefix to , p (persp-set-keymap-prefix (kbd " p")) (persp-mode 1)) #+END_SRC ** powerline [[https://github.com/milkypostman/powerline][powerline]] is a prettier mode line for emacs #+BEGIN_SRC emacs-lisp (use-package powerline :ensure t :init (setq powerline-default-separator 'wave powerline-display-mule-info nil) :config (powerline-default-theme)) #+END_SRC ** projectile [[https://github.com/bbatsov/projectile][projectile]] adds some features around projects, for example finding only files that are in the current project (defined by a .git directory). #+BEGIN_SRC emacs-lisp (use-package projectile :ensure t :diminish projectile-mode :config (projectile-global-mode)) #+END_SRC ** elfeed [[https://github.com/skeeto/elfeed][Elfeed]] is an RSS reader for emacs #+BEGIN_SRC emacs-lisp (use-package elfeed :ensure t :bind ((" f" . elfeed)) :init (setq elfeed-db-directory "~/Shared/elfeeddb")) #+END_SRC [[https://github.com/remyhonig/elfeed-org][elfeed-org]] allows you to define your list of RSS feeds with an org file instead of an elisp list. #+BEGIN_SRC emacs-lisp (use-package elfeed-org :ensure t :init (setq rmh-elfeed-org-files (list "~/Shared/elfeed.org")) :config (elfeed-org)) #+END_SRC [[https://github.com/algernon/elfeed-goodies][elfeed-goodies]] adds some ui/ux sugar to the elfeed screen #+BEGIN_SRC emacs-lisp (use-package elfeed-goodies :ensure t :config (elfeed-goodies/setup)) #+END_SRC ** fill column indicator FCI-mode draws a pretty little line on the right hand side indicating where the fill column is. #+BEGIN_SRC emacs-lisp (use-package fill-column-indicator :ensure t :init (setq fci-rule-width 1 fci-rule-color "#202020") :config (add-hook 'prog-mode-hook 'fci-mode)) #+END_SRC * Languages ** Python Elpy does a great job of supporting Python so I just use that. #+BEGIN_SRC emacs-lisp (add-to-list 'package-archives '("elpy" . "http://jorgenschaefer.github.io/packages/")) (use-package elpy :ensure t :config (elpy-enable)) #+END_SRC ** Rust Installation: - Install Rust: https://www.rust-lang.org/en-US/install.html - Install Racer: https://github.com/racer-rust/racer - Install the Rust source: =rustup component add rust-src= This goes to: ~/.multirust/toolchains/[toolchain]/lib/rustlib/src/rust/src - Define the =RUST_SRC_PATH= environment var to the source directory #+BEGIN_SRC emacs-lisp (use-package rust-mode :ensure t :commands (rust-mode)) (use-package cargo :ensure t :commands (cargo-minor-mode)) (use-package racer :ensure t :commands (racer-mode)) (add-hook 'rust-mode-hook (lambda () (racer-mode) (cargo-minor-mode))) (add-hook 'racer-mode-hook #'company-mode) #+END_SRC * org-mode ** Setup Start org-indent-mode. This displays a single indented star instead of many stars in org-mode headings. #+BEGIN_SRC emacs-lisp (setq org-startup-indented t org-src-fontify-natively t) #+END_SRC ** Key Bindings Define the keybindings for org-mode related things | Key | Function | Description | |-----+------------+-----------------------------| | F12 | org-agenda | Display the org-agenda menu | #+BEGIN_SRC emacs-lisp (global-set-key (kbd "") 'org-agenda) #+END_SRC ** Agenda Rather than using ~C-[~ and ~C-]~ for adding files to the agenda manually this defines directories that include all org files in the agenda. #+BEGIN_SRC emacs-lisp (setq org-agenda-files '("~/org/")) #+END_SRC ** HTMLize Styles source code blocks when exporting an org file to HTML #+BEGIN_SRC emacs-lisp (use-package htmlize :ensure t) #+END_SRC