Files
sydnix/modules/home/users/crumb/emacs/modules/syd-autosave.el
Madeleine Sydney Ślaga 0ea963c879 chore: Fix tree-wide permissions
No idea why everything was executable, lol.
2025-09-08 06:08:20 -06:00

80 lines
3.3 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
;;; syd-autosave.el -*- lexical-binding: t; -*-
(require 'syd-prelude)
(setq backup-directory-alist
`(("." . ,(file-name-concat syd-data-dir "backup")))
auto-save-list-file-prefix (let ((dir (file-name-concat syd-cache-dir
"autosave/")))
(make-directory dir t)
dir)
;; Nil means untracked files under VC won't get backed up.
vc-make-backup-files t
;; Nil will clobber symlinks.
backup-by-copying t
;; Use versioned backups.
version-control t
;; Don't create ugly lockfiles. See
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html#Interlocking
;; This is a good feature, but not very relevant to a single-user system.
create-lockfiles nil
auto-save-file-name-transforms
;; Good grief, girl...
`(("\\`/[^/]*:\\([^/]*/\\)*\\([^/]*\\)\\'"
,(concat auto-save-list-file-prefix "tramp-\\2") t)
(".*"
,(file-name-concat syd-cache-dir "autosave") t))
kept-new-versions 5
delete-old-versions t)
;; Save your cursor position in recently-opened files.
(use-package saveplace
:hook (on-first-file-hook . save-place-mode)
:custom (save-place-file (file-name-concat syd-cache-dir "places")))
;; Keep track of recently-visited files.
(use-package recentf
:hook ((on-first-file-hook . recentf-mode)
(find-file-hook . recentf-save-list))
:custom (recentf-save-file (file-name-concat syd-data-dir "recentf")))
(use-package savehist
:defer-incrementally custom
:hook (on-first-input-hook . savehist-mode)
:custom (savehist-file (file-name-concat syd-cache-dir "savehist"))
:config
(setq savehist-save-minibuffer-history t
savehist-autosave-interval nil ; save on kill only
savehist-additional-variables
'(kill-ring ; persist clipboard
register-alist ; persist macros
mark-ring global-mark-ring ; persist marks
search-ring regexp-search-ring)) ; persist searches
(syd-add-hook 'savehist-save-hook
(defun syd--savehist-unpropertize-variables-h ()
"Remove text properties from `kill-ring' to reduce savehist cache size."
(setq kill-ring
(mapcar #'substring-no-properties
(cl-remove-if-not #'stringp kill-ring))
register-alist
(cl-loop for (reg . item) in register-alist
if (stringp item)
collect (cons reg (substring-no-properties item))
else collect (cons reg item))))
(defun syd--savehist-remove-unprintable-registers-h ()
"Remove unwriteable registers (e.g. containing window configurations).
Otherwise, `savehist' would discard `register-alist' entirely if we don't omit
the unwritable tidbits."
;; Save new value in the temp buffer savehist is running
;; `savehist-save-hook' in. We don't want to actually remove the
;; unserializable registers in the current session!
(setq-local register-alist
(cl-remove-if-not #'savehist-printable register-alist)))))
(with-eval-after-load 'bookmark
;; Stay out of my config dir!
(setq bookmark-default-file (file-name-concat syd-data-dir "bookmarks")))
(provide 'syd-autosave)