diff options
-rw-r--r-- | early-init.el | 2 | ||||
-rw-r--r-- | init.el | 131 | ||||
-rw-r--r-- | lisp/acdw-compat.el | 71 |
3 files changed, 179 insertions, 25 deletions
diff --git a/early-init.el b/early-init.el index 90a2b0c..b964a5a 100644 --- a/early-init.el +++ b/early-init.el | |||
@@ -87,7 +87,7 @@ | |||
87 | (:work 12) | 87 | (:work 12) |
88 | (_ 10)) | 88 | (_ 10)) |
89 | acdw-fonts/variable (acdw/system | 89 | acdw-fonts/variable (acdw/system |
90 | (:home "DejaVu Sans") | 90 | (:home "Inter") |
91 | (:work "Calibri") | 91 | (:work "Calibri") |
92 | (_ "sans-serif")) | 92 | (_ "sans-serif")) |
93 | acdw-fonts/variable-size (acdw/system | 93 | acdw-fonts/variable-size (acdw/system |
diff --git a/init.el b/init.el index ee08c4d..6a62991 100644 --- a/init.el +++ b/init.el | |||
@@ -48,6 +48,9 @@ | |||
48 | ;;;; Private stuff | 48 | ;;;; Private stuff |
49 | (acdw/require-private) | 49 | (acdw/require-private) |
50 | 50 | ||
51 | ;;;; Compatibility with older versions | ||
52 | (require 'acdw-compat) | ||
53 | |||
51 | 54 | ||
52 | ;;;; Utility functions and variables | 55 | ;;;; Utility functions and variables |
53 | ;; see also: `acdw' and friends. Functions here aren't big enough, or they're | 56 | ;; see also: `acdw' and friends. Functions here aren't big enough, or they're |
@@ -367,8 +370,8 @@ | |||
367 | (apply f r)))) | 370 | (apply f r)))) |
368 | 371 | ||
369 | (:hook erc-autoaway-mode | 372 | (:hook erc-autoaway-mode |
370 | erc-track-mode | 373 | erc-track-mode |
371 | erc-truncate-mode) | 374 | erc-truncate-mode) |
372 | 375 | ||
373 | (:bind "C-c C-b" acdw-erc/erc-switch-to-buffer | 376 | (:bind "C-c C-b" acdw-erc/erc-switch-to-buffer |
374 | "C-c C-c" nil ; def: `erc-toggle-interpret-controls' | 377 | "C-c C-c" nil ; def: `erc-toggle-interpret-controls' |
@@ -419,9 +422,11 @@ like a dumbass." | |||
419 | ;; Define keys | 422 | ;; Define keys |
420 | (dolist (spec '(("C-d" . eshell-quit-or-delete-char))) | 423 | (dolist (spec '(("C-d" . eshell-quit-or-delete-char))) |
421 | (define-key eshell-mode-map (kbd (car spec)) (function (cdr spec)))) | 424 | (define-key eshell-mode-map (kbd (car spec)) (function (cdr spec)))) |
422 | ;; Etc. | 425 | ;; Fix modeline |
423 | (when (boundp 'simple-modeline--mode-line) | 426 | (when (boundp 'simple-modeline--mode-line) |
424 | (setq mode-line-format '(:eval simple-modeline--mode-line)))) | 427 | (setq mode-line-format '(:eval simple-modeline--mode-line))) |
428 | ;; Set outline-regexp for consult-outline | ||
429 | (setq outline-regexp eshell-prompt-regexp)) | ||
425 | 430 | ||
426 | (defun eshell-buffer-name () | 431 | (defun eshell-buffer-name () |
427 | (rename-buffer (concat "*eshell*<" (eshell/pwd) ">") t)) | 432 | (rename-buffer (concat "*eshell*<" (eshell/pwd) ">") t)) |
@@ -605,6 +610,13 @@ like a dumbass." | |||
605 | (minibuffer-electric-default-mode +1) | 610 | (minibuffer-electric-default-mode +1) |
606 | (fset 'yes-or-no-p #'y-or-n-p)) | 611 | (fset 'yes-or-no-p #'y-or-n-p)) |
607 | 612 | ||
613 | (setup page | ||
614 | (defun recenter-to-top (&rest _args) | ||
615 | "Recenter the cursor to the top of the window." | ||
616 | (recenter 0)) | ||
617 | (:advise forward-page :after #'recenter-to-top | ||
618 | backward-page :after #'recenter-to-top)) | ||
619 | |||
608 | (setup prog | 620 | (setup prog |
609 | (:option smie-indent-basic tab-width) | 621 | (:option smie-indent-basic tab-width) |
610 | 622 | ||
@@ -826,13 +838,15 @@ like a dumbass." | |||
826 | (:global "M-=" count-words | 838 | (:global "M-=" count-words |
827 | "C-w" kill-region-or-backward-word | 839 | "C-w" kill-region-or-backward-word |
828 | "<help> h" nil ; HELLO takes a long time to load on Windows | 840 | "<help> h" nil ; HELLO takes a long time to load on Windows |
829 | ) | 841 | "M-c" capitalize-dwim |
842 | "M-u" upcase-dwim | ||
843 | "M-l" downcase-dwim) | ||
830 | 844 | ||
831 | ;; (when (display-graphic-p) | 845 | ;; (when (display-graphic-p) |
832 | ;; (:global "<escape>" keyboard-escape-quit)) | 846 | ;; (:global "<escape>" keyboard-escape-quit)) |
833 | 847 | ||
834 | ;; Remap C-h to DEL -- <f1> can be the "help" key | 848 | ;; Remap C-h to DEL -- <f1> can be the "help" key |
835 | (define-key key-translation-map [?\C-h] [?\C-?]) | 849 | ;; (define-key key-translation-map [?\C-h] [?\C-?]) |
836 | 850 | ||
837 | (:global "C-c t" acdw/insert-iso-date | 851 | (:global "C-c t" acdw/insert-iso-date |
838 | "C-z" nil)) | 852 | "C-z" nil)) |
@@ -890,10 +904,10 @@ like a dumbass." | |||
890 | "Perform `consult-git-grep' if in a git project, otherwise `consult-ripgrep' | 904 | "Perform `consult-git-grep' if in a git project, otherwise `consult-ripgrep' |
891 | if ripgrep is installed, otherwise `consult-grep'." | 905 | if ripgrep is installed, otherwise `consult-grep'." |
892 | (interactive "P") | 906 | (interactive "P") |
893 | (cond ((string-equal (vc-backend buffer-file-name) "Git") | 907 | (cond ((executable-find "rg") |
894 | (call-interactively #'consult-git-grep)) | ||
895 | ((executable-find "rg") | ||
896 | (call-interactively #'consult-ripgrep)) | 908 | (call-interactively #'consult-ripgrep)) |
909 | ((string-equal (vc-backend buffer-file-name) "Git") | ||
910 | (call-interactively #'consult-git-grep)) | ||
897 | (t (call-interactively #'consult-grep)))) | 911 | (t (call-interactively #'consult-grep)))) |
898 | 912 | ||
899 | (defun consult-sensible-find (&optional arg) | 913 | (defun consult-sensible-find (&optional arg) |
@@ -902,6 +916,15 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
902 | (cond ((executable-find "locate") (call-interactively #'consult-locate)) | 916 | (cond ((executable-find "locate") (call-interactively #'consult-locate)) |
903 | (t (call-interactively #'consult-find)))) | 917 | (t (call-interactively #'consult-find)))) |
904 | 918 | ||
919 | ;; Orderless Regexp Compiler! -- from Consult Wiki | ||
920 | (defun consult--orderless-regexp-compiler (input type) | ||
921 | (setq input (orderless-pattern-compiler input)) | ||
922 | (cons | ||
923 | (mapcar (lambda (r) (consult--convert-regexp r type)) input) | ||
924 | (lambda (str) (orderless--highlight input str)))) | ||
925 | |||
926 | (setq consult--regexp-compiler #'consult--orderless-regexp-compiler) | ||
927 | |||
905 | ;; Bindings | 928 | ;; Bindings |
906 | (:global | 929 | (:global |
907 | ;; C-c bindings (`mode-specific-map') | 930 | ;; C-c bindings (`mode-specific-map') |
@@ -913,6 +936,7 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
913 | ;; C-x bindings (`ctl-x-map') | 936 | ;; C-x bindings (`ctl-x-map') |
914 | "C-x M-:" consult-complex-command | 937 | "C-x M-:" consult-complex-command |
915 | "C-x b" consult-buffer | 938 | "C-x b" consult-buffer |
939 | "<f1>" consult-buffer ; trying this out ... | ||
916 | "C-x 4 b" consult-buffer-other-window | 940 | "C-x 4 b" consult-buffer-other-window |
917 | "C-x 5 b" consult-buffer-other-frame | 941 | "C-x 5 b" consult-buffer-other-frame |
918 | ;; Custom M-# bindings for fast register access | 942 | ;; Custom M-# bindings for fast register access |
@@ -977,7 +1001,16 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
977 | (defun crm-indicator (args) | 1001 | (defun crm-indicator (args) |
978 | (cons (concat "[CRM] " (car args)) (cdr args))) | 1002 | (cons (concat "[CRM] " (car args)) (cdr args))) |
979 | (:advise completing-read-multiple | 1003 | (:advise completing-read-multiple |
980 | :filter-args #'crm-indicator))) | 1004 | :filter-args #'crm-indicator)) |
1005 | |||
1006 | (with-eval-after-load 'vertico | ||
1007 | (with-eval-after-load 'consult | ||
1008 | (define-key consult-crm-map "\r" #'+vertico-crm-exit) | ||
1009 | (define-key consult-crm-map "\t" #'vertico-exit) | ||
1010 | (defun +vertico-crm-exit () | ||
1011 | (interactive) | ||
1012 | (run-at-time 0 nil #'vertico-exit) | ||
1013 | (funcall #'vertico-exit))))) | ||
981 | 1014 | ||
982 | (setup (:straight crux) | 1015 | (setup (:straight crux) |
983 | 1016 | ||
@@ -985,7 +1018,9 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
985 | "C-o" crux-smart-open-line | 1018 | "C-o" crux-smart-open-line |
986 | "M-o" crux-smart-open-line-above | 1019 | "M-o" crux-smart-open-line-above |
987 | "C-M-\\" crux-cleanup-buffer-or-region | 1020 | "C-M-\\" crux-cleanup-buffer-or-region |
988 | "C-x 4 t" crux-transpose-windows)) | 1021 | "C-x 4 t" crux-transpose-windows) |
1022 | |||
1023 | (crux-reopen-as-root-mode +1)) | ||
989 | 1024 | ||
990 | ;; requires extension: | 1025 | ;; requires extension: |
991 | ;; https://addons.mozilla.org/en-US/firefox/addon/edit-with-emacs1/ | 1026 | ;; https://addons.mozilla.org/en-US/firefox/addon/edit-with-emacs1/ |
@@ -1031,8 +1066,7 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
1031 | (require 'gemini-write)))) | 1066 | (require 'gemini-write)))) |
1032 | 1067 | ||
1033 | (setup (:straight embark) | 1068 | (setup (:straight embark) |
1034 | (:global "C-." embark-act | 1069 | (:global "C-." embark-act) |
1035 | "C-;" embark-dwim) | ||
1036 | (:option prefix-help-command #'embark-prefix-help-command | 1070 | (:option prefix-help-command #'embark-prefix-help-command |
1037 | (append display-buffer-alist) | 1071 | (append display-buffer-alist) |
1038 | '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" | 1072 | '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" |
@@ -1208,7 +1242,57 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
1208 | :host github | 1242 | :host github |
1209 | :repo "oantolin/orderless")) | 1243 | :repo "oantolin/orderless")) |
1210 | (require 'orderless) | 1244 | (require 'orderless) |
1211 | (:option (append completion-styles) 'orderless)) | 1245 | |
1246 | (:option (append completion-styles) 'orderless | ||
1247 | orderless-component-separator #'orderless-escapable-split-on-space | ||
1248 | orderless-style-dispatchers '(acdw/orderless-dispatch)) | ||
1249 | |||
1250 | (defun fix-dollar (args) | ||
1251 | (if (string-suffix-p "$" (car args)) | ||
1252 | (list (concat (substring (car args) 0 -1) "[\x100000-\x10FFFD]*$")) | ||
1253 | args)) | ||
1254 | (advice-add #'orderless-regexp :filter-args #'fix-dollar) | ||
1255 | |||
1256 | (defun acdw/orderless-dispatch (pattern _index _total) | ||
1257 | "My custom dispatcher for `orderless'." | ||
1258 | (cond | ||
1259 | ;; Ensure that $ works with Consult commands, which add disambiguation | ||
1260 | ;; suffixes -- see `fix-dollar' | ||
1261 | ((string-suffix-p "$" pattern) | ||
1262 | `(orderless-regexp . ,(concat (substring pattern 0 -1) | ||
1263 | "[\x100000-\x10FFFD]*$"))) | ||
1264 | ;; File extensions | ||
1265 | ((string-match-p "\\`\\.." pattern) | ||
1266 | `(orderless-regexp . ,(concat "\\." (substring pattern 1) | ||
1267 | "[\x100000-\x10FFFD]*$"))) | ||
1268 | ;; Ignore single ! | ||
1269 | ((string= "!" pattern) | ||
1270 | `(orderless-literal . "")) | ||
1271 | ;; Character folding | ||
1272 | ((string-prefix-p "%" pattern) | ||
1273 | `(char-fold-to-regexp . ,(substring pattern 1))) | ||
1274 | ((string-suffix-p "%" pattern) | ||
1275 | `(char-fold-to-regexp . ,(substring pattern 0 -1))) | ||
1276 | ;; Without literal | ||
1277 | ((string-prefix-p "!" pattern) | ||
1278 | `(orderless-without-literal . ,(substring pattern 1))) | ||
1279 | ((string-suffix-p "!" pattern) | ||
1280 | `(orderless-without-literal . ,(substring pattern 0 -1))) | ||
1281 | ;; Initialism matching | ||
1282 | ((string-prefix-p "`" pattern) | ||
1283 | `(orderless-initialism . ,(substring pattern 1))) | ||
1284 | ((string-suffix-p "`" pattern) | ||
1285 | `(orderless-initialism . ,(substring pattern 0 -1))) | ||
1286 | ;; Literal matching | ||
1287 | ((string-prefix-p "=" pattern) | ||
1288 | `(orderless-literal . ,(substring pattern 1))) | ||
1289 | ((string-suffix-p "=" pattern) | ||
1290 | `(orderless-literal . ,(substring pattern 0 -1))) | ||
1291 | ;; Flex matching | ||
1292 | ((string-prefix-p "~" pattern) | ||
1293 | `(orderless-flex . ,(substring pattern 1))) | ||
1294 | ((string-suffix-p "~" pattern) | ||
1295 | `(orderless-flex . ,(substring pattern 0 -1)))))) | ||
1212 | 1296 | ||
1213 | (setup (:straight org) | 1297 | (setup (:straight org) |
1214 | (:straight org-contrib) | 1298 | (:straight org-contrib) |
@@ -1383,16 +1467,15 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
1383 | (:also-load vertico-mouse) | 1467 | (:also-load vertico-mouse) |
1384 | (vertico-mouse-mode +1) | 1468 | (vertico-mouse-mode +1) |
1385 | 1469 | ||
1386 | ;; Workarounds! | 1470 | ;; Prefix the current candidate with ": ". From Vertico wiki. |
1387 | ;; (with-eval-after-load 'org | 1471 | (advice-add #'vertico--format-candidate :around |
1388 | ;; (when (version< org-version "9.5") | 1472 | (lambda (orig cand prefix suffix index _start) |
1389 | ;; (defun disable-selection () | 1473 | (setq cand (funcall orig cand prefix suffix index _start)) |
1390 | ;; (when (eq minibuffer-completion-table #'org-tags-completion-function) | 1474 | (concat |
1391 | ;; (setq-local vertico-map minibuffer-local-completion-map | 1475 | (if (= vertico--index index) |
1392 | ;; completion-cycle-threshold nil | 1476 | (propertize ": " 'face 'vertico-current) |
1393 | ;; completion-styles '(basic)))) | 1477 | " ") |
1394 | ;; (advice-add #'vertico--setup :before #'disable-selection))) | 1478 | cand)))) |
1395 | ) | ||
1396 | 1479 | ||
1397 | (setup (:straight vuiet) | 1480 | (setup (:straight vuiet) |
1398 | (:needs "youtube-dl" | 1481 | (:needs "youtube-dl" |
diff --git a/lisp/acdw-compat.el b/lisp/acdw-compat.el new file mode 100644 index 0000000..b77527c --- /dev/null +++ b/lisp/acdw-compat.el | |||
@@ -0,0 +1,71 @@ | |||
1 | ;;; acdw-compat.el -*- lexical-binding: t; coding: utf-8-unix -*- | ||
2 | |||
3 | ;; Author: Case Duckworth <acdw@acdw.net> | ||
4 | ;; Created: 2021-08-11 | ||
5 | ;; Keywords: configuration | ||
6 | ;; URL: https://tildegit.org/acdw/emacs | ||
7 | |||
8 | ;; This file is NOT part of GNU Emacs. | ||
9 | |||
10 | ;;; License: | ||
11 | ;; Everyone is permitted to do whatever with this software, without | ||
12 | ;; limitation. This software comes without any warranty whatsoever, | ||
13 | ;; but with two pieces of advice: | ||
14 | ;; - Don't hurt yourself. | ||
15 | ;; - Make good choices. | ||
16 | |||
17 | ;;; Commentary: | ||
18 | |||
19 | ;; This file contains functions, variables, and other code that might not be in | ||
20 | ;; every version of Emacs I use. | ||
21 | |||
22 | ;;; Code: | ||
23 | |||
24 | ;; Convenience macro | ||
25 | (defmacro safe-defun (name arglist &optional docstring &rest body) | ||
26 | "Like `defun', but only if the function doesn't already exist. | ||
27 | |||
28 | Is it necessary? Who knows! | ||
29 | |||
30 | \(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)" | ||
31 | (declare (doc-string 3) | ||
32 | (indent 2)) | ||
33 | `(unless (fboundp (function ,name)) | ||
34 | (defun ,name ,@body))) | ||
35 | |||
36 | |||
37 | ;;; Functions for changing capitalization that Do What I Mean | ||
38 | ;; Defined in /usr/share/emacs/28.0.50/lisp/simple.el | ||
39 | |||
40 | (safe-defun upcase-dwim (arg) | ||
41 | "Upcase words in the region, if active; if not, upcase word at point. | ||
42 | If the region is active, this function calls `upcase-region'. | ||
43 | Otherwise, it calls `upcase-word', with prefix argument passed to it | ||
44 | to upcase ARG words." | ||
45 | (interactive "*p") | ||
46 | (if (use-region-p) | ||
47 | (upcase-region (region-beginning) (region-end) (region-noncontiguous-p)) | ||
48 | (upcase-word arg))) | ||
49 | |||
50 | (safe-defun downcase-dwim (arg) | ||
51 | "Downcase words in the region, if active; if not, downcase word at point. | ||
52 | If the region is active, this function calls `downcase-region'. | ||
53 | Otherwise, it calls `downcase-word', with prefix argument passed to it | ||
54 | to downcase ARG words." | ||
55 | (interactive "*p") | ||
56 | (if (use-region-p) | ||
57 | (downcase-region (region-beginning) (region-end) (region-noncontiguous-p)) | ||
58 | (downcase-word arg))) | ||
59 | |||
60 | (safe-defun capitalize-dwim (arg) | ||
61 | "Capitalize words in the region, if active; if not, capitalize word at point. | ||
62 | If the region is active, this function calls `capitalize-region'. | ||
63 | Otherwise, it calls `capitalize-word', with prefix argument passed to it | ||
64 | to capitalize ARG words." | ||
65 | (interactive "*p") | ||
66 | (if (use-region-p) | ||
67 | (capitalize-region (region-beginning) (region-end) (region-noncontiguous-p)) | ||
68 | (capitalize-word arg))) | ||
69 | |||
70 | (provide 'acdw-compat) | ||
71 | ;;; acdw-compat.el ends here | ||