Skip to content

Instantly share code, notes, and snippets.

@adisbladis
Created October 20, 2016 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adisbladis/162332627fb0885bb013126aa009781a to your computer and use it in GitHub Desktop.
Save adisbladis/162332627fb0885bb013126aa009781a to your computer and use it in GitHub Desktop.
adisbladis emacs config

Adisbladis emacs configuration

Bootstrap this configuration

This configuration is designed to follow the XDG guidelines. This means that I configure locations for files of quite a lot of things.

To use this configuration of Emacs, save this file in ~/.config/emacs/config.org. You can download the file here.

This is a minimal bootstrap which should live in ~/.emacs:

;; Define XDG directories
(setq-default user-emacs-config-directory
              (concat (getenv "HOME") "/.config/emacs"))
(setq-default user-emacs-data-directory
              (concat (getenv "HOME") "/.local/share/emacs"))
(setq-default user-emacs-cache-directory
              (concat (getenv "HOME") "/.cache/emacs"))

;; Load config
(org-babel-load-file (concat user-emacs-config-directory "/config.org"))

Emacs initialization

Add package sources and initialize the package manager

Set up package sources with HTTPS, specify where to store packages and initialize the package management.

(setq-default package-archives
              '(("gnu" . "https://elpa.gnu.org/packages/")
                ("melpa" . "https://melpa.org/packages/")))

(setq-default package-user-dir (concat user-emacs-cache-directory "/elpa"))

(package-initialize)

Install use-package if missing

(unless (package-installed-p 'use-package)
  (progn
    (package-refresh-contents)
    (package-install 'use-package)))

(require 'use-package)

General configuration

Backup Files

Unless the $XGD_DATA_DIR/emacs/backup directory exists, create it. Then set as backup directory.

(let ((backup-dir (concat user-emacs-data-directory "/backup")))
  (unless (file-directory-p backup-dir)
    (mkdir backup-dir t))

  (setq-default backup-directory-alist (cons (cons "." backup-dir) nil)))

Lock-files

Disable creation of lock-files named .#<filename>.

(setq-default create-lockfiles nil)

Theme

(use-package lush-theme
  :ensure t
  :config
  (progn
    (load-theme 'lush t)
    (menu-bar-mode -1)
    (tool-bar-mode -1)
    (scroll-bar-mode -1)))
(add-to-list 'default-frame-alist '(font . "Inconsolata 12"))

Basic code style

(setq c-basic-indent 4)
(setq indent-line-function 'insert-tab)
(setq indent-tabs-mode nil)
(setq tab-stop-list '(4 8 12 16 20 24 28 32))
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)

Language modes

Python mode

(use-package jedi
  :ensure t
  :config
  (progn
    (add-hook 'python-mode-hook 'jedi:setup)
    (setq-default jedi:setup-keys t)
    (setq-default jedi:complete-on-dot t)))

Fish shell mode

(use-package fish-mode :ensure t)

Go mode

(use-package go-mode
  :ensure t
  :config
  (progn
    (add-hook 'before-save-hook 'gofmt-before-save)))

Web Mode

Install web-mode, set rules for filetypes and indent.

(use-package web-mode
  :ensure t
  :mode "\\.html\\'"
  :config
  (progn
    (setq-default web-mode-markup-indent-offset 4) ; HTML
    (setq-default web-mode-css-indent-offset 4)    ; CSS
    (setq-default web-mode-code-indent-offset 4))) ; JS/PHP/etc

Utilities

Git frontend

Install magit, bind C-x g to display the main magit popup and bind C-x M-g to display a magit popup with keybinds used in magit.

(use-package magit
  :ensure t
  :bind (("C-x g" . magit-status)     ; Display the main magit popup
         ("C-x M-g" . magit-dispatch-popup))) ; Display keybinds for magit

Autocomplete

(use-package company
  :ensure t
  :bind ("<backtab>" . company-complete)
  :config
  (progn
    ;; TODO: Keybind company-complete to something good
    (setq-default company-tooltip-minimum-width 15)

    (setq-default company-idle-delay 0.1)

    (global-company-mode)))

Fuzzy Matching

(use-package company-flx
  :ensure t
  :config
  (progn
    (with-eval-after-load 'company
      (company-flx-mode +1))))

Statistics for completions

(use-package company-statistics
  :ensure t
  :config
  (progn
    (setq-default company-statistics-file
                  (concat user-emacs-data-directory
                          "/company-statistics.dat"))
    (company-statistics-mode)))

go

Utilizes the program gocode as backend. Available in AUR as gocode-git.

(use-package company-go
  :ensure t
  :config
  (progn
    (add-hook 'go-mode-hook
              (lambda ()
                (unless (executable-find "gocode")
                  (error "Program: gocode is missing"))

                (set (make-local-variable 'company-backends) '(company-go))
                (company-mode t)))))

Fast file search

Install ag, frontend for ag - the_silver_searcher.

(use-package ag :ensure t)

Flexible ido matching

Load ido-mode with flx for flexible matching. Also move the history file to $XGD_DATA_DIR/emacs/ido.dat.

(use-package flx-ido
  :ensure t
  :config
  (progn
    ;; Flexible matching
    (setq-default ido-enable-flex-matching t)

    ;; Load ido-mode
    (ido-mode 1)
    (ido-everywhere 1)
    (flx-ido-mode 1)

    ;; History file
    (setq-default ido-save-directory-list-file
                  (concat user-emacs-data-directory "/ido.dat"))

    ;; Always open files in current frame
    (setq-default ido-default-file-method 'selected-window)

    ;; Always switch to buffers in current frame
    (setq-default ido-default-buffer-method 'selected-window)))
(ido-mode)

Smooth scrolling

This package makes Emacs scroll before cursor reach top or bottom which makes scrolling smoother.

(use-package smooth-scrolling
  :ensure t
  :config
  (progn
    (setq-default smooth-scroll-margin 2)))

Fancy search

(use-package swiper
  :ensure t
  :bind (("C-s" . swiper)
         ("C-r" . swiper))
  :config
  (progn
    (setq-default ivy-use-virtual-buffers t)))

Markdown

Handy when editing markdown.

(use-package markdown-mode :ensure t)

YAML

Handy when editing YAML/YML.

(use-package yaml-mode :ensure t)

webpaste

Paste whole buffers or parts of buffers to the internet.

(use-package webpaste
  :ensure t
  :bind (("C-c C-p C-b" . webpaste-paste-buffer)
         ("C-c C-p C-r" . webpaste-paste-region)))

Smart-mode-line

(use-package smart-mode-line
  :ensure t
  :config
  (progn
    (sml/setup)))

Flycheck

(use-package flycheck
  :ensure t
  :config
  (progn
    (global-flycheck-mode)))

Useless utilities

Nyan-mode

(use-package nyan-mode
  :ensure t
  :config
  (progn
      (nyan-mode)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment