summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-autoinsert.el55
-rw-r--r--lisp/acdw.el44
2 files changed, 72 insertions, 27 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
diff --git a/lisp/acdw.el b/lisp/acdw.el index 5d23e72..df2962a 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -787,32 +787,6 @@ This function is internal. Use `acdw/make-password-fetcher' instead."
787 (insert "💩") 787 (insert "💩")
788 (setq n (1- n))))) 788 (setq n (1- n)))))
789 789
790(defun spongebob-case-region (beg end)
791 "Make region, defined by BEG and END, lOoK lIkE tHiS."
792 (interactive "*r")
793 (save-excursion
794 (let (case)
795 (goto-char beg)
796 (while (< (point) end)
797 (if (looking-at "[[:alpha:]]")
798 (if (setq case (not case))
799 (upcase-region (point) (progn (forward-char 1) (point)))
800 (downcase-region (point) (progn (forward-char 1) (point))))
801 (forward-char 1))))))
802
803(defun spongebob-case-word (n)
804 "Spongebob-case N words forward, beginning at point, moving over."
805 (interactive "*p")
806 (spongebob-case-region (point) (progn (forward-word n) (point))))
807
808(defun spongebob-case-dwim (arg)
809 "Spongebob-case words in the region if active, else word at point.
810If ARG exists, it's passed to `spongebob-case-word'."
811 (interactive "*p")
812 (if (use-region-p)
813 (spongebob-case-region (region-beginning) (region-end))
814 (spongebob-case-word arg)))
815
816 790
817;;; Fat finger solutions 791;;; Fat finger solutions
818(defun acdw/fat-finger-exit (&optional prefix) 792(defun acdw/fat-finger-exit (&optional prefix)
@@ -872,7 +846,23 @@ three blank lines, then place the point on the second one."
872 (newline) 846 (newline)
873 (delete-blank-lines) 847 (delete-blank-lines)
874 (newline 2) 848 (newline 2)
875 (previous-line)) 849 (forward-line -1))
850
851(defun require/ (feature &optional filename noerror)
852 "If FEATURE is not loaded, load it from FILENAME.
853This function works just like `require', with one crucial
854difference: if the FEATURE name contains a slash, the FILENAME
855will as well -- unless, of course, FILENAME is set. This allows
856for `require/' to require files within subdirectories of
857directories of `load-path'. Of course, NOERROR isn't affected by
858the change."
859 (let* ((feature-name (if (symbolp feature)
860 (symbol-name feature)
861 feature))
862 (filename (or filename
863 (and (string-match-p "/" feature-name)
864 feature-name))))
865 (require (intern feature-name) filename noerror)))
876 866
877(provide 'acdw) 867(provide 'acdw)
878;;; acdw.el ends here 868;;; acdw.el ends here