diff options
Diffstat (limited to 'lisp/+scratch.el')
-rw-r--r-- | lisp/+scratch.el | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/lisp/+scratch.el b/lisp/+scratch.el deleted file mode 100644 index 5d749c6..0000000 --- a/lisp/+scratch.el +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | ;;; +scratch.el --- *scratch* improvements -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;; Copyright (C) 2023 Case Duckworth | ||
4 | |||
5 | ;; Author: Case Duckworth <case@acdw.net> | ||
6 | ;; Keywords: convenience | ||
7 | |||
8 | ;; This program is free software; you can redistribute it and/or modify | ||
9 | ;; it under the terms of the GNU General Public License as published by | ||
10 | ;; the Free Software Foundation, either version 3 of the License, or | ||
11 | ;; (at your option) any later version. | ||
12 | |||
13 | ;; This program is distributed in the hope that it will be useful, | ||
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | ;; GNU General Public License for more details. | ||
17 | |||
18 | ;; You should have received a copy of the GNU General Public License | ||
19 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
20 | |||
21 | ;;; Commentary: | ||
22 | |||
23 | ;; | ||
24 | |||
25 | ;;; Code: | ||
26 | |||
27 | (defcustom +scratch-save-dir (locate-user-emacs-file "scratch.d") | ||
28 | "Where to save scratch files." | ||
29 | :type 'file) | ||
30 | |||
31 | (defcustom +scratch-max-age (* 60 60 24 365) | ||
32 | "Maximum age of a saved scratch buffer. Default: one year." | ||
33 | :type 'natnum) | ||
34 | |||
35 | (defun +scratch@immortal () | ||
36 | "Don't kill *scratch* with `kill-buffer'." | ||
37 | (if (equal (buffer-name) "*scratch*") | ||
38 | (progn (bury-buffer) nil) | ||
39 | t)) | ||
40 | |||
41 | (defun +scratch-save (time-format) | ||
42 | "Save *scratch* buffer to `+scratch-save-dir'. | ||
43 | TIME-FORMAT will be used to name the buffer." | ||
44 | (interactive (list "%FT%H%z")) | ||
45 | (with-current-buffer (get-scratch-buffer-create) | ||
46 | (let ((buffer-file-name (expand-file-name (format "%s.%s" | ||
47 | (format-time-string | ||
48 | time-format) | ||
49 | (pcase major-mode | ||
50 | ('org-mode "org") | ||
51 | ('emacs-lisp-mode "el") | ||
52 | (_ "txt"))) | ||
53 | +scratch-save-dir))) | ||
54 | (unless (string-equal (buffer-substring (point-min) (point-max)) | ||
55 | initial-scratch-message) | ||
56 | (save-buffer 0))))) | ||
57 | |||
58 | (defun +scratch-save-on-exit () | ||
59 | (+scratch-save "%FT%T%z") | ||
60 | (+scratch-clean)) | ||
61 | |||
62 | (defun +scratch-clean () | ||
63 | "Clean up saved scratches. | ||
64 | Scratch files older than `+scratch-max-age' will be removed." | ||
65 | (dolist (f (directory-files +scratch-save-dir)) | ||
66 | (when (and (not (equal f ".")) | ||
67 | (not (equal f "..")) | ||
68 | (> (time-convert (file-attribute-modification-time | ||
69 | (file-attributes f)) | ||
70 | 'integer) | ||
71 | +scratch-max-age)) | ||
72 | (delete-file (expand-file-name f +scratch-save-dir) :trash)))) | ||
73 | |||
74 | (provide '+scratch) | ||
75 | ;;; +scratch.el ends here | ||