From b2eb31629e96043163f6e210b4fc8b7f72b63f16 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 7 Oct 2021 17:28:30 -0500 Subject: Begin on acdw-auto-insert.el XXX It doesn't work right now --- lisp/acdw-autoinsert.el | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lisp/acdw-autoinsert.el (limited to 'lisp') 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 @@ +;;; acdw-autoinsert.el --- autoinsert.el -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 Case Duckworth + +;; Author: Case Duckworth <acdw@acdw.ne + +;;; License: + +;; Everyone is permitted to do whatever with this software, without +;; limitation. This software comes without any warranty whatsoever, +;; but with two pieces of advice: + +;; - Be kind to yourself. + +;; - Make good choices. + +;;; Commentary: + +;; These are my bespoke changes to the `autoinsert' library. + +;;; Code: + +(require 'autoinsert) +(require 'cl-lib) + +(defun acdw/define-auto-insert (options condition action) + "Associate CONDITION with ACTION in `auto-insert-alist'. +This function differs from `define-auto-insert' in that it won't +allow more than one duplicate entry in `auto-insert-alist'. + +OPTIONS is a plist with three optional arguments: + +- `:testfn' takes a function to test the given CONDITION against + the already-existing ones in `auto-insert-alist'. It defaults + to testing the cdr of CONDITION against the cdar of each entry + in `auto-insert-alist'. + +- `:replace', if non-nil, will replace the matching entry with + the given one. Default: nil. + +- `:after' is the third, optional argument to `define-auto-insert'." + (declare (indent 1)) + (let ((testfn (or (plist-get options :testfn) + (lambda (a b) + (string= (cdr a) (cdar b))))) + (replace (or (plist-get options :replace) nil)) + (after (or (plist-get options :after) nil))) + (when replace + (setq auto-insert-alist + (assoc-delete-all condition auto-insert-alist testfn))) + (unless (assoc (list condition) auto-insert-alist testfn) + (define-auto-insert condition action after)))) + +(provide 'acdw-autoinsert) +;;; acdw-autoinsert.el ends here -- cgit 1.4.1-21-gabe81