diff options
-rw-r--r-- | init.el | 84 | ||||
-rw-r--r-- | lisp/acdw-autoinsert.el | 55 | ||||
-rw-r--r-- | lisp/acdw.el | 44 |
3 files changed, 145 insertions, 38 deletions
diff --git a/init.el b/init.el index b4790e0..d3ad238 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) |
@@ -397,8 +431,7 @@ | |||
397 | (:bind "c" #'capitalize-dwim | 431 | (:bind "c" #'capitalize-dwim |
398 | "t" #'titlecase-dwim | 432 | "t" #'titlecase-dwim |
399 | "u" #'upcase-dwim | 433 | "u" #'upcase-dwim |
400 | "l" #'downcase-dwim | 434 | "l" #'downcase-dwim)) |
401 | "s" #'spongebob-case-dwim)) | ||
402 | 435 | ||
403 | (column-number-mode +1)) | 436 | (column-number-mode +1)) |
404 | 437 | ||
@@ -523,11 +556,10 @@ | |||
523 | 556 | ||
524 | (defun list-string-match-p (string regexp-list) | 557 | (defun list-string-match-p (string regexp-list) |
525 | "Return t if at least one regex in RETGEXP-LIST matches STRING, else nil." | 558 | "Return t if at least one regex in RETGEXP-LIST matches STRING, else nil." |
526 | (when string ; if STRING is nil, return nil. | 559 | ;; FINE alphapapa ;P |
527 | (catch 'found | 560 | (seq-some (lambda (regexp) |
528 | (dolist (regexp regexp-list) | 561 | (string-match regexp string)) |
529 | (when (string-match regexp string) | 562 | regexp-list)) |
530 | (throw 'found t)))))) | ||
531 | 563 | ||
532 | (defun flymake-unless () | 564 | (defun flymake-unless () |
533 | "Turn on `flymake-mode', UNLESS it's inhibited. | 565 | "Turn on `flymake-mode', UNLESS it's inhibited. |
@@ -1185,6 +1217,7 @@ specific to most general, they are these: | |||
1185 | scroll-margin 0 | 1217 | scroll-margin 0 |
1186 | word-wrap t | 1218 | word-wrap t |
1187 | wrap-prefix (repeat-string acdw-irc/left-margin " ") | 1219 | wrap-prefix (repeat-string acdw-irc/left-margin " ") |
1220 | nyan-mode nil | ||
1188 | line-number-mode nil | 1221 | line-number-mode nil |
1189 | column-number-mode nil | 1222 | column-number-mode nil |
1190 | file-percentage-mode nil) | 1223 | file-percentage-mode nil) |
@@ -1298,6 +1331,23 @@ specific to most general, they are these: | |||
1298 | "C-M-\\" #'crux-cleanup-buffer-or-region | 1331 | "C-M-\\" #'crux-cleanup-buffer-or-region |
1299 | "C-x 4 t" #'crux-transpose-windows) | 1332 | "C-x 4 t" #'crux-transpose-windows) |
1300 | 1333 | ||
1334 | (el-patch-feature crux) | ||
1335 | (with-eval-after-load 'crux | ||
1336 | (el-patch-defun crux-reopen-as-root () | ||
1337 | "Find file as root if necessary. | ||
1338 | |||
1339 | Meant to be used as `find-file-hook'. | ||
1340 | See also `crux-reopen-as-root-mode'." | ||
1341 | (unless (or | ||
1342 | ;; This helps fix for `nov-mode', and possibly others. | ||
1343 | (el-patch-add (null buffer-file-name)) | ||
1344 | (tramp-tramp-file-p buffer-file-name) | ||
1345 | (equal major-mode 'dired-mode) | ||
1346 | (not (file-exists-p (file-name-directory buffer-file-name))) | ||
1347 | (file-writable-p buffer-file-name) | ||
1348 | (crux-file-owned-by-user-p buffer-file-name)) | ||
1349 | (crux-find-alternate-file-as-root buffer-file-name)))) | ||
1350 | |||
1301 | (crux-reopen-as-root-mode +1)) | 1351 | (crux-reopen-as-root-mode +1)) |
1302 | 1352 | ||
1303 | ;; (setup (:straight-when | 1353 | ;; (setup (:straight-when |
@@ -1906,7 +1956,13 @@ browser defined in `browse-url-secondary-browser-function'." | |||
1906 | (:option nyan-animate-nyancat nil | 1956 | (:option nyan-animate-nyancat nil |
1907 | nyan-bar-length 20 | 1957 | nyan-bar-length 20 |
1908 | nyan-minimum-window-width fill-column) | 1958 | nyan-minimum-window-width fill-column) |
1909 | (nyan-mode +1)) | 1959 | (nyan-mode +1) |
1960 | (defun disable-nyan-mode () | ||
1961 | "Disable `nyan-mode' in current buffer." | ||
1962 | (setq-local nyan-mode -1)) | ||
1963 | (dolist (mode '(eshell-mode | ||
1964 | comint-mode)) | ||
1965 | (add-hook mode #'disable-nyan-mode))) | ||
1910 | 1966 | ||
1911 | ;; (setup (:straight olivetti) | 1967 | ;; (setup (:straight olivetti) |
1912 | ;; (:option olivetti-body-width (+ fill-column 4) | 1968 | ;; (:option olivetti-body-width (+ fill-column 4) |
@@ -1927,7 +1983,8 @@ browser defined in `browse-url-secondary-browser-function'." | |||
1927 | orderless-component-separator #'orderless-escapable-split-on-space | 1983 | orderless-component-separator #'orderless-escapable-split-on-space |
1928 | orderless-matching-styles '(orderless-literal | 1984 | orderless-matching-styles '(orderless-literal |
1929 | orderless-regexp | 1985 | orderless-regexp |
1930 | orderless-flex) | 1986 | ;; orderless-flex |
1987 | ) | ||
1931 | orderless-style-dispatchers '(acdw/orderless-dispatch)) | 1988 | orderless-style-dispatchers '(acdw/orderless-dispatch)) |
1932 | 1989 | ||
1933 | (:advise orderless-regexp :filter-args | 1990 | (:advise orderless-regexp :filter-args |
@@ -2032,7 +2089,7 @@ browser defined in `browse-url-secondary-browser-function'." | |||
2032 | org-src-window-setup 'current-window | 2089 | org-src-window-setup 'current-window |
2033 | org-startup-truncated nil | 2090 | org-startup-truncated nil |
2034 | org-startup-with-inline-images t | 2091 | org-startup-with-inline-images t |
2035 | org-tags-column (- fill-column)) | 2092 | org-tags-column (- (- fill-column (length org-ellipsis)))) |
2036 | 2093 | ||
2037 | (:bind "RET" #'acdw-org/return-dwim | 2094 | (:bind "RET" #'acdw-org/return-dwim |
2038 | "<S-return>" #'acdw-org/org-table-copy-down | 2095 | "<S-return>" #'acdw-org/org-table-copy-down |
@@ -2375,6 +2432,11 @@ the default is \"/\"." | |||
2375 | (:unbind "M-j" ; sp-join-sexp | 2432 | (:unbind "M-j" ; sp-join-sexp |
2376 | )) | 2433 | )) |
2377 | 2434 | ||
2435 | (setup (:straight (spongebob-case | ||
2436 | :host github | ||
2437 | :repo "duckwork/spongebob-case.el")) | ||
2438 | (:global "C-c c s" #'spongebob-case-dwim)) | ||
2439 | |||
2378 | (setup (:straight ssh-config-mode) | 2440 | (setup (:straight ssh-config-mode) |
2379 | (:file-match (rx "/.ssh/config" eos) | 2441 | (:file-match (rx "/.ssh/config" eos) |
2380 | (rx "/ssh" (? "d") "_config" eos)) | 2442 | (rx "/ssh" (? "d") "_config" eos)) |
@@ -2511,7 +2573,7 @@ If used with a numeric prefix argument N, N backticks will be inserted." | |||
2511 | (add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)) | 2573 | (add-hook 'rfn-eshadow-update-overlay-hook #'vertico-directory-tidy)) |
2512 | 2574 | ||
2513 | (setup (:straight visual-fill-column) | 2575 | (setup (:straight visual-fill-column) |
2514 | (:option visual-fill-column-width (+ fill-column 4) | 2576 | (:option visual-fill-column-width fill-column |
2515 | visual-fill-column-center-text t | 2577 | visual-fill-column-center-text t |
2516 | (append reading-modes) '(visual-fill-column-mode . +1)) | 2578 | (append reading-modes) '(visual-fill-column-mode . +1)) |
2517 | (:hook-into org-mode) | 2579 | (:hook-into org-mode) |
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 | ||
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. | ||
810 | If 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. | ||
853 | This function works just like `require', with one crucial | ||
854 | difference: if the FEATURE name contains a slash, the FILENAME | ||
855 | will as well -- unless, of course, FILENAME is set. This allows | ||
856 | for `require/' to require files within subdirectories of | ||
857 | directories of `load-path'. Of course, NOERROR isn't affected by | ||
858 | the 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 |