diff --git a/init.el b/init.el index b73eaccef..7a4af1060 100644 --- a/init.el +++ b/init.el @@ -3,11 +3,149 @@ ;; Packages are installed via Nix configuration, this file only ;; initialises the newly loaded packages. -(require 'package) +(require 'use-package) (require 'seq) (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 ("" . company-indent-or-complete-common) + :map lisp-mode-map ("" . 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. (setq custom-file (concat user-emacs-directory "init/custom.el")) (load custom-file) @@ -18,9 +156,6 @@ ;; Seed RNG (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: ;; Emacs will automatically initialise all installed packages. @@ -35,12 +170,8 @@ bindings term-setup eshell-setup - haskell-setup - rust-setup - lisp-setup ))) (add-hook 'after-init-hook 'load-other-settings) (put 'narrow-to-region 'disabled nil) -(edit-server-start) (put 'upcase-region 'disabled nil) diff --git a/init/bindings.el b/init/bindings.el index cb793f725..f10869a53 100644 --- a/init/bindings.el +++ b/init/bindings.el @@ -14,16 +14,9 @@ ;; Counsel stuff: (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 (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) (windmove-default-keybindings) ;; Shift+direction @@ -33,12 +26,7 @@ ;; Start a new eshell even if one is active. (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) - -;; 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 "C-c w") 'whitespace-cleanup) diff --git a/init/haskell-setup.el b/init/haskell-setup.el deleted file mode 100644 index 23de004cd..000000000 --- a/init/haskell-setup.el +++ /dev/null @@ -1,5 +0,0 @@ -(require 'haskell-mode) - -(add-hook 'haskell-mode-hook 'intero-mode) - -(provide 'haskell-setup) diff --git a/init/lisp-setup.el b/init/lisp-setup.el deleted file mode 100644 index e117817e3..000000000 --- a/init/lisp-setup.el +++ /dev/null @@ -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) diff --git a/init/look-and-feel.el b/init/look-and-feel.el index 555feca43..3d480bd5f 100644 --- a/init/look-and-feel.el +++ b/init/look-and-feel.el @@ -1,7 +1,5 @@ ;;; -*- lexical-binding: t; -*- -(require 'telephone-line) - ;; Hide those ugly tool bars: (tool-bar-mode 0) (scroll-bar-mode 0) @@ -46,36 +44,37 @@ (when (bottom-right-window-p) (telephone-line-raw mode-line-misc-info t))) -(telephone-line-defsegment telephone-line-last-window-segment () - (telephone-misc-if-last-window)) +(defun telephone-line-setup () + (telephone-line-defsegment telephone-line-last-window-segment () + (telephone-misc-if-last-window)) -;; Display the current EXWM workspace index in the mode-line -(telephone-line-defsegment telephone-line-exwm-workspace-index () - (when (bottom-right-window-p) - (format "[%s]" exwm-workspace-current-index))) + ;; Display the current EXWM workspace index in the mode-line + (telephone-line-defsegment telephone-line-exwm-workspace-index () + (when (bottom-right-window-p) + (format "[%s]" exwm-workspace-current-index))) -;; Define a highlight font for ~ important ~ information in the last -;; window. -(defface special-highlight '((t (:foreground "white" :background "#5f627f"))) "") -(add-to-list 'telephone-line-faces - '(highlight . (special-highlight . special-highlight))) + ;; Define a highlight font for ~ important ~ information in the last + ;; window. + (defface special-highlight '((t (:foreground "white" :background "#5f627f"))) "") + (add-to-list 'telephone-line-faces + '(highlight . (special-highlight . special-highlight))) -(setq telephone-line-lhs - '((nil . (telephone-line-position-segment)) - (accent . (telephone-line-buffer-segment)))) + (setq telephone-line-lhs + '((nil . (telephone-line-position-segment)) + (accent . (telephone-line-buffer-segment)))) -(setq telephone-line-rhs - '((accent . (telephone-line-major-mode-segment)) - (nil . (telephone-line-last-window-segment - telephone-line-exwm-workspace-index)) - (highlight . (telephone-line-notmuch-counts)))) + (setq telephone-line-rhs + '((accent . (telephone-line-major-mode-segment)) + (nil . (telephone-line-last-window-segment + telephone-line-exwm-workspace-index)) + (highlight . (telephone-line-notmuch-counts)))) -(setq telephone-line-primary-left-separator 'telephone-line-tan-left - telephone-line-primary-right-separator 'telephone-line-tan-right - telephone-line-secondary-left-separator 'telephone-line-tan-hollow-left - telephone-line-secondary-right-separator 'telephone-line-tan-hollow-right) + (setq telephone-line-primary-left-separator 'telephone-line-tan-left + telephone-line-primary-right-separator 'telephone-line-tan-right + telephone-line-secondary-left-separator 'telephone-line-tan-hollow-left + telephone-line-secondary-right-separator 'telephone-line-tan-hollow-right) -(telephone-line-mode 1) + (telephone-line-mode 1)) ;; Auto refresh buffers (global-auto-revert-mode 1) diff --git a/init/modes.el b/init/modes.el index d9a27c52a..19ed2a684 100644 --- a/init/modes.el +++ b/init/modes.el @@ -1,14 +1,6 @@ ;; Initializes modes I use. (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 (defun set-auto-complete-as-completion-at-point-function () @@ -17,35 +9,18 @@ (add-hook 'auto-complete-mode-hook '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 (add-hook 'prog-mode-hook 'rainbow-delimiters-mode) ;; Enable Paredit & Company in Emacs Lisp mode -(add-hook 'emacs-lisp-mode-hook 'paredit-mode) (add-hook 'emacs-lisp-mode-hook 'company-mode) ;; Always highlight matching brackets (show-paren-mode 1) ;; Always auto-close parantheses and other pairs -(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) +;; (replaced by smartparens) +;; (electric-pair-mode) ;; Keep track of recent files (recentf-mode) @@ -57,9 +32,5 @@ (auto-compression-mode t) ;; 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) diff --git a/init/nixos.el b/init/nixos.el index 431ba705c..f3cefea7f 100644 --- a/init/nixos.el +++ b/init/nixos.el @@ -6,11 +6,6 @@ (require 'f) (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) (shell-command (concat "pulseaudio-ctl " cmd)) (message "Volume command: %s" cmd)) @@ -38,70 +33,68 @@ (0 "eDP1") ,(-map (lambda (n) (list n "eDP1")) (number-sequence 6 9))))) -(if is-nixos - (progn - (message "Running on NixOS, configuring ExWM.") - (require 'exwm) - (require 'exwm-config) +(use-package exwm + :hook ((exwm-update-class . (lambda () + ;; Make class name the buffer name + (exwm-workspace-rename-buffer exwm-class-name)))) + :init + (progn + (require 'exwm-config) - (fringe-mode 3) + (fringe-mode 3) - (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))) + (setq exwm-workspace-number 10) - ;; 's-r': Reset - (exwm-input-set-key (kbd "s-r") #'exwm-reset) - ;; 's-w': Switch workspace - (exwm-input-set-key (kbd "s-w") #'exwm-workspace-switch) - ;; 's-N': Switch to certain workspace - (dotimes (i 10) - (exwm-input-set-key (kbd (format "s-%d" i)) - `(lambda () - (interactive) - (exwm-workspace-switch-create ,i)))) + ;; 's-r': Reset + (exwm-input-set-key (kbd "s-r") #'exwm-reset) + ;; 's-w': Switch workspace + (exwm-input-set-key (kbd "s-w") #'exwm-workspace-switch) + ;; 's-N': Switch to certain workspace + (dotimes (i 10) + (exwm-input-set-key (kbd (format "s-%d" i)) + `(lambda () + (interactive) + (exwm-workspace-switch-create ,i)))) - ;; Launch applications with completion (dmenu style!) - (exwm-input-set-key (kbd "s-d") #'ivy-run-external-command) - (exwm-input-set-key (kbd "s-p") #'ivy-password-store) - (exwm-input-set-key (kbd "C-s-p") '(lambda () - (interactive) - (ivy-password-store "~/.aprila-secrets"))) + ;; Launch applications with completion (dmenu style!) + (exwm-input-set-key (kbd "s-d") #'ivy-run-external-command) + (exwm-input-set-key (kbd "s-p") #'ivy-password-store) + (exwm-input-set-key (kbd "C-s-p") '(lambda () + (interactive) + (ivy-password-store "~/.aprila-secrets"))) - ;; Toggle between line-mode / char-mode - (exwm-input-set-key (kbd "C-c C-t C-t") #'exwm-input-toggle-keyboard) + ;; Toggle between line-mode / char-mode + (exwm-input-set-key (kbd "C-c C-t C-t") #'exwm-input-toggle-keyboard) - ;; Volume keys - (exwm-input-set-key (kbd "") #'volume-mute) - (exwm-input-set-key (kbd "") #'volume-up) - (exwm-input-set-key (kbd "") #'volume-down) + ;; Volume keys + (exwm-input-set-key (kbd "") #'volume-mute) + (exwm-input-set-key (kbd "") #'volume-up) + (exwm-input-set-key (kbd "") #'volume-down) - ;; Brightness keys - (exwm-input-set-key (kbd "") #'brightness-down) - (exwm-input-set-key (kbd "") #'brightness-up) - (exwm-input-set-key (kbd "") #'lock-screen) + ;; Brightness keys + (exwm-input-set-key (kbd "") #'brightness-down) + (exwm-input-set-key (kbd "") #'brightness-up) + (exwm-input-set-key (kbd "") #'lock-screen) - ;; Line-editing shortcuts - (exwm-input-set-simulation-keys - '(([?\C-d] . delete) - ([?\C-w] . ?\C-c))) + ;; Line-editing shortcuts + (exwm-input-set-simulation-keys + '(([?\C-d] . delete) + ([?\C-w] . ?\C-c))) - ;; Enable EXWM - (exwm-enable) + ;; Enable EXWM + (exwm-enable) - ;; Show time in the mode line - (display-time-mode) + ;; Show time in the mode line + (display-time-mode) - ;; Configure xrandr when running on laptop - (when (equal (shell-command-to-string "hostname") "adho\n") - (require 'exwm-randr) - (setq exwm-randr-workspace-output-plist (generate-randr-config)) - (exwm-randr-enable)) + ;; Configure xrandr when running on laptop + (when (equal (shell-command-to-string "hostname") "adho\n") + (require 'exwm-randr) + (setq exwm-randr-workspace-output-plist (generate-randr-config)) + (exwm-randr-enable)) - ;; Let buffers move seamlessly between workspaces - (setq exwm-workspace-show-all-buffers t) - (setq exwm-layout-show-all-buffers t))) + ;; Let buffers move seamlessly between workspaces + (setq exwm-workspace-show-all-buffers t) + (setq exwm-layout-show-all-buffers t))) (provide 'nixos) diff --git a/init/rust-setup.el b/init/rust-setup.el deleted file mode 100644 index cc61718c1..000000000 --- a/init/rust-setup.el +++ /dev/null @@ -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) diff --git a/init/settings.el b/init/settings.el index 5d09dfb4d..2e4dedc0a 100644 --- a/init/settings.el +++ b/init/settings.el @@ -1,7 +1,6 @@ (require 'prescient) (require 'ivy-prescient) (require 'uniquify) -(require 'password-store) (require 'ivy-pass) ;; Make ivy go! @@ -63,20 +62,4 @@ ;; Show time in 24h format (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) diff --git a/init/term-setup.el b/init/term-setup.el index e8c743871..ea58a53bb 100644 --- a/init/term-setup.el +++ b/init/term-setup.el @@ -1,6 +1,4 @@ -;; Configuration for multi-term mode: - -(require 'multi-term) +;; Utilities for term-mode (defun open-or-create-term-buffer (buffer-name) "Switch to the buffer with BUFFER-NAME or create a @@ -31,16 +29,4 @@ (rename-buffer (format "*terminal<%s>*" (read-string "New terminal name: "))) (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)