From b727d4f684a2611351189e134b64fcef3661d9f8 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 11 May 2021 09:44:04 -0500 Subject: Add `acdw/system' macro `acdw/system' eases configuration -- it returns the system when called with no arguments, acts as a test with one argument, or as a `pcase' with more than one argument. --- early-init.el | 24 ++++++++++++------------ init.el | 36 ++++++++++++++++++------------------ lisp/acdw.el | 35 ++++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 39 deletions(-) diff --git a/early-init.el b/early-init.el index 3f1ebb0..622d220 100644 --- a/early-init.el +++ b/early-init.el @@ -51,10 +51,10 @@ (height . 30) (left-fringe . 8) ; Width of fringes (right-fringe . 8) ; (8 is default) - (font . ,(pcase acdw/system - (:home "DejaVu Sans Mono 10") - (:work "Consolas 10") - (:other "monospace 10")))) + (font . ,(acdw/system + (:home "DejaVu Sans Mono 10") + (:work "Consolas 10") + (:other "monospace 10")))) frame-inhibit-implied-resize t ; Don't resize randomly frame-resize-pixelwise t ; Resize by pixels, not chars inhibit-x-resources t ; Don't load ~/.Xresources @@ -76,15 +76,15 @@ (defun acdw/first-frame-setup () ;; fonts (require 'acdw-fonts) - (setq acdw-fonts/monospace (pcase acdw/system - (:home "DejaVu Sans Mono") - (:work "Consolas") - (:other "monospace")) + (setq acdw-fonts/monospace (acdw/system + (:home "DejaVu Sans Mono") + (:work "Consolas") + (:other "monospace")) acdw-fonts/monospace-size 10 - acdw-fonts/variable (pcase acdw/system - (:home "DejaVu Sans") - (:work "Calibri") - (:other "sans-serif")) + acdw-fonts/variable (acdw/system + (:home "DejaVu Sans") + (:work "Calibri") + (:other "sans-serif")) acdw-fonts/variable-size 12) (acdw-fonts/set) (acdw-fonts/setup-emoji-fonts "Segoe UI Emoji" diff --git a/init.el b/init.el index 74993fe..af817ee 100644 --- a/init.el +++ b/init.el @@ -66,7 +66,7 @@ ;; Flash the mode line (defun flash-mode-line () "Flash the modeline as a bell." - (when (eq acdw/system :home) + (when (acdw/system :home) (beep)) (invert-face 'mode-line) (run-with-timer 0.1 nil #'invert-face 'mode-line)) @@ -103,7 +103,7 @@ 'browse-url-default-browser) browse-url-new-window-flag t browse-url-firefox-new-window-is-tab t) - (when (eq acdw/system :work) + (when (acdw/system :work) (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox"))) (setup buffers @@ -162,14 +162,14 @@ (:global "C-x C-j" dired-jump) - (pcase acdw/system - (:work (:straight w32-browser) - (autoload 'dired-w32-browser "w32-browser") - (:bind "RET" dired-w32-browser)) - (:home (:straight dired-open) - (require 'dired-open) - (:bind "RET" dired-find-alternate-file) - (:option (prepend dired-open-functions) #'dired-open-xdg))) + (acdw/system + (:work (:straight w32-browser) + (autoload 'dired-w32-browser "w32-browser") + (:bind "RET" dired-w32-browser)) + (:home (:straight dired-open) + (require 'dired-open) + (:bind "RET" dired-find-alternate-file) + (:option (prepend dired-open-functions) #'dired-open-xdg))) (:when-loaded (:straight dired-subtree) @@ -251,11 +251,11 @@ (set-terminal-coding-system 'utf-8-unix) (set-keyboard-coding-system 'utf-8-unix) - (pcase acdw/system - (:work (set-clipboard-coding-system 'utf-16-le) - (set-selection-coding-system 'utf-16-le)) - (_ (set-selection-coding-system 'utf-8) - (set-clipboard-coding-system 'utf-8)))) + (acdw/system + (:work (set-clipboard-coding-system 'utf-16-le) + (set-selection-coding-system 'utf-16-le)) + (_ (set-selection-coding-system 'utf-8) + (set-clipboard-coding-system 'utf-8)))) (setup eshell (:option eshell-directory-name (acdw/dir "eshell/" t) @@ -469,7 +469,7 @@ (setup saveplace (:option save-place-file (acdw/dir "places.el") - save-place-forget-unreadable-files (eq acdw/system :home)) + save-place-forget-unreadable-files (acdw/system :home)) (save-place-mode +1)) @@ -1017,7 +1017,7 @@ if ripgrep is installed, otherwise `consult-grep'." (:option undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'") undo-fu-session-directory (acdw/dir "undo/" t) - undo-fu-session-compression (eq acdw/system :home)) + undo-fu-session-compression (acdw/system :home)) (global-undo-fu-session-mode +1)) @@ -1091,7 +1091,7 @@ call `zzz-to-char'." ;;; System-dependent ;;;; Home -(when (eq acdw/system :home) +(when (acdw/system :home) (setup (:straight pkgbuild-mode)) diff --git a/lisp/acdw.el b/lisp/acdw.el index a798069..a1c364d 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -21,12 +21,29 @@ ;;; Variables -(defconst acdw/system (pcase system-type - ('gnu/linux :home) - ((or 'msdos 'windows-nt) :work) - (_ :other)) +(defconst acdw/system + (pcase system-type + ('gnu/linux :home) + ((or 'msdos 'windows-nt) :work) + (_ :other)) "Which computer system is currently being used.") +(defmacro acdw/system (&rest arg) + "Convenience macro for interfacing with `acdw/system'. + +When called without arguments, it returns `acdw/system'. +When called with one argument, it returns (eq acdw/system ARG). +When called with multiple arguments, it returns `pcase' over each argument." + (cond + ((not arg) acdw/system) + ((not (cdr arg)) + `(when (eq acdw/system ,(car arg)) + ,(car arg))) + ((cdr arg) + `(pcase acdw/system + ,@arg)) + (t (error "Wrong argument type: %s" (type-of arg))))) + ;;; Utility functions ;; I don't prefix these because ... reasons. Honestly I probably should prefix @@ -162,11 +179,11 @@ if MAKE-DIRECTORY is non-nil." (defun acdw/find-emacs-source () "Find where Emacs keeps its source tree." - (pcase acdw/system - (:work (expand-file-name - (concat "~/src/emacs-" emacs-version "/src"))) - (:home (expand-file-name "~/src/pkg/emacs/src/emacs-git/src")) - (:other nil))) + (acdw/system + (:work (expand-file-name + (concat "~/src/emacs-" emacs-version "/src"))) + (:home (expand-file-name "~/src/pkg/emacs/src/emacs-git/src")) + (:other nil))) (defun acdw/gc-disable () "Functionally disable the Garbage collector." -- cgit 1.4.1-21-gabe81 From 2bf518fab7ad0b8d0146a551291f1c34e0660821 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 11 May 2021 09:45:42 -0500 Subject: Add `org-mode' to `stupid-modes' for `dumb-auto-format' To keep hanging list items from indenting at save. --- init.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index af817ee..ddbb53f 100644 --- a/init.el +++ b/init.el @@ -617,7 +617,8 @@ ;; Use a dumb formatter on modes that `apheleia' doesn't work for. (hook-defun dumb-auto-format before-save-hook - (setq stupid-modes '(makefile-mode)) + (setq stupid-modes '(makefile-mode + org-mode)) ;; If there's no apheleia formatter for the mode, just indent the buffer. (unless (or (apply #'derived-mode-p stupid-modes) (and (fboundp 'apheleia--get-formatter-command) -- cgit 1.4.1-21-gabe81 From 05ea83385ba5478f7463d99e13b615e166c599eb Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 12 May 2021 16:41:58 -0500 Subject: Make recentf dired-aware --- init.el | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index 24d71ed..9d2fa33 100644 --- a/init.el +++ b/init.el @@ -450,8 +450,37 @@ (:option recentf-save-file (acdw/dir "recentf.el") recentf-max-menu-items 100 recentf-max-saved-items nil - recentf-auto-cleanup 60 + recentf-auto-cleanup 'mode (append recentf-exclude) (acdw/dir)) + + ;; Magic advice to rename entries in recentf when moving files in + ;; dired. + (defun rjs/recentf-rename-notify (oldname newname &rest args) + (if (file-directory-p newname) + (rjs/recentf-rename-directory oldname newname) + (rjs/recentf-rename-file oldname newname))) + + (defun rjs/recentf-rename-file (oldname newname) + (setq recentf-list + (mapcar (lambda (name) + (if (string-equal name oldname) + newname + oldname)) + recentf-list))) + + (defun rjs/recentf-rename-directory (oldname newname) + ;; oldname, newname and all entries of recentf-list should already + ;; be absolute and normalised so I think this can just test whether + ;; oldname is a prefix of the element. + (setq recentf-list + (mapcar (lambda (name) + (if (string-prefix-p oldname name) + (concat newname (substring name (length oldname))) + name)) + recentf-list))) + + (advice-add 'dired-rename-file :after #'rjs/recentf-rename-notify) + (recentf-mode +1)) (setup (:require savehist) -- cgit 1.4.1-21-gabe81 From 92ff615f9cb6a501cef2ca95f35abd20a70d2f28 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 12 May 2021 16:42:18 -0500 Subject: Unbind h --- init.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index 9d2fa33..b8951a0 100644 --- a/init.el +++ b/init.el @@ -624,7 +624,9 @@ find-function-C-source-directory (acdw/find-emacs-source)) (:global "M-=" count-words - "C-w" kill-region-or-backward-word) + "C-w" kill-region-or-backward-word + " h" nil ; HELLO takes a long time to load on Windows + ) ;; Remap C-h to DEL -- can be the "help" key (define-key key-translation-map [?\C-h] [?\C-?]) -- cgit 1.4.1-21-gabe81 From 2341f0bac30a4206209639e7b25431723fe6e715 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 12 May 2021 16:42:36 -0500 Subject: Save more variables --- init.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/init.el b/init.el index b8951a0..bc61a28 100644 --- a/init.el +++ b/init.el @@ -486,12 +486,15 @@ (setup (:require savehist) (:option history-length t history-delete-duplicates t - savehist-autosave-interval 6 + savehist-autosave-interval 60 savehist-file (acdw/dir "savehist.el")) - (dolist (var '(kill-ring + (dolist (var '(extended-command-history + global-mark-ring + kill-ring + regexp-search-ring search-ring - regexp-search-ring)) + mark-ring)) (:option (append savehist-additional-variables) var)) (savehist-mode +1)) -- cgit 1.4.1-21-gabe81 From 814cc4313853bb2c29fe97789e523089ecdda7f6 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 12 May 2021 16:42:59 -0500 Subject: Remove INBOX from groups.txt I think it causes issues with restarting Gnus in a running session. --- groups.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/groups.txt b/groups.txt index 5cee798..08c604c 100644 --- a/groups.txt +++ b/groups.txt @@ -1,4 +1,3 @@ -nnimap+fastmail.com:INBOX nntp+news.gwene.org:gwene.blog.botanistinthek nntp+news.gwene.org:gwene.ca.muto nntp+news.gwene.org:gwene.casa.m455 -- cgit 1.4.1-21-gabe81