refactor: Begin moving package configuration to use-package

This is the first in a series of commits for refactoring my
configuration to make use of jwiegley's use-package.

In the previous layout of the configuration there were some questions
around what settings go into which file, but in the end it is all just
related to which packages are being configured (besides settings
related to global Emacs behaviour).

This commit introduces use-package forms for all currently used
packages (which are still installed via Nix, not via package.el) but
does not yet clean up the rest of the configuration in a suitable way.

Note that this version introduces a bug in which the configuration of
telephone line is not correctly initialised after package setup.
This commit is contained in:
Vincent Ambo 2018-06-22 10:29:31 +02:00 committed by Vincent Ambo
parent f0dfc8b06d
commit 4fe8d78dbb
10 changed files with 218 additions and 216 deletions

147
init.el
View file

@ -3,11 +3,149 @@
;; Packages are installed via Nix configuration, this file only ;; Packages are installed via Nix configuration, this file only
;; initialises the newly loaded packages. ;; initialises the newly loaded packages.
(require 'package) (require 'use-package)
(require 'seq) (require 'seq)
(package-initialize) (package-initialize)
;; Add 'init' folder that contains other settings to load.
(add-to-list 'load-path (concat user-emacs-directory "init"))
;; Initialise all packages installed via Nix.
;;
;; TODO: Generate this section in Nix for all packages that do not
;; require special configuration.
;;
;; Packages providing generic functionality.
;;
(use-package ace-window
:bind (("C-x o" . ace-window))
:init
(progn (setq aw-keys '(?f ?j ?d ?k ?s ?l ?a)
aw-scope 'frame)
;; Show previews of ace-window numbers in the mode line for each window.
(ace-window-display-mode)))
(use-package adjust-parens :hook ((lisp-mode . adjust-parens-hook)))
(use-package auth-source-pass :init (auth-source-pass-enable))
(use-package avy
:bind (("M-j" . avy-goto-char)
("M-p" . avy-pop-mark)
("M-g g" . avy-goto-line)))
(use-package browse-kill-ring)
(use-package company
:hook ((prog-mode . company-mode))
:bind (:map rust-mode-map ("<tab>" . company-indent-or-complete-common)
:map lisp-mode-map ("<tab>" . company-indent-or-complete-common))
:init (setq company-tooltip-align-annotations t))
(use-package dash)
(use-package dash-functional)
(use-package edit-server :init (edit-server-start))
(use-package gruber-darker-theme)
(use-package ht)
(use-package hydra)
(use-package idle-highlight-mode :hook ((prog-mode . idle-highlight-mode)))
(use-package paredit :hook ((lisp-mode . paredit-mode)))
(use-package multiple-cursors)
(use-package pinentry
:init
(setq epa-pinentry-mode 'loopback)
(pinentry-start))
(use-package rainbow-delimiters :hook (prog-mode . rainbow-delimiters-mode))
(use-package rainbow-mode)
(use-package s)
(use-package smartparens :init (smartparens-global-mode))
(use-package string-edit)
(use-package telephone-line :init (telephone-line-setup))
(use-package undo-tree :init (global-undo-tree-mode))
(use-package uuidgen)
(use-package which-key :init (which-key-mode t))
;;
;; Applications in emacs
;;
(use-package magit
:bind ("C-c g" . magit-status)
:init (setq magit-repository-directories '(("/home/vincent/projects" . 2))))
(use-package multi-term
:bind ("C-x t" . counsel-switch-to-term)
:init (progn
;; term-mode's attempt to use isearch is not my favourite thing in the
;; world.
(delete '("C-r" . isearch-backward) term-bind-key-alist)
(delete '("C-s" . isearch-forward) term-bind-key-alist)
(add-to-list 'term-bind-key-alist '("C-r" . term-send-reverse-search-history))
(add-to-list 'term-bind-key-alist '("C-c C-l" . term-line-mode))
(add-to-list 'term-bind-key-alist '("C-s" . swiper))
(add-to-list 'term-bind-key-alist '("C-c C-r" . term-rename))))
(use-package password-store)
(use-package pg)
(use-package restclient)
;;
;; Packages providing language-specific functionality
;;
(use-package cargo :hook ((rust-mode . cargo-minor-mode)
(cargo-process-mode . visual-line-mode)))
(use-package dockerfile-mode)
(use-package eglot
:init (defvar rust-eglot-initialized nil)
:hook ((rust-mode . (lambda ()
(unless rust-eglot-initialized
(call-interactively #'eglot)
(setq rust-eglot-initialized t))))))
(use-package erlang
:hook ((erlang-mode . (lambda ()
;; Don't indent after '>' while I'm writing
(local-set-key ">" 'self-insert-command)))))
(use-package go-mode)
(use-package haskell-mode)
(use-package jq-mode
:init (add-to-list 'auto-mode-alist '("\\.jq\\'" . jq-mode)))
(use-package kotlin-mode)
(use-package markdown-mode
:init
(add-to-list 'auto-mode-alist '("\\.txt\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)))
(use-package markdown-toc)
(use-package nginx-mode)
(use-package rust-mode)
(use-package terraform-mode)
(use-package toml-mode)
(use-package web-mode)
(use-package yaml-mode)
;; (use-package sly
;; :init
;; (setq inferior-lisp-program (concat (nix-store-path "sbcl") "/bin/sbcl"))
;; (add-to-list 'company-backends 'sly-company))
;;
;; EXWM / NixOS related packages
;;
;; Configure a few basics before moving on to package-specific initialisation. ;; Configure a few basics before moving on to package-specific initialisation.
(setq custom-file (concat user-emacs-directory "init/custom.el")) (setq custom-file (concat user-emacs-directory "init/custom.el"))
(load custom-file) (load custom-file)
@ -18,9 +156,6 @@
;; Seed RNG ;; Seed RNG
(random t) (random t)
;; Add 'init' folder that contains other settings to load.
(add-to-list 'load-path (concat user-emacs-directory "init"))
;; Load configuration that makes use of installed packages: ;; Load configuration that makes use of installed packages:
;; Emacs will automatically initialise all installed packages. ;; Emacs will automatically initialise all installed packages.
@ -35,12 +170,8 @@
bindings bindings
term-setup term-setup
eshell-setup eshell-setup
haskell-setup
rust-setup
lisp-setup
))) )))
(add-hook 'after-init-hook 'load-other-settings) (add-hook 'after-init-hook 'load-other-settings)
(put 'narrow-to-region 'disabled nil) (put 'narrow-to-region 'disabled nil)
(edit-server-start)
(put 'upcase-region 'disabled nil) (put 'upcase-region 'disabled nil)

View file

@ -14,16 +14,9 @@
;; Counsel stuff: ;; Counsel stuff:
(global-set-key (kbd "C-c r g") 'counsel-rg) (global-set-key (kbd "C-c r g") 'counsel-rg)
;; Avy mode
(global-set-key (kbd "M-j") 'avy-goto-char)
(global-set-key (kbd "M-p") 'avy-pop-mark)
;; imenu instead of insert-file ;; imenu instead of insert-file
(global-set-key (kbd "C-x i") 'imenu) (global-set-key (kbd "C-x i") 'imenu)
(global-set-key (kbd "C-x o") ; Yes, I went there!
'ace-window)
;; Window switching. (C-x o goes to the next window) ;; Window switching. (C-x o goes to the next window)
(windmove-default-keybindings) ;; Shift+direction (windmove-default-keybindings) ;; Shift+direction
@ -33,12 +26,7 @@
;; Start a new eshell even if one is active. ;; Start a new eshell even if one is active.
(global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t))) (global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t)))
;; Magit!
(global-set-key (kbd "C-c g") 'magit-status)
(global-set-key (kbd "C-x p") 'ivy-browse-repositories) (global-set-key (kbd "C-x p") 'ivy-browse-repositories)
;; Replace standard goto-line with ace-jump-line-mode
(global-set-key (kbd "M-g g") 'avy-goto-line)
(global-set-key (kbd "M-g M-g") 'goto-line-with-feedback) (global-set-key (kbd "M-g M-g") 'goto-line-with-feedback)
(global-set-key (kbd "C-c w") 'whitespace-cleanup) (global-set-key (kbd "C-c w") 'whitespace-cleanup)

View file

@ -1,5 +0,0 @@
(require 'haskell-mode)
(add-hook 'haskell-mode-hook 'intero-mode)
(provide 'haskell-setup)

View file

@ -1,21 +0,0 @@
;; lisp-settings.el - settings for various Lisp dialects
;; -*- lexical-binding: t; -*-
(require 'adjust-parens)
(require 'sly)
;; All the lisps:
(add-to-list 'lisp-mode-hook #'company-mode)
(add-to-list 'lisp-mode-hook #'paredit-mode)
(add-to-list 'lisp-mode-hook #'adjust-parens-mode)
(define-key lisp-mode-map (kbd "TAB")
#'company-indent-or-complete-common)
;; Common Lisp:
(setq inferior-lisp-program (concat (nix-store-path "sbcl") "/bin/sbcl"))
(add-to-list 'company-backends 'sly-company)
(provide 'lisp-setup)

View file

@ -1,7 +1,5 @@
;;; -*- lexical-binding: t; -*- ;;; -*- lexical-binding: t; -*-
(require 'telephone-line)
;; Hide those ugly tool bars: ;; Hide those ugly tool bars:
(tool-bar-mode 0) (tool-bar-mode 0)
(scroll-bar-mode 0) (scroll-bar-mode 0)
@ -46,36 +44,37 @@
(when (bottom-right-window-p) (when (bottom-right-window-p)
(telephone-line-raw mode-line-misc-info t))) (telephone-line-raw mode-line-misc-info t)))
(telephone-line-defsegment telephone-line-last-window-segment () (defun telephone-line-setup ()
(telephone-line-defsegment telephone-line-last-window-segment ()
(telephone-misc-if-last-window)) (telephone-misc-if-last-window))
;; Display the current EXWM workspace index in the mode-line ;; Display the current EXWM workspace index in the mode-line
(telephone-line-defsegment telephone-line-exwm-workspace-index () (telephone-line-defsegment telephone-line-exwm-workspace-index ()
(when (bottom-right-window-p) (when (bottom-right-window-p)
(format "[%s]" exwm-workspace-current-index))) (format "[%s]" exwm-workspace-current-index)))
;; Define a highlight font for ~ important ~ information in the last ;; Define a highlight font for ~ important ~ information in the last
;; window. ;; window.
(defface special-highlight '((t (:foreground "white" :background "#5f627f"))) "") (defface special-highlight '((t (:foreground "white" :background "#5f627f"))) "")
(add-to-list 'telephone-line-faces (add-to-list 'telephone-line-faces
'(highlight . (special-highlight . special-highlight))) '(highlight . (special-highlight . special-highlight)))
(setq telephone-line-lhs (setq telephone-line-lhs
'((nil . (telephone-line-position-segment)) '((nil . (telephone-line-position-segment))
(accent . (telephone-line-buffer-segment)))) (accent . (telephone-line-buffer-segment))))
(setq telephone-line-rhs (setq telephone-line-rhs
'((accent . (telephone-line-major-mode-segment)) '((accent . (telephone-line-major-mode-segment))
(nil . (telephone-line-last-window-segment (nil . (telephone-line-last-window-segment
telephone-line-exwm-workspace-index)) telephone-line-exwm-workspace-index))
(highlight . (telephone-line-notmuch-counts)))) (highlight . (telephone-line-notmuch-counts))))
(setq telephone-line-primary-left-separator 'telephone-line-tan-left (setq telephone-line-primary-left-separator 'telephone-line-tan-left
telephone-line-primary-right-separator 'telephone-line-tan-right telephone-line-primary-right-separator 'telephone-line-tan-right
telephone-line-secondary-left-separator 'telephone-line-tan-hollow-left telephone-line-secondary-left-separator 'telephone-line-tan-hollow-left
telephone-line-secondary-right-separator 'telephone-line-tan-hollow-right) telephone-line-secondary-right-separator 'telephone-line-tan-hollow-right)
(telephone-line-mode 1) (telephone-line-mode 1))
;; Auto refresh buffers ;; Auto refresh buffers
(global-auto-revert-mode 1) (global-auto-revert-mode 1)

View file

@ -1,14 +1,6 @@
;; Initializes modes I use. ;; Initializes modes I use.
(add-hook 'prog-mode-hook 'esk-add-watchwords) (add-hook 'prog-mode-hook 'esk-add-watchwords)
(add-hook 'prog-mode-hook 'idle-highlight-mode)
;; Configure markdown-mode
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.txt\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
;; Use auto-complete as completion at point ;; Use auto-complete as completion at point
(defun set-auto-complete-as-completion-at-point-function () (defun set-auto-complete-as-completion-at-point-function ()
@ -17,35 +9,18 @@
(add-hook 'auto-complete-mode-hook (add-hook 'auto-complete-mode-hook
'set-auto-complete-as-completion-at-point-function) 'set-auto-complete-as-completion-at-point-function)
;; Configure Erlang mode
(defun erlang-mode-init-setup ()
(interactive)
;; Don't indent after '>' while I'm writing
(local-set-key ">" 'self-insert-command)
;;(local-set-key "RET" 'newline)
(rainbow-delimiters-mode 1)
)
(add-hook 'erlang-mode-hook 'erlang-mode-init-setup)
;; Enable rainbow-delimiters for all things programming ;; Enable rainbow-delimiters for all things programming
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode) (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
;; Enable Paredit & Company in Emacs Lisp mode ;; Enable Paredit & Company in Emacs Lisp mode
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
(add-hook 'emacs-lisp-mode-hook 'company-mode) (add-hook 'emacs-lisp-mode-hook 'company-mode)
;; Always highlight matching brackets ;; Always highlight matching brackets
(show-paren-mode 1) (show-paren-mode 1)
;; Always auto-close parantheses and other pairs ;; Always auto-close parantheses and other pairs
(electric-pair-mode) ;; (replaced by smartparens)
;; (electric-pair-mode)
;; Represent undo-history as an actual tree (visualize with C-x u)
(setq undo-tree-mode-lighter "")
(require 'undo-tree)
(global-undo-tree-mode)
;; Keep track of recent files ;; Keep track of recent files
(recentf-mode) (recentf-mode)
@ -57,9 +32,5 @@
(auto-compression-mode t) (auto-compression-mode t)
;; Show available key chord completions ;; Show available key chord completions
(which-key-mode t)
;; Show previews of ace-window numbers in the mode line for each window.
(ace-window-display-mode)
(provide 'modes) (provide 'modes)

View file

@ -6,11 +6,6 @@
(require 'f) (require 'f)
(require 'dash) (require 'dash)
(defvar is-nixos
(let ((os-f "/etc/os-release"))
(s-contains?
"NixOS" (if (f-file? os-f) (f-read os-f)))))
(defun pulseaudio-ctl (cmd) (defun pulseaudio-ctl (cmd)
(shell-command (concat "pulseaudio-ctl " cmd)) (shell-command (concat "pulseaudio-ctl " cmd))
(message "Volume command: %s" cmd)) (message "Volume command: %s" cmd))
@ -38,19 +33,17 @@
(0 "eDP1") (0 "eDP1")
,(-map (lambda (n) (list n "eDP1")) (number-sequence 6 9))))) ,(-map (lambda (n) (list n "eDP1")) (number-sequence 6 9)))))
(if is-nixos (use-package exwm
:hook ((exwm-update-class . (lambda ()
;; Make class name the buffer name
(exwm-workspace-rename-buffer exwm-class-name))))
:init
(progn (progn
(message "Running on NixOS, configuring ExWM.")
(require 'exwm)
(require 'exwm-config) (require 'exwm-config)
(fringe-mode 3) (fringe-mode 3)
(setq exwm-workspace-number 10) (setq exwm-workspace-number 10)
;; Make class name the buffer name
(add-hook 'exwm-update-class-hook
(lambda ()
(exwm-workspace-rename-buffer exwm-class-name)))
;; 's-r': Reset ;; 's-r': Reset
(exwm-input-set-key (kbd "s-r") #'exwm-reset) (exwm-input-set-key (kbd "s-r") #'exwm-reset)

View file

@ -1,23 +0,0 @@
(require 'company)
(require 'eglot)
(require 'rust-mode)
;; LSP configuration:
(defvar rust-eglot-initialized nil)
(add-hook 'rust-mode-hook (lambda ()
(unless rust-eglot-initialized
(call-interactively #'eglot)
(setq rust-eglot-initialized t))))
;; Enable cargo-related (C-c C-c C-...) commands.
(add-hook 'rust-mode-hook #'cargo-minor-mode)
;; Configure autocompletion for rust
(add-hook 'rust-mode-hook #'company-mode)
(define-key rust-mode-map (kbd "TAB") #'company-indent-or-complete-common)
(setq company-tooltip-align-annotations t)
;; Ensure long compiler errors don't flow out of the screen (very annoying!)
(add-hook 'cargo-process-mode-hook #'visual-line-mode)
(provide 'rust-setup)

View file

@ -1,7 +1,6 @@
(require 'prescient) (require 'prescient)
(require 'ivy-prescient) (require 'ivy-prescient)
(require 'uniquify) (require 'uniquify)
(require 'password-store)
(require 'ivy-pass) (require 'ivy-pass)
;; Make ivy go! ;; Make ivy go!
@ -63,20 +62,4 @@
;; Show time in 24h format ;; Show time in 24h format
(setq display-time-24hr-format t) (setq display-time-24hr-format t)
;; Make ace-window behave in a sane way:
(setq aw-keys '(?f ?j ?d ?k ?s ?l ?a)) ; Homerow keys in sensible order!
(setq aw-scope 'frame) ; There are many frames in exwm, I don't care!
;; Configure pinentry for use with GPG
(setq epa-pinentry-mode 'loopback)
(pinentry-start)
;; Configure password-store as an auth-source
;; (this requires emacs 26)
(require 'auth-source-pass)
(auth-source-pass-enable)
;; Configure magit-repository-list
(setq magit-repository-directories '(("/home/vincent/projects" . 2)))
(provide 'settings) (provide 'settings)

View file

@ -1,6 +1,4 @@
;; Configuration for multi-term mode: ;; Utilities for term-mode
(require 'multi-term)
(defun open-or-create-term-buffer (buffer-name) (defun open-or-create-term-buffer (buffer-name)
"Switch to the buffer with BUFFER-NAME or create a "Switch to the buffer with BUFFER-NAME or create a
@ -31,16 +29,4 @@
(rename-buffer (format "*terminal<%s>*" (read-string "New terminal name: "))) (rename-buffer (format "*terminal<%s>*" (read-string "New terminal name: ")))
(error "This function is only intended to rename terminal buffers.")))) (error "This function is only intended to rename terminal buffers."))))
(global-set-key (kbd "C-x t") #'counsel-switch-to-term)
;; term-mode's attempt to use isearch is not my favourite thing in the
;; world.
(delete '("C-r" . isearch-backward) term-bind-key-alist)
(delete '("C-s" . isearch-forward) term-bind-key-alist)
(add-to-list 'term-bind-key-alist '("C-r" . term-send-reverse-search-history))
(add-to-list 'term-bind-key-alist '("C-c C-l" . term-line-mode))
(add-to-list 'term-bind-key-alist '("C-s" . swiper))
(add-to-list 'term-bind-key-alist '("C-c C-r" . term-rename))
(provide 'term-setup) (provide 'term-setup)