diff options
author | Case Duckworth | 2021-10-07 17:28:30 -0500 |
---|---|---|
committer | Case Duckworth | 2021-10-07 17:28:30 -0500 |
commit | b2eb31629e96043163f6e210b4fc8b7f72b63f16 (patch) | |
tree | d513309ace686c7d0141d436b2c8304f0851122d | |
parent | Change widths of things (diff) | |
download | emacs-b2eb31629e96043163f6e210b4fc8b7f72b63f16.tar.gz emacs-b2eb31629e96043163f6e210b4fc8b7f72b63f16.zip |
Begin on acdw-auto-insert.el
XXX It doesn't work right now
-rw-r--r-- | init.el | 34 | ||||
-rw-r--r-- | lisp/acdw-autoinsert.el | 55 |
2 files changed, 89 insertions, 0 deletions
diff --git a/init.el b/init.el index fcf37c8..ac88cde 100644 --- a/init.el +++ b/init.el | |||
@@ -13,7 +13,9 @@ | |||
13 | ;; Everyone is permitted to do whatever with this software, without | 13 | ;; Everyone is permitted to do whatever with this software, without |
14 | ;; limitation. This software comes without any warranty whatsoever, | 14 | ;; limitation. This software comes without any warranty whatsoever, |
15 | ;; but with two pieces of advice: | 15 | ;; but with two pieces of advice: |
16 | |||
16 | ;; - Be kind to yourself. | 17 | ;; - Be kind to yourself. |
18 | |||
17 | ;; - Make good choices. | 19 | ;; - Make good choices. |
18 | 20 | ||
19 | ;;; Commentary: | 21 | ;;; Commentary: |
@@ -94,6 +96,38 @@ | |||
94 | (expand-file-name-exists-p "pkg/" user-emacs-directory))) | 96 | (expand-file-name-exists-p "pkg/" user-emacs-directory))) |
95 | (normal-top-level-add-subdirs-to-load-path))) | 97 | (normal-top-level-add-subdirs-to-load-path))) |
96 | 98 | ||
99 | (setup autoinsert | ||
100 | (require 'acdw-autoinsert) | ||
101 | (acdw/define-auto-insert '(:replace t) | ||
102 | ;; This is my custom auto-insert for elisp files. | ||
103 | '("\\.el\\'" . "Emacs Lisp header (acdw)") | ||
104 | '("Short description: " ";;; " | ||
105 | (file-name-nondirectory (buffer-file-name)) | ||
106 | " --- " str | ||
107 | (make-string (max 2 ( - 80 (current-column) 27)) 32) | ||
108 | "-*- lexical-binding: t; -*-" | ||
109 | '(setq lexical-binding t) | ||
110 | "\n\n;; Copyright (C) " (format-time-string "%Y") | ||
111 | " " (getenv "ORGANIZATION") | (progn user-full-name) | ||
112 | "\n\n;; Author: " (user-full-name) | ||
113 | '(if (search-backward "&" (line-beginning-position) t) | ||
114 | (replace-match (capitalize (user-login-name)) t t)) | ||
115 | '(end-of-line 1) | ||
116 | " <" (progn user-mail-address) ">" | ||
117 | & -2 | ||
118 | "\n\n;;; License:" | ||
119 | "\n\n;; Everyone is permitted to do whatever with this software, without" | ||
120 | "\n;; limitation. This software comes without any warranty whatsoever," | ||
121 | "\n;; but with two pieces of advice:" | ||
122 | "\n\n;; - Be kind to yourself." | ||
123 | "\n\n;; - Make good choices." | ||
124 | "\n\n;;; Commentary:" | ||
125 | "\n\n;; " _ | ||
126 | "\n\n;;; Code:" | ||
127 | "\n\n\n\n(provide '" (file-name-base (buffer-file-name)) ")" | ||
128 | "\n;;; " (file-name-nondirectory (buffer-file-name)) " ends here\n")) | ||
129 | (auto-insert-mode +1)) | ||
130 | |||
97 | (setup autorevert | 131 | (setup autorevert |
98 | (:option global-auto-revert-non-file-buffers t | 132 | (:option global-auto-revert-non-file-buffers t |
99 | auto-revert-verbose nil) | 133 | auto-revert-verbose nil) |
diff --git a/lisp/acdw-autoinsert.el b/lisp/acdw-autoinsert.el new file mode 100644 index 0000000..a89bc80 --- /dev/null +++ b/lisp/acdw-autoinsert.el | |||
@@ -0,0 +1,55 @@ | |||
1 | ;;; acdw-autoinsert.el --- autoinsert.el -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;; Copyright (C) 2021 Case Duckworth | ||
4 | |||
5 | ;; Author: Case Duckworth <acdw@acdw.ne | ||
6 | |||
7 | ;;; License: | ||
8 | |||
9 | ;; Everyone is permitted to do whatever with this software, without | ||
10 | ;; limitation. This software comes without any warranty whatsoever, | ||
11 | ;; but with two pieces of advice: | ||
12 | |||
13 | ;; - Be kind to yourself. | ||
14 | |||
15 | ;; - Make good choices. | ||
16 | |||
17 | ;;; Commentary: | ||
18 | |||
19 | ;; These are my bespoke changes to the `autoinsert' library. | ||
20 | |||
21 | ;;; Code: | ||
22 | |||
23 | (require 'autoinsert) | ||
24 | (require 'cl-lib) | ||
25 | |||
26 | (defun acdw/define-auto-insert (options condition action) | ||
27 | "Associate CONDITION with ACTION in `auto-insert-alist'. | ||
28 | This function differs from `define-auto-insert' in that it won't | ||
29 | allow more than one duplicate entry in `auto-insert-alist'. | ||
30 | |||
31 | OPTIONS is a plist with three optional arguments: | ||
32 | |||
33 | - `:testfn' takes a function to test the given CONDITION against | ||
34 | the already-existing ones in `auto-insert-alist'. It defaults | ||
35 | to testing the cdr of CONDITION against the cdar of each entry | ||
36 | in `auto-insert-alist'. | ||
37 | |||
38 | - `:replace', if non-nil, will replace the matching entry with | ||
39 | the given one. Default: nil. | ||
40 | |||
41 | - `:after' is the third, optional argument to `define-auto-insert'." | ||
42 | (declare (indent 1)) | ||
43 | (let ((testfn (or (plist-get options :testfn) | ||
44 | (lambda (a b) | ||
45 | (string= (cdr a) (cdar b))))) | ||
46 | (replace (or (plist-get options :replace) nil)) | ||
47 | (after (or (plist-get options :after) nil))) | ||
48 | (when replace | ||
49 | (setq auto-insert-alist | ||
50 | (assoc-delete-all condition auto-insert-alist testfn))) | ||
51 | (unless (assoc (list condition) auto-insert-alist testfn) | ||
52 | (define-auto-insert condition action after)))) | ||
53 | |||
54 | (provide 'acdw-autoinsert) | ||
55 | ;;; acdw-autoinsert.el ends here | ||