summary refs log tree commit diff
diff options
context:
space:
mode:
authornoa2025-02-16 22:09:45 +0800
committernoa2025-02-16 22:09:45 +0800
commit438c591e7d290944f4b07c524a4eee93f461aa5b (patch)
tree24fddaa5af28a7752e6f70241289706780fab665
parentd249aa94e7c3e488cd7f62753efc9db8542a7896 (diff)
Update various packages to be configured via use-package
-rw-r--r--emacs/init.el348
1 files changed, 189 insertions, 159 deletions
diff --git a/emacs/init.el b/emacs/init.el
index 5fda993..8bb20c3 100644
--- a/emacs/init.el
+++ b/emacs/init.el
@@ -106,7 +106,16 @@
 
 (use-package simple
   :hook ((text-mode . visual-line-mode)
-         (after-init . auto-save-mode)))
+         (after-init . auto-save-mode))
+  :custom
+  (save-interprogram-paste-before-kill t)
+  (kill-ring-max 25)
+  ;; Hide commands in M-x which do not work in the current mode.
+  (read-extended-command-predicate 'command-completion-default-include-p)
+  ;; My brain is not ready for advanced emacs undo
+  (undo-no-redo t)
+  :bind (("C-z" . undo)
+         ("C-S-z" . undo-redo)))
 
 ;; (advice-add 'text-scale-adjust :after #'visual-fill-column-adjust)
 
@@ -118,12 +127,17 @@
 (use-package tooltip
   :custom (tooltip-mode nil))
 
-;;; Further options
-(setopt inhibit-startup-screen t
-	mouse-drag-and-drop-region nil
-	mouse-yank-at-point t
-	;; deleting should be an explicit action
-	delete-selection-mode nil)
+;; startup.el does not provide itself, cannot be used with use-package
+(setopt inhibit-startup-screen t)
+
+(use-package mouse
+  :custom
+  (mouse-yank-at-point t)
+  (mouse-drag-and-drop-region nil)
+  (mouse-yank-at-point t)
+  ;; Allow for slightly sloppier clicking.
+  (mouse-prefer-closest-glyph t) ;; Emacs 30
+)
 
 ;; Shift click to select region with the mouse (https://christiantietze.de/posts/2022/07/shift-click-in-emacs-to-select/)
 (global-set-key (kbd "S-<down-mouse-1>") #'mouse-set-mark)
@@ -238,8 +252,30 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
 (use-package flymake
   :hook (prog-mode . flymake-mode))
 
-;; Use a bar cursor and blink it and don't stop blinking it.
-(setopt cursor-type 'bar)
+(use-package emacs
+  :custom
+  (window-combination-resize t)
+  (window-resize-pixelwise t)
+  (frame-resize-pixelwise t)
+  (shell-file-name "/bin/sh")
+  (completion-ignore-case t)
+  (read-buffer-completion-ignore-case t)
+  ;; yes-or-no-p uses y-or-no-p, and read-answer accepts single key press answers
+  (use-short-answers t)
+  (history-length 250)
+  ;; Use a bar cursor and blink it and don't stop blinking it.
+  (cursor-type 'bar)
+  ;; Support opening new minibuffers from inside existing minibuffers.
+  (enable-recursive-minibuffers t)
+  ;; Whether to drop into the debugger on any error.  This seems cool, but in practice is a bit annoying.
+  (debug-on-error nil)
+  (create-lockfiles nil)
+  (auto-save-interval 6)  ;; every six keystrokes
+  (auto-save-timeout 5) ;; every 5 seconds
+  (auto-save-no-message t)
+  ;; Always give me a line of text when i'm near the edges of the screen
+  (scroll-margin 2)
+)
 
 (use-package dired
   :defer t
@@ -275,20 +311,38 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
   (dired-du-size-format t))
 
 ;; Some tramp settings.
-(setopt remote-file-name-inhibit-locks t)
+(use-package files
+  :custom
+  (view-read-only t)
+  (confirm-kill-emacs 'y-or-n-p)
+  ;; We are on a unix system, so it makes sense to end files in the unix system way.  I'm surprised this isn't the default.
+  (require-final-newline t)
+
+  ;; This behaviour changes how we visit symlinks.
+  (find-file-visit-truename t)
+
+  (remote-file-name-inhibit-locks t)
+  (remote-file-name-inhibit-auto-save t)
+  (remote-file-name-inhibit-auto-save-visited t)
+  (backup-directory-alist '(("." . "~/.config/emacs/backups/")))
+  (make-backup-files nil)
+  (backup-by-copying t)
+  (version-control t)
+  ;; this will auto save to the current file
+  (auto-save-visited-mode t)
+  )
 (use-package tramp
   :defer t
   :custom
-(tramp-inline-compress-start-size 1000)
-(tramp-verbose 3))
+  (tramp-inline-compress-start-size 1000)
+  (tramp-verbose 3))
 ;; (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
 
 ;; I only use git, and this apparently speeds up tramp.
 (use-package vc-hooks
   :after vc
   :custom
-(vc-handled-backends '(Git)))
-;; (setopt vc-handled-backends '(Git RCS CVS SVN SCCS SRC Bzr Hg))
+  (vc-handled-backends '(Git)))
 
 ;;  It seems that tramp can also be made faster with these .ssh/config settings.
 
@@ -300,7 +354,13 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
 ;;      ServerAliveInterval 60
 
 ;; Don't override display actions when i manually initiate a buffer switch.
-(setopt switch-to-buffer-obey-display-actions t)
+(use-package window
+  :custom
+  ;; My computer has a small screen, so i find that it's more beneficial for me to split the frame into columns, so i get more context.  However, splitting in this way only gives me a (window-width) of 61, so emacs will always split into vertically stacked windows.  By setting this to 80, the first split should always be vertical.
+  (split-width-threshold 80)
+  (switch-to-buffer-obey-display-actions t)
+  ;; C-l from top to bottom
+  (recenter-positions '(top middle bottom)))
 
 (use-package frame
   :hook (after-init . window-divider-mode)
@@ -321,46 +381,18 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
 	(cdr args)))
 (advice-add #'completing-read-multiple :filter-args #'crm-indicator)
 
-;; Support opening new minibuffers from inside existing minibuffers.
-(setopt enable-recursive-minibuffers t)
-
-;; Whether to drop into the debugger on any error.  This seems cool, but in practice is a bit annoying.
-(setopt debug-on-error nil)
-
-;; Hide commands in M-x which do not work in the current mode.
-(setopt read-extended-command-predicate 'command-completion-default-include-p)
-
 (use-package recentf
   :hook (after-init . recentf-mode)
   :custom
   (recentf-max-menu-items 25)
   (recentf-save-file "~/.config/emacs/recentf"))
 
-(setopt bookmark-default-file "~/.config/emacs/bookmarks")
-
-;; My brain is not ready for advanced emacs undo
-(setopt undo-no-redo t)
-(global-unset-key (kbd "C-z"))
-(global-set-key (kbd "C-z") 'undo)
-(global-set-key (kbd "C-S-z") 'undo-redo)
+(use-package bookmark
+  :defer t
+  :custom
+  (bookmark-default-file "~/.config/emacs/bookmarks"))
 
 ;; Saving
-;; Backups are pointless in long emacs sessions, but autosaves are useful.
-(setopt remote-file-name-inhibit-auto-save t)
-(setopt remote-file-name-inhibit-auto-save-visited t)
-
-(setopt backup-directory-alist '(("." . "~/.config/emacs/backups/"))
-	make-backup-files nil
-	backup-by-copying t
-	create-lockfiles nil
-	auto-save-interval 6  ;; every six keystrokes
-	auto-save-timeout 5 ;; every 5 seconds
-	auto-save-default nil
-	auto-save-no-message t
-	save-silently t
-	version-control t
-	;; this will auto save to the current file
-	auto-save-visited-mode t)
 
 ;; https://reeds.website/project-write-every-change-in-emacs-buffer-to-disk
 ;; See here for a solution using built-in functionality
@@ -383,92 +415,61 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
     (fill-paragraph nil)))
 (global-set-key (kbd "M-Q") #'unfill-paragraph)
 
-;; C-l from top to bottom
-(setopt recenter-positions '(top middle bottom))
-;; Always give me a line of text when i'm near the edges of the screen
-(setopt scroll-margin 2)
-
 ;; Remember my position in files
-(setopt save-place-mode t)
-
-;; Use single character abbreviations to answer prompts.
-(setopt read-answer-short t)
-(setopt use-short-answers t)
+(use-package saveplace
+  :hook (after-init . save-place-mode))
 
 ;; Disable disabled commands
 (setq disabled-command-function nil)
 
 ;; Don't save changes in the customize interface
-(setopt custom-file (make-temp-file "custom"))
+(use-package cus-edit
+  :custom
+  (custom-file (make-temp-file "custom")))
 
 ;; Scroll along with text in compilation mode, and stop scrolling at the first error.
-(setopt compilation-scroll-output 'first-error)
+(use-package compile
+  :defer t
+  :custom
+  (compilation-scroll-output 'first-error))
 
 ;; Don't advertise gnu on startup
 (setq inhibit-startup-echo-area-message "noa")  ;; #userfreedom
 
 ;; Better buffer naming
-(setopt uniquify-after-kill-buffer-p t
-	uniquify-buffer-name-style 'forward
-	uniquify-ignore-buffers-re "^\\*"
-	uniquify-separator "/")
+(use-package uniquify
+  :custom
+  (uniquify-after-kill-buffer-p t)
+  (uniquify-buffer-name-style 'forward)
+  (uniquify-ignore-buffers-re "^\\*")
+  (uniquify-separator "/"))
 
 ;; Emacs server
 ;; (unless (server-running-p) (server-start)))
 
 ;; Better support for long lines.
-(setopt global-so-long-mode t)
-
-;; This will stop us being prompted before killing a buffer with a running process:
-(setopt kill-buffer-query-functions
-	(remq 'process-kill-buffer-query-function
-	      kill-buffer-query-functions))
+(use-package so-long
+  :hook (after-init . global-so-long-mode))
 
 ;; Automatically revert buffers when they change on disk.  This doesn't apply to tramp.
-(setopt global-auto-revert-mode t)
-(setopt global-auto-revert-non-file-buffers t)
-
-;; This behaviour changes how we visit symlinks.
-(setopt find-file-visit-truename t)
-(setopt vc-follow-symlinks 'ask)
-
-;; Clicking around
-;; Allow for slightly sloppier clicking.
-(setopt mouse-prefer-closest-glyph t)
-
-(use-package consult
-  :ensure t
-  :bind
-  (([remap switch-to-buffer] . consult-buffer)
-   ([remap yank-pop] . consult-yank-pop)
-   ([remap goto-line] . consult-goto-line)
-   ([remap imenu] . consult-imenu)
-   ([remap info] . consult-info)
-   ([remap repeat-complex-command] . consult-complex-command)
-   ([remap bookmark-jump] . consult-bookmark))
+(use-package autorevert
+  :hook (after-init . global-auto-revert-mode)
   :custom
-  ;; Use consult for completion at point
-  (completion-in-region-function 'consult-completion-in-region))
+  (global-auto-revert-non-file-buffers t))
 
-;; Annotations for completing-read
-;; (package-ensure 'marginalia)
-(use-package marginalia
-  :ensure t
-  :defer t
+(use-package vc-hooks
   :custom
-  (marginalia-mode t)
-  (marginalia-max-relative-age most-positive-fixnum) ;; Always show the relative age of file
-  )
+  (vc-follow-symlinks 'ask))
 
 ;; Minibuffer candidate completion
 ;; Display completion candidates vertically
 (use-package vertico
-  :ensure t
+  ;; :ensure t
+  :hook (after-init . vertico-mode)
   :custom
-  (vertico-mode t)
-  (vertico-count 12) ;; Use about half the screen to show candidates
-  (vertico-group-format #("%s " 0 3 (face vertico-group-title))) ;; Don't put a vertical line across group titles
-  (vertico-cycle t)) 
+  (vertico-resize nil) ;; don't shrink when there are less candidates
+  ;; (vertico-group-format #("%s " 0 3 (face vertico-group-title))) ;; Don't put a vertical line across group titles
+  )
 
 ;; Interact with vertico with the mouse.
 (use-package vertico-mouse
@@ -485,39 +486,98 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
   ;; If i type ~/ etc in a find-file prompt, get rid of the preceding directory names for a cleaner look.
   :hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
 
-;; Some settings for nicer completion with the default emacs completion buffer.  I don't use this, because i use vertico.
-;; (setopt completion-auto-help 'lazy
-;;         completion-auto-select 'second-tab
-;;         completion-show-help nil
-;;         completions-sort nil
-;;         completions-header-format nil)
+;; Prefix the current candidate with “» ”. From
+;; https://github.com/minad/vertico/wiki#prefix-current-candidate-with-arrow
+(advice-add #'vertico--format-candidate :around
+            (lambda (orig cand prefix suffix index _start)
+              (setq cand (funcall orig cand prefix suffix index _start))
+              (concat
+               (if (= vertico--index index)
+                   (propertize "» " 'face 'vertico-current)
+                 "  ")
+               cand)))
 
-;; Completion styles
-;; When given a prompt to select from a list of candidates, there are quite a lot of things we can tweak to improve the experience.
+;; Annotations for completing-read
+(use-package marginalia
+  ;; :ensure t
+  :defer t
+  :hook (after-init . marginalia-mode)
+  ;; :custom
+  ;; (marginalia-mode t)
+  )
 
-;; I don't actually know if these make any difference when i've specified a different completion style.
-(setopt read-buffer-completion-ignore-case t)
-(setopt read-file-name-completion-ignore-case t)
-(setopt completion-ignore-case t)
 
 ;; Basic matches candidates with the same text before the point, and the text after the point as a substring.
 ;; Orderless takes any number of space separated components and displays candidates that much every component in any order.
+;; I don't actually know if these make any difference when i've specified a different completion style.
+(use-package minibuffer
+  :custom
+  (read-file-name-completion-ignore-case t))
+
 (use-package orderless
-  :ensure t
+  :after minibuffer
   :custom
   (completion-styles '(orderless basic))
   (completion-category-overrides '((file (styles basic partial-completion)))))
 
+;; History
+
+(use-package savehist
+  :custom
+  (savehist-file "~/.config/emacs/savehist")
+  (savehist-additional-variables
+        '(kill-ring
+          command-history
+          set-variable-value-history
+          custom-variable-history
+          query-replace-history
+          read-expression-history
+          minibuffer-history
+          read-char-history
+          face-name-history
+          bookmark-history
+          file-name-history))
+  :hook (after-init . savehist-mode))
+
+(use-package consult
+  ;; :ensure t
+  :defer t
+  ;; :commands (consult-complete-in-region)
+  :bind
+  (
+   ;; ([remap switch-to-buffer] . consult-buffer)
+   ([remap yank-pop] . consult-yank-pop)
+   ([remap goto-line] . consult-goto-line)
+   ;; ([remap imenu] . consult-imenu)
+   ;; ([remap info] . consult-info)
+   ([remap repeat-complex-command] . consult-complex-command)
+   ([remap bookmark-jump] . consult-bookmark))
+  ;; :custom
+  ;; Use consult for completion at point
+  ;; (completion-in-region-function 'consult-completion-in-region)
+  )
+
+
+
+;; Some settings for nicer completion with the default emacs completion buffer.  I don't use this, because i use vertico.
+;; (setopt completion-auto-help 'lazy
+;;         completion-auto-select 'second-tab
+;;         completion-show-help nil
+;;         completions-sort nil
+;;         completions-header-format nil)
+
+;; Completion styles
+;; When given a prompt to select from a list of candidates, there are quite a lot of things we can tweak to improve the experience.
+
 ;; Make leading whitespace a uniform width, so indentation still works with proportional fonts
-(require 'elastic-indent)
-(add-hook 'prog-mode-hook #'elastic-indent-mode)
+(use-package elastic-indent
+  :disabled t
+  :hook (prog-mode . elastic-indent-mode))
 
 ;; Change the width of tab characters within lines to make subsequent lines form a table-like layout.
-(require 'elastic-table)
-(add-hook 'prog-mode-hook #'elastic-table-mode)
-
-;; Use tab for completion if the region is already indented
-(setopt tab-always-indent 'complete)
+(use-package elastic-table
+  :disabled t
+  :hook (prog-mode-hook . elastic-table-mode))
 
 ;; Indenting lisp with tabs is horrible.  H/t acdw
 (defvar space-indent-modes '(emacs-lisp-mode
@@ -541,9 +601,6 @@ The misspelled word is taken from OVERLAY.  WORD is the corrected word."
 ;; If i write a script, i will always run chmod +x after saving it.  This command means i don't have to do that.
 (add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
 
-;; We are on a unix system, so it makes sense to end files in the unix system way.  I'm surprised this isn't the default.
-(setopt require-final-newline t)
-
 ;; Zap up to char
 (global-set-key (kbd "M-z") 'zap-up-to-char)
 
@@ -589,18 +646,6 @@ With prefix argument TIME, also add the current time."
 
 (global-set-key (kbd "C-x k") 'kill-current-buffer)
 
-;; Window management
-;; My computer has a small screen, so i find that it's more beneficial for me to split the frame into columns, so i get more context.  However, splitting in this way only gives me a (window-width) of 61, so emacs will always split into vertically stacked windows.  By setting this to 80, the first split should always be vertical.
-(setopt split-width-threshold 80)
-
-;; Full text search of every file in my home directory.
-(defun noa/consult-rg-home ()
-  (interactive)
-  (consult-ripgrep "~/"))
-(global-set-key (kbd "M-<menu>") #'noa/consult-rg-home)
-
-(setopt shell-file-name "/bin/sh")
-
 (defun snarf-song (url)
   (interactive "sYoutube url:")
   (async-shell-command
@@ -609,10 +654,6 @@ With prefix argument TIME, also add the current time."
            " "
            (shell-quote-argument url))))
 
-;;; Other
-(setopt confirm-kill-emacs 'y-or-n-p)
-
-(global-set-key (kbd "C-=") #'calc)
 
 ;;; Email
 
@@ -674,19 +715,10 @@ With prefix argument TIME, also add the current time."
 ;; Dictionary
 ;; Emacs has built in support for interfacing with dictd.  With dictd and some dictionaries installed on debian, this works fine out of the box.
 ;; Unfortunately, dictionaries in this format tend to be hard wrapped and there isn't a lot of coverage outside of english
-(setopt dictionary-search-interface nil)
-
-;; Unsorted
-;; Just a few settings i haven't put into another category yet.
-(setopt save-interprogram-paste-before-kill t
-	mouse-yank-at-point t
-	require-final-newline t
-	load-prefer-newer t
-	ediff-window-setup-function 'ediff-setup-windows-plain)
-
-;; Qr codes
-(use-package qrencode
-  :ensure t)
+(use-package dictionary
+  :defer t
+  :custom
+  (dictionary-search-interface nil))
 
 ;;; Bibliography management
 ;; TODO: update this to fit with the new single org file notes system.  This way should be easier than the previous method i think.
@@ -962,8 +994,6 @@ With prefix argument TIME, also add the current time."
              ("bb" . bbdb-search-name)
              ("el" apply-partially #'hyperspace-action->info "(elisp)Top"))))
 
-(setopt view-read-only t)
-
 ;; Common lisp development
 
 (use-package sly