Skip to content

Latest commit

 

History

History
393 lines (317 loc) · 9.13 KB

emacs-config.org

File metadata and controls

393 lines (317 loc) · 9.13 KB

My Emacs configuration

Emacs Config

Initialization

(package-initialize)

Customize output file

I don’t want stuff added by Customize to show up in init.el.

(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  (when (file-exists-p custom-file)
     (load custom-file :noerror))

Add package repos

;; Adds melpa and org mode repos unless already defined
(unless (assoc-default "melpa" package-archives)
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t))
(unless (assoc-default "org" package-archives)
  (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t))

Use M-x package-refresh-contents to reload the list of packages after adding these for the first time.

Set up automatic package installation

(unless (package-installed-p 'use-package)
  (package-install 'use-package))
(setq use-package-verbose t)
(setq use-package-always-ensure t)
(require 'use-package)

;; Don't use outdated elisp bytecode
(use-package auto-compile
  :config (auto-compile-on-load-mode))
(setq load-prefer-newer t)

Config utility packages

(use-package bind-key) ;; Utility for rebinding stuff
(use-package diminish) ;; Allows use-package to hide minor modes from the modeline

General Configuration

(use-package better-defaults)

General Behavior

Splash Screen

Don’t display the “Welcome to Emacs” stuff

(setq inhibit-startup-screen t)

Backups

By default, Emacs saves backup files in the current directory. These are the files ending in ~ that are cluttering up your directory lists. The following code stashes them all in ~/.emacs.d/backups, where I can find them with C-x C-f (find-file) if I really need to.

(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))

Git

For all my git version control needs

(use-package magit)

Evil

A few settings to get things as Spacemacs-ey as possible.

(use-package evil
  :config (evil-mode))

(load-file "~/.emacs.d/lisp/evil-leader.el")
(load-file "~/.emacs.d/lisp/flycheck-xo.el")

(require 'evil-leader)
(global-evil-leader-mode)
(evil-leader/set-leader "<SPC>")
(evil-leader/set-key
  "p"   'projectile-command-map
  "f"   'helm-find-files
  "g"   'magit-status
  "bl"  'list-bookmarks
  "bs"  'bookmark-set
  "d"   (lambda ()
          (interactive)
          (find-file "~/.emacs.d/emacs-config.org"))

  "<tab>" 'switch-to-prev-buffer
  "<SPC>" 'helm-M-x
  )
(use-package spaceline-config
  :ensure spaceline
  :config
  (spaceline-spacemacs-theme)
  (setq spaceline-highlight-face-func 'spaceline-highlight-face-evil-state))

(use-package which-key
  :config (which-key-mode))

Projectile

For working in larger projects, and keeping track of all of ‘em.

(use-package projectile
    :config (projectile-mode +1))

(use-package helm-projectile)

The Silver Searcher

(use-package ag)

**** Speedbar

(use-package speedbar)
(use-package sr-speedbar)
(evil-leader/set-key
  "po" 'sr-speedbar-toggle
)

Helm

Helm makes it easy to complete various things.

(use-package helm
  :diminish helm-mode)
(helm-mode 1)

(global-set-key "\C-x\C-f" 'helm-find-files)
(global-set-key "\M-x" 'helm-M-x)
(setq helm-bookmark-show-location t)

(ido-mode -1) ;; Turn off ido mode in case I enabled it accidentally

Treemacs

(use-package treemacs)
(use-package treemacs-evil)
(use-package treemacs-projectile)

Abbrev mode

I don’t currently use Abbrev, so I disable it.

(abbrev-mode -1)

Delete trailing whitespace

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Change “yes or no” to “y or n”

Lazy people like me never want to type “yes” when “y” will suffice.

(fset 'yes-or-no-p 'y-or-n-p)

Line numbers

As of Emacs 26, linum-mode is deprecated, to be replaced with display-line-numbers-mode.

(when (< emacs-major-version 26)
  (global-linum-mode))

(when (>= emacs-major-version 26)
  (global-display-line-numbers-mode)
  (global-linum-mode -1))

Automatically follow symlinks

This is especially helpful when you use symlinks to manage your configuration files, as I do.

(setq vc-follow-symlinks t)

Appearance

Color scheme

(use-package jbeans-theme
  :config (load-theme 'jbeans t))

Again, you may have to launch an actual emacs instance in order to enable this theme for the first time.

Time in the modeline

(display-time-mode 1)

Indentation Blocks

I like seeing the indentation blocks, since I primarily develop in Python

(use-package highlight-indentation
  :init (highlight-indentation-mode))

Editing

SSH for CS241

(defun connect-remote ()
  (interactive)
  (dired "/ssh:[email protected]:/"))

Unfilling

It’s a little strange that you can’t readily undo M-x fill-paragraph. This command binds M-Q to be the inverse of M-q.

(defun my/unfill-paragraph (&optional region)
    "Takes a multi-line paragraph and makes it into a single line of text."
    (interactive (progn (barf-if-buffer-read-only) (list t)))
    (let ((fill-column (point-max))) (fill-paragraph nil region)))
(bind-key "M-Q" 'my/unfill-paragraph)

“Pair” programming

I like having paired parens, braces, and whatnot

(electric-pair-mode 1)
(setq electric-pair-preserve-balance nil)

LaTeX

(use-package tex-mode
  :ensure auctex)

Markdown

(use-package markdown-mode
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "multimarkdown"))

Flycheck

(use-package flycheck
  :init (add-hook 'prog-mode-hook 'flycheck-mode))

Company

Autocompletion framework for Emacs

(use-package company
  :init (add-hook 'prog-mode-hook 'company-mode)
  :config (setq company-tooltip-align-annotations t)
          (setq company-minimum-prefix-length 1))

Language Server Protocol (LSP)

(use-package lsp-mode)

(use-package lsp-ui
  :init (add-hook 'lsp-mode-hook 'lsp-ui-mode))

(use-package company-lsp
  :init (push 'company-lsp company-backends))

Bash

Arch Linux PKGBUILDS

A PKGBUILD should be treated like a shell script.

(add-to-list 'auto-mode-alist '("PKGBUILD\\'" . shell-script-mode))

TOML

(use-package toml-mode)

Rust

With rustup, run rustup update nightly and rustup component add rls-preview rust-analysis rust-src.

(use-package rust-mode)

(use-package flycheck-rust
  :init (with-eval-after-load 'rust-mode (add-hook 'flycheck-mode-hook 'flycheck-rust-setup)))

;;(use-package lsp-rust
;;  :config (setq lsp-rust-rls-command '("rustup" "run" "nightly" "rls"))
;;  :init (add-hook 'rust-mode-hook 'lsp-rust-enable))

MIPS

(use-package mips-mode
  :mode "\\.mips$")

Python

(use-package anaconda-mode
  :config (add-hook 'python-mode-hook 'anaconda-mode))

(use-package company-anaconda
  :requires company
  :config (add-to-list 'company-backends 'company-anaconda))

(use-package virtualenvwrapper)

;; Python only bindings
(evil-leader/set-key-for-mode 'python-mode
  "avw" 'venv-workon
  "avd" 'venv-deactivate
  )

JavaScript

(use-package js2-mode)
(use-package indium)
(use-package company-tern)
(use-package rjsx-mode)
(add-to-list 'company-backends 'company-tern)

Switch flycheck backend to xo

(require 'flycheck-xo)
(flycheck-xo-setup)
(defun shell-command-on-region-to-string (start end command)
  (with-output-to-string
    (shell-command-on-region start end command standard-output)))

(defun xo-fix-buffer ()
  (interactive)
  (number-to-register (point) 241)
  (call-shell-region
    (point-min) (point-max)
    (format "xo --stdin --fix --stdin-filename=%s" (buffer-file-name))
    t
    (current-buffer)
    )
  (goto-char (get-register 241))
  ()
)

(evil-leader/set-key-for-mode 'js2-mode
  "axf" 'xo-fix-buffer
  "x" 'xo-fix-buffer
)

C

(use-package cquery)
(setq cquery-executable "/bin/cquery")