59 lines
1.9 KiB
EmacsLisp
59 lines
1.9 KiB
EmacsLisp
;;; 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-safe a) (cdar b)))))
|
|
(replace (or (plist-get options :replace) nil))
|
|
(after (or (plist-get options :after) nil)))
|
|
(if replace
|
|
(progn (setq auto-insert-alist
|
|
(assoc-delete-all (list condition)
|
|
auto-insert-alist
|
|
testfn))
|
|
(define-auto-insert condition action after))
|
|
(unless (assoc (list condition) auto-insert-alist testfn)
|
|
(define-auto-insert condition action after)))))
|
|
|
|
(provide 'acdw-autoinsert)
|
|
;;; acdw-autoinsert.el ends here
|