summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-10-07 17:28:30 -0500
committerCase Duckworth2021-10-07 17:28:30 -0500
commitb2eb31629e96043163f6e210b4fc8b7f72b63f16 (patch)
treed513309ace686c7d0141d436b2c8304f0851122d /lisp
parentChange widths of things (diff)
downloademacs-b2eb31629e96043163f6e210b4fc8b7f72b63f16.tar.gz
emacs-b2eb31629e96043163f6e210b4fc8b7f72b63f16.zip
Begin on acdw-auto-insert.el
XXX It doesn't work right now
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-autoinsert.el55
1 files changed, 55 insertions, 0 deletions
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'.
28This function differs from `define-auto-insert' in that it won't
29allow more than one duplicate entry in `auto-insert-alist'.
30
31OPTIONS 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