diff options
author | Case Duckworth | 2021-08-16 22:48:29 -0500 |
---|---|---|
committer | Case Duckworth | 2021-08-16 22:48:29 -0500 |
commit | a6fd6508c9f853df9f0a61079f2268cd88e3d5f7 (patch) | |
tree | 1e3eb323b6f44ed16f09a36e88624289080d7eef | |
parent | Change work font to Inter (diff) | |
download | emacs-a6fd6508c9f853df9f0a61079f2268cd88e3d5f7.tar.gz emacs-a6fd6508c9f853df9f0a61079f2268cd88e3d5f7.zip |
Break out functionality into other files
-rw-r--r-- | init.el | 178 | ||||
-rw-r--r-- | lisp/acdw-browse-url.el | 122 | ||||
-rw-r--r-- | lisp/acdw-consult.el | 37 | ||||
-rw-r--r-- | lisp/acdw-lisp.el | 25 | ||||
-rw-r--r-- | lisp/acdw.el | 79 |
5 files changed, 232 insertions, 209 deletions
diff --git a/init.el b/init.el index 550cb34..968627d 100644 --- a/init.el +++ b/init.el | |||
@@ -51,20 +51,8 @@ | |||
51 | ;;;; Compatibility with older versions | 51 | ;;;; Compatibility with older versions |
52 | (require 'acdw-compat) | 52 | (require 'acdw-compat) |
53 | 53 | ||
54 | 54 | ;;;; Lisp | |
55 | ;;;; Utility functions and variables | 55 | (require 'acdw-lisp) |
56 | ;; see also: `acdw' and friends. Functions here aren't big enough, or they're | ||
57 | ;; too tightly bound to stuff here, to be placed in `acdw'. | ||
58 | |||
59 | (defvar lispy-modes '(emacs-lisp-mode | ||
60 | eval-expression-minibuffer | ||
61 | ielm-mode | ||
62 | lisp-mode | ||
63 | lisp-interaction-mode | ||
64 | scheme-mode | ||
65 | slime-repl-mode | ||
66 | sly-mrepl-mode) | ||
67 | "List of modes that are lisp-like enough to hook packages into.") | ||
68 | 56 | ||
69 | 57 | ||
70 | ;;; Basics | 58 | ;;; Basics |
@@ -81,63 +69,26 @@ | |||
81 | (global-auto-revert-mode +1)) | 69 | (global-auto-revert-mode +1)) |
82 | 70 | ||
83 | (setup browse-url | 71 | (setup browse-url |
72 | (require 'acdw-browse-url) | ||
73 | |||
84 | (setq-default browse-url-secondary-browser-function | 74 | (setq-default browse-url-secondary-browser-function |
85 | (if (executable-find "firefox") ; prefer Firefox | 75 | (if (executable-find "firefox") ; prefer Firefox |
86 | 'browse-url-firefox | 76 | #'browse-url-firefox |
87 | 'browse-url-default-browser) | 77 | #'browse-url-default-browser) |
88 | browse-url-new-window-flag nil ; for eww | 78 | browse-url-new-window-flag nil ; for eww |
89 | browse-url-firefox-arguments '("--new-tab") ; for firefox | 79 | browse-url-firefox-arguments '("--new-tab") ; for firefox |
90 | browse-url-firefox-new-window-is-tab t) | 80 | browse-url-firefox-new-window-is-tab t) |
91 | 81 | ||
92 | (defvar browse-url-mpv-arguments nil | 82 | (acdw/browse-url-set-handlers |
93 | "Arguments to pass to mpv in `browse-url-mpv'.") | 83 | `(("\\.jpe?g\\'" . ,(if (executable-find "feh") |
94 | 84 | #'browse-url-feh | |
95 | (defun browse-url-mpv (url &optional new-window) | 85 | #'eww-browse-url)) |
96 | "Play `URL' in mpv." | 86 | ("youtube\\.com\\|youtu\\.be" . ,(if (executable-find "mpv") |
97 | (interactive (browse-url-interactive-arg "Video URL: ")) | 87 | #'browse-url-mpv |
98 | (ignore new-window) ;; mpv always opens a new window | 88 | #'eww-browse-url)) |
99 | (let* ((url (browse-url-encode-url url)) | 89 | ("google\\.com" . browse-url-default-browser) |
100 | (process-environment (browse-url-process-environment))) | 90 | ("\\(twitter\\.com\\|t\\.co\\)" . acdw/eww-browse-twitter-url) |
101 | (message "Playing %s in mpv..." url) | 91 | ("." . eww-browse-url))) |
102 | (apply #'start-process | ||
103 | (concat "mpv " url) nil | ||
104 | "mpv" | ||
105 | (append | ||
106 | browse-url-mpv-arguments | ||
107 | (list url))))) | ||
108 | |||
109 | (defvar browse-url-feh-arguments '("--auto-zoom" | ||
110 | "--geometry" "800x600") | ||
111 | "Arguments to pass to feh in `browse-url-feh'.") | ||
112 | |||
113 | (defun browse-url-feh (url &optional new-window) | ||
114 | "Open `URL' in feh." | ||
115 | (interactive (browse-url-interactive-arg "Video URL: ")) | ||
116 | (ignore new-window) ;; mpv always opens a new window | ||
117 | (let* ((url (browse-url-encode-url url)) | ||
118 | (process-environment (browse-url-process-environment))) | ||
119 | (message "Opening %s in feh..." url) | ||
120 | (apply #'start-process | ||
121 | (concat "feh " url) nil | ||
122 | "feh" | ||
123 | (append | ||
124 | browse-url-feh-arguments | ||
125 | (list url))))) | ||
126 | |||
127 | ;; `browse-url-browser-function' as an alist is deprecated in Emacs 28 for | ||
128 | ;; `browse-url-handlers'. | ||
129 | (set-default (if (version<= emacs-version "28") | ||
130 | 'browse-url-browser-function | ||
131 | 'browse-url-handlers) | ||
132 | `(("\\.jpe?g\\'" . ,(if (executable-find "feh") | ||
133 | 'browse-url-feh | ||
134 | 'eww-browse-url)) | ||
135 | ("youtube\\.com\\|youtu\\.be" . ,(if (executable-find "mpv") | ||
136 | 'browse-url-mpv | ||
137 | 'eww-browse-url)) | ||
138 | ("google\\.com" . browse-url-default-browser) | ||
139 | ("\\(twitter\\.com\\|t\\.co\\)" . acdw/eww-browse-twitter-url) | ||
140 | ("." . eww-browse-url))) | ||
141 | 92 | ||
142 | ;; Buttonize gemini:// links. | 93 | ;; Buttonize gemini:// links. |
143 | (acdw/add-button-url-regexp-protocol "gemini")) | 94 | (acdw/add-button-url-regexp-protocol "gemini")) |
@@ -270,24 +221,14 @@ | |||
270 | '("Setup" | 221 | '("Setup" |
271 | "\\(^\\s-*(setup +(?\\)\\(\\_<.+\\_>\\)" 2)))) | 222 | "\\(^\\s-*(setup +(?\\)\\(\\_<.+\\_>\\)" 2)))) |
272 | 223 | ||
273 | (defun acdw/eval-region-or-buffer () | ||
274 | (interactive) | ||
275 | (if (region-active-p) | ||
276 | (let ((begin (region-beginning)) | ||
277 | (end (region-end))) | ||
278 | (with-message (format "Evaluating %S -> %S" begin end) | ||
279 | (eval-region begin end))) | ||
280 | (with-message "Evaluating buffer" | ||
281 | (eval-buffer)))) | ||
282 | |||
283 | ;; Emulate slime's eval binds | 224 | ;; Emulate slime's eval binds |
284 | (:with-map emacs-lisp-mode-map | 225 | (:with-map emacs-lisp-mode-map |
285 | (:bind "C-c C-c" eval-defun | 226 | (:bind "C-c C-c" eval-defun |
286 | "C-c C-k" acdw/eval-region-or-buffer | 227 | "C-c C-k" acdw/eval-region-or-buffer |
287 | "C-c C-z" ielm)) | 228 | "C-c C-z" ielm)) |
288 | 229 | ||
289 | (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) | 230 | (add-hook 'emacs-lisp-mode-hook #'turn-on-eldoc-mode) |
290 | (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode) | 231 | (add-hook 'ielm-mode-hook #'turn-on-eldoc-mode) |
291 | 232 | ||
292 | (setup (:straight macrostep) | 233 | (setup (:straight macrostep) |
293 | (define-key emacs-lisp-mode-map (kbd "C-c e") #'macrostep-expand)) | 234 | (define-key emacs-lisp-mode-map (kbd "C-c e") #'macrostep-expand)) |
@@ -488,15 +429,9 @@ like a dumbass." | |||
488 | (unless (file-exists-p ispell-personal-dictionary) | 429 | (unless (file-exists-p ispell-personal-dictionary) |
489 | (write-region "" nil ispell-personal-dictionary nil 0)) | 430 | (write-region "" nil ispell-personal-dictionary nil 0)) |
490 | 431 | ||
491 | (defun flyspell-start () | ||
492 | "Start `flyspell-mode' or `flyspell-prog-mode', depending on current mode." | ||
493 | (cond ((derived-mode-p 'text-mode) | ||
494 | (flyspell-mode)) | ||
495 | ((derived-mode-p 'prog-mode) | ||
496 | (flyspell-prog-mode)))) | ||
497 | |||
498 | (when (executable-find ispell-program-name) | 432 | (when (executable-find ispell-program-name) |
499 | (add-hook 'change-major-mode-hook #'flyspell-start)) | 433 | (add-hook 'text-mode-hook #'flyspell-mode) |
434 | (add-hook 'prog-mode-hook #'flyspell-prog-mode)) | ||
500 | 435 | ||
501 | (:when-loaded | 436 | (:when-loaded |
502 | (setup (:straight flyspell-correct) | 437 | (setup (:straight flyspell-correct) |
@@ -556,9 +491,9 @@ like a dumbass." | |||
556 | (mode . eww-mode)))))) | 491 | (mode . eww-mode)))))) |
557 | (:global "C-x C-b" ibuffer) | 492 | (:global "C-x C-b" ibuffer) |
558 | 493 | ||
559 | (defun ibuffer-filter-to-default () | 494 | (add-hook 'ibuffer-mode |
560 | (ibuffer-switch-to-saved-filter-groups "default")) | 495 | (defun ibuffer@filter-to-default () |
561 | (:hook ibuffer-filter-to-default) | 496 | (ibuffer-switch-to-saved-filter-groups "default"))) |
562 | 497 | ||
563 | (:also-load ibuf-ext) | 498 | (:also-load ibuf-ext) |
564 | (:option ibuffer-show-empty-filter-groups nil | 499 | (:option ibuffer-show-empty-filter-groups nil |
@@ -693,7 +628,7 @@ like a dumbass." | |||
693 | regexp-search-ring | 628 | regexp-search-ring |
694 | search-ring | 629 | search-ring |
695 | mark-ring)) | 630 | mark-ring)) |
696 | (:option (append savehist-additional-variables) var)) | 631 | (add-to-list 'savehist-additional-variables var)) |
697 | 632 | ||
698 | (savehist-mode +1)) | 633 | (savehist-mode +1)) |
699 | 634 | ||
@@ -779,9 +714,6 @@ like a dumbass." | |||
779 | (:hook turn-on-auto-fill | 714 | (:hook turn-on-auto-fill |
780 | acdw/setup-fringes)) | 715 | acdw/setup-fringes)) |
781 | 716 | ||
782 | (setup (:straight typo) | ||
783 | (:hook-into text-mode)) | ||
784 | |||
785 | (setup uniquify | 717 | (setup uniquify |
786 | (:option uniquify-buffer-name-style 'forward | 718 | (:option uniquify-buffer-name-style 'forward |
787 | uniquify-separator path-separator | 719 | uniquify-separator path-separator |
@@ -840,14 +772,17 @@ like a dumbass." | |||
840 | ;; This should stay as /minimal/ as possible. Anything that can go somewhere | 772 | ;; This should stay as /minimal/ as possible. Anything that can go somewhere |
841 | ;; else /should/ go there. | 773 | ;; else /should/ go there. |
842 | (setup emacs | 774 | (setup emacs |
843 | (:option disabled-command-function nil | 775 | (:option |
844 | kill-read-only-ok t | 776 | attempt-orderly-shutdown-on-fatal-signal nil |
845 | load-prefer-newer t | 777 | attempt-stack-overflow-recovery nil |
846 | native-comp-async-report-warnings-errors nil | 778 | disabled-command-function nil |
847 | echo-keystrokes 0.01 | 779 | echo-keystrokes 0.01 |
848 | attempt-stack-overflow-recovery nil | 780 | find-function-C-source-directory (acdw/find-emacs-source) |
849 | attempt-orderly-shutdown-on-fatal-signal nil | 781 | kill-read-only-ok t |
850 | find-function-C-source-directory (acdw/find-emacs-source)) | 782 | load-prefer-newer t |
783 | native-comp-async-report-warnings-errors nil | ||
784 | set-mark-command-repeat-pop t | ||
785 | ) | ||
851 | 786 | ||
852 | (:global "M-=" count-words | 787 | (:global "M-=" count-words |
853 | "C-w" kill-region-or-backward-word | 788 | "C-w" kill-region-or-backward-word |
@@ -906,30 +841,7 @@ like a dumbass." | |||
906 | (setup (:straight (consult | 841 | (setup (:straight (consult |
907 | :host github | 842 | :host github |
908 | :repo "minad/consult")) | 843 | :repo "minad/consult")) |
909 | 844 | (require 'acdw-consult) | |
910 | ;; "Sensible" functions | ||
911 | (defun consult-sensible-grep (&optional arg) | ||
912 | "Perform `consult-git-grep' if in a git project, otherwise `consult-ripgrep' | ||
913 | if ripgrep is installed, otherwise `consult-grep'." | ||
914 | (interactive "P") | ||
915 | (cond ((executable-find "rg") | ||
916 | (call-interactively #'consult-ripgrep)) | ||
917 | ((string-equal (vc-backend buffer-file-name) "Git") | ||
918 | (call-interactively #'consult-git-grep)) | ||
919 | (t (call-interactively #'consult-grep)))) | ||
920 | |||
921 | (defun consult-sensible-find (&optional arg) | ||
922 | "Peform `consult-locate' if locate is installed, otehrwise `consult-find'." | ||
923 | (interactive "P") | ||
924 | (cond ((executable-find "locate") (call-interactively #'consult-locate)) | ||
925 | (t (call-interactively #'consult-find)))) | ||
926 | |||
927 | ;; Orderless Regexp Compiler! -- from Consult Wiki | ||
928 | (defun consult--orderless-regexp-compiler (input type) | ||
929 | (setq input (orderless-pattern-compiler input)) | ||
930 | (cons | ||
931 | (mapcar (lambda (r) (consult--convert-regexp r type)) input) | ||
932 | (lambda (str) (orderless--highlight input str)))) | ||
933 | 845 | ||
934 | (setq consult--regexp-compiler #'consult--orderless-regexp-compiler) | 846 | (setq consult--regexp-compiler #'consult--orderless-regexp-compiler) |
935 | 847 | ||
@@ -960,8 +872,8 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
960 | "M-g i" consult-imenu | 872 | "M-g i" consult-imenu |
961 | "M-g I" consult-project-imenu | 873 | "M-g I" consult-project-imenu |
962 | ;; M-s bindings (`search-map') | 874 | ;; M-s bindings (`search-map') |
963 | "M-s g" consult-sensible-grep | 875 | "M-s g" acdw-consult/sensible-grep |
964 | "M-s f" consult-sensible-find | 876 | "M-s f" acdw-consult/sensible-find |
965 | "M-s l" consult-line | 877 | "M-s l" consult-line |
966 | "M-s m" consult-multi-occur | 878 | "M-s m" consult-multi-occur |
967 | "M-s k" consult-keep-lines | 879 | "M-s k" consult-keep-lines |
@@ -991,12 +903,7 @@ if ripgrep is installed, otherwise `consult-grep'." | |||
991 | 903 | ||
992 | ;; Competion-at-point (complete-region) | 904 | ;; Competion-at-point (complete-region) |
993 | (:global "M-/" completion-at-point) | 905 | (:global "M-/" completion-at-point) |
994 | (:option completion-in-region-function | 906 | (:option completion-in-region-function #'acdw-consult/complete-in-region |
995 | (lambda (&rest args) | ||
996 | (apply (if vertico-mode | ||
997 | #'consult-completion-in-region | ||
998 | #'completion--in-region) | ||
999 | args)) | ||
1000 | completion-cycle-threshold 3 | 907 | completion-cycle-threshold 3 |
1001 | tab-always-indent 'complete) | 908 | tab-always-indent 'complete) |
1002 | 909 | ||
@@ -1154,7 +1061,9 @@ With any prefix argument | |||
1154 | successive invocations." | 1061 | successive invocations." |
1155 | (interactive "P") | 1062 | (interactive "P") |
1156 | (cond | 1063 | (cond |
1157 | (arg | 1064 | ((or arg |
1065 | (and set-mark-command-repeat-pop | ||
1066 | (eq last-command 'pop-to-mark-command))) | ||
1158 | (setq this-command 'set-mark-command) | 1067 | (setq this-command 'set-mark-command) |
1159 | (set-mark-command arg)) | 1068 | (set-mark-command arg)) |
1160 | ((eq last-command 'acdw/set-mark-or-expand-region) | 1069 | ((eq last-command 'acdw/set-mark-or-expand-region) |
@@ -1493,6 +1402,9 @@ successive invocations." | |||
1493 | (add-to-list 'auto-mode-alist spec)) | 1402 | (add-to-list 'auto-mode-alist spec)) |
1494 | (add-hook 'ssh-config-mode-hook #'turn-on-font-lock)) | 1403 | (add-hook 'ssh-config-mode-hook #'turn-on-font-lock)) |
1495 | 1404 | ||
1405 | (setup (:straight typo) | ||
1406 | (:hook-into text-mode)) | ||
1407 | |||
1496 | (setup (:straight undo-fu) | 1408 | (setup (:straight undo-fu) |
1497 | (:global "C-/" undo-fu-only-undo | 1409 | (:global "C-/" undo-fu-only-undo |
1498 | "C-?" undo-fu-only-redo)) | 1410 | "C-?" undo-fu-only-redo)) |
diff --git a/lisp/acdw-browse-url.el b/lisp/acdw-browse-url.el new file mode 100644 index 0000000..93f470c --- /dev/null +++ b/lisp/acdw-browse-url.el | |||
@@ -0,0 +1,122 @@ | |||
1 | ;;; acdw-browse-url.el -*- lexical-binding: t; coding: utf-8-unix -*- | ||
2 | ;; | ||
3 | ;; Add-ons to `browse-url'. | ||
4 | |||
5 | (defvar browse-url-mpv-arguments nil | ||
6 | "Arguments to pass to mpv in `browse-url-mpv'.") | ||
7 | |||
8 | (defun browse-url-mpv (url &optional new-window) | ||
9 | "Play `URL' in mpv." | ||
10 | (interactive (browse-url-interactive-arg "Video URL: ")) | ||
11 | (ignore new-window) ;; mpv always opens a new window | ||
12 | (let* ((url (browse-url-encode-url url)) | ||
13 | (process-environment (browse-url-process-environment))) | ||
14 | (message "Playing %s in mpv..." url) | ||
15 | (apply #'start-process | ||
16 | (concat "mpv " url) nil | ||
17 | "mpv" | ||
18 | (append | ||
19 | browse-url-mpv-arguments | ||
20 | (list url))))) | ||
21 | |||
22 | (defvar browse-url-feh-arguments '("--auto-zoom" | ||
23 | "--geometry" "800x600") | ||
24 | "Arguments to pass to feh in `browse-url-feh'.") | ||
25 | |||
26 | (defun browse-url-feh (url &optional new-window) | ||
27 | "Open `URL' in feh." | ||
28 | (interactive (browse-url-interactive-arg "Video URL: ")) | ||
29 | (ignore new-window) ;; mpv always opens a new window | ||
30 | (let* ((url (browse-url-encode-url url)) | ||
31 | (process-environment (browse-url-process-environment))) | ||
32 | (message "Opening %s in feh..." url) | ||
33 | (apply #'start-process | ||
34 | (concat "feh " url) nil | ||
35 | "feh" | ||
36 | (append | ||
37 | browse-url-feh-arguments | ||
38 | (list url))))) | ||
39 | |||
40 | (defun acdw/browse-url-set-handlers (handlers) | ||
41 | "Set handlers for `browse-url'. | ||
42 | If Emacs' version is 28 or higher, set `browse-url-handlers'. | ||
43 | Else, set `browse-url-browser-function'; it's deprecated in 28+." | ||
44 | (set-default (if (version< emacs-version "28") | ||
45 | #'browse-url-browser-function | ||
46 | #'browse-url-handlers) | ||
47 | handlers)) | ||
48 | |||
49 | ;;; URL regexp | ||
50 | ;; really, I just want to add gemini:// protocol, but I'm going to do some | ||
51 | ;; reverse-engineering here. | ||
52 | (defvar acdw/button-protocols '("http" | ||
53 | "https" | ||
54 | "shttp" | ||
55 | "shttps" | ||
56 | "ftp" | ||
57 | "file" | ||
58 | "gopher" | ||
59 | "nntp" | ||
60 | "news" | ||
61 | "telnet" | ||
62 | "wais" | ||
63 | "mailto" | ||
64 | "info") | ||
65 | "The list of protocols to splice into `browse-url-button-regexp'.") | ||
66 | |||
67 | (defun acdw/build-button-url-regexp () | ||
68 | "Build `browse-url-button-regexp' from `acdw/button-protocols'. | ||
69 | I used `xr' (not included in Emacs) to get the RX form of the | ||
70 | default, so I can easily splice the list into it. THIS IS | ||
71 | BRITTLE AF!!!" | ||
72 | (rx-to-string ; thanks wgreenhouse! | ||
73 | `(seq word-boundary | ||
74 | (group | ||
75 | (group | ||
76 | (or "www." | ||
77 | (seq | ||
78 | (group (or ,@acdw/button-protocols)) | ||
79 | ":"))) | ||
80 | (opt | ||
81 | (group "//" | ||
82 | (one-or-more | ||
83 | (any "0-9a-z" "._-")) | ||
84 | ":" | ||
85 | (zero-or-more | ||
86 | (any "0-9")))) | ||
87 | (or | ||
88 | (seq | ||
89 | (one-or-more | ||
90 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
91 | "(" | ||
92 | (one-or-more | ||
93 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
94 | (zero-or-more | ||
95 | (any "0-9a-z" "#$%&*+/=@\\_~-" word)) | ||
96 | ")" | ||
97 | (opt | ||
98 | (one-or-more | ||
99 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
100 | (any "0-9a-z" "#$%&*+/=@\\_~-" word))) | ||
101 | (seq | ||
102 | (one-or-more | ||
103 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
104 | (any "0-9a-z" "#$%&*+/=@\\_~-" word))))))) | ||
105 | |||
106 | (defun acdw/add-button-url-regexp-protocol (proto) | ||
107 | "Add PROTO to `browse-url-button-regexp' | ||
108 | First, add PROTO to `acdw/button-protocols'. | ||
109 | Then, build `browse-url-button-regexp' with the new protocol." | ||
110 | (add-to-list 'acdw/button-protocols proto) | ||
111 | (setq-default browse-url-button-regexp (acdw/build-button-url-regexp))) | ||
112 | |||
113 | ;;; Browse-URL tweaks | ||
114 | |||
115 | ;; convert twitter.com to nitter | ||
116 | (defun acdw/eww-browse-twitter-url (url &rest args) | ||
117 | "Browse a Twitter.com URL using Nitter." | ||
118 | (let* ((nitter "nitter.snopyta.org") | ||
119 | (url (replace-regexp-in-string "twitter\\.com" nitter url))) | ||
120 | (eww-browse-url url args))) | ||
121 | |||
122 | (provide 'acdw-browse-url) | ||
diff --git a/lisp/acdw-consult.el b/lisp/acdw-consult.el new file mode 100644 index 0000000..e6995f5 --- /dev/null +++ b/lisp/acdw-consult.el | |||
@@ -0,0 +1,37 @@ | |||
1 | ;;; acdw-consult.el -*- lexical-binding: t; coding: utf-8-unix -*- | ||
2 | |||
3 | ;; Customization for consult. | ||
4 | |||
5 | (require 'consult) | ||
6 | |||
7 | ;; "Sensible" functions | ||
8 | (defun acdw-consult/sensible-grep (&optional arg) | ||
9 | "Perform `consult-git-grep' if in a git project, otherwise `consult-ripgrep' | ||
10 | if ripgrep is installed, otherwise `consult-grep'." | ||
11 | (interactive "P") | ||
12 | (cond ((executable-find "rg") | ||
13 | (call-interactively #'consult-ripgrep)) | ||
14 | ((string-equal (vc-backend buffer-file-name) "Git") | ||
15 | (call-interactively #'consult-git-grep)) | ||
16 | (t (call-interactively #'consult-grep)))) | ||
17 | |||
18 | (defun acdw-consult/sensible-find (&optional arg) | ||
19 | "Peform `consult-locate' if locate is installed, otehrwise `consult-find'." | ||
20 | (interactive "P") | ||
21 | (cond ((executable-find "locate") (call-interactively #'consult-locate)) | ||
22 | (t (call-interactively #'consult-find)))) | ||
23 | |||
24 | ;; Orderless Regexp Compiler! -- from Consult Wiki | ||
25 | (defun consult--orderless-regexp-compiler (input type) | ||
26 | (setq input (orderless-pattern-compiler input)) | ||
27 | (cons | ||
28 | (mapcar (lambda (r) (consult--convert-regexp r type)) input) | ||
29 | (lambda (str) (orderless--highlight input str)))) | ||
30 | |||
31 | (defun acdw-consult/complete-in-region (&rest args) | ||
32 | (apply (if vertico-mode | ||
33 | #'consult-completion-in-region | ||
34 | #'completion--in-region) | ||
35 | args)) | ||
36 | |||
37 | (provide 'acdw-consult) | ||
diff --git a/lisp/acdw-lisp.el b/lisp/acdw-lisp.el new file mode 100644 index 0000000..8f551c9 --- /dev/null +++ b/lisp/acdw-lisp.el | |||
@@ -0,0 +1,25 @@ | |||
1 | ;;; acdw-lisp.el -*- lexical-binding: t; coding: utf-8-unix -*- | ||
2 | ;; | ||
3 | ;; Extras for Lisp modes. | ||
4 | |||
5 | (defvar lispy-modes '(emacs-lisp-mode | ||
6 | eval-expression-minibuffer | ||
7 | ielm-mode | ||
8 | lisp-mode | ||
9 | lisp-interaction-mode | ||
10 | scheme-mode | ||
11 | slime-repl-mode | ||
12 | sly-mrepl-mode) | ||
13 | "List of modes that are lisp-like enough to hook packages into.") | ||
14 | |||
15 | (defun acdw/eval-region-or-buffer () | ||
16 | (interactive) | ||
17 | (if (region-active-p) | ||
18 | (let ((begin (region-beginning)) | ||
19 | (end (region-end))) | ||
20 | (with-message (format "Evaluating %S -> %S" begin end) | ||
21 | (eval-region begin end))) | ||
22 | (with-message "Evaluating buffer" | ||
23 | (eval-buffer)))) | ||
24 | |||
25 | (provide 'acdw-lisp) | ||
diff --git a/lisp/acdw.el b/lisp/acdw.el index 2aa6c1f..8cbe16d 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el | |||
@@ -318,7 +318,9 @@ With a prefix argument, run git pull on the repo first." | |||
318 | (insert s) | 318 | (insert s) |
319 | (let ((sentence-end-double-space nil)) | 319 | (let ((sentence-end-double-space nil)) |
320 | (unfill-region (point-min) (point-max))) | 320 | (unfill-region (point-min) (point-max))) |
321 | (copy-region-as-kill (point-min) (point-max))))) | 321 | (copy-region-as-kill (point-min) (point-max)) |
322 | (when (called-interactively-p 'interactive) | ||
323 | (indicate-copied-region))))) | ||
322 | 324 | ||
323 | (defun acdw/dir (&optional file make-directory) | 325 | (defun acdw/dir (&optional file make-directory) |
324 | "Place Emacs files in one place. | 326 | "Place Emacs files in one place. |
@@ -443,81 +445,6 @@ It's called 'require-private' for historical reasons." | |||
443 | :noerror :nomessage)) | 445 | :noerror :nomessage)) |
444 | 446 | ||
445 | 447 | ||
446 | ;;; URL regexp | ||
447 | ;; really, I just want to add gemini:// protocol, but I'm going to do some | ||
448 | ;; reverse-engineering here. | ||
449 | |||
450 | (defvar acdw/button-protocols '("http" | ||
451 | "https" | ||
452 | "shttp" | ||
453 | "shttps" | ||
454 | "ftp" | ||
455 | "file" | ||
456 | "gopher" | ||
457 | "nntp" | ||
458 | "news" | ||
459 | "telnet" | ||
460 | "wais" | ||
461 | "mailto" | ||
462 | "info") | ||
463 | "The list of protocols to splice into `browse-url-button-regexp'.") | ||
464 | |||
465 | (defun acdw/build-button-url-regexp () | ||
466 | "Build `browse-url-button-regexp' from `acdw/button-protocols'. | ||
467 | I used `xr' (not included in Emacs) to get the RX form of the | ||
468 | default, so I can easily splice the list into it. THIS IS | ||
469 | BRITTLE AF!!!" | ||
470 | (rx-to-string ; thanks wgreenhouse! | ||
471 | `(seq word-boundary | ||
472 | (group | ||
473 | (group | ||
474 | (or "www." | ||
475 | (seq | ||
476 | (group (or ,@acdw/button-protocols)) | ||
477 | ":"))) | ||
478 | (opt | ||
479 | (group "//" | ||
480 | (one-or-more | ||
481 | (any "0-9a-z" "._-")) | ||
482 | ":" | ||
483 | (zero-or-more | ||
484 | (any "0-9")))) | ||
485 | (or | ||
486 | (seq | ||
487 | (one-or-more | ||
488 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
489 | "(" | ||
490 | (one-or-more | ||
491 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
492 | (zero-or-more | ||
493 | (any "0-9a-z" "#$%&*+/=@\\_~-" word)) | ||
494 | ")" | ||
495 | (opt | ||
496 | (one-or-more | ||
497 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
498 | (any "0-9a-z" "#$%&*+/=@\\_~-" word))) | ||
499 | (seq | ||
500 | (one-or-more | ||
501 | (any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word)) | ||
502 | (any "0-9a-z" "#$%&*+/=@\\_~-" word))))))) | ||
503 | |||
504 | (defun acdw/add-button-url-regexp-protocol (proto) | ||
505 | "Add PROTO to `browse-url-button-regexp' | ||
506 | First, add PROTO to `acdw/button-protocols'. | ||
507 | Then, build `browse-url-button-regexp' with the new protocol." | ||
508 | (add-to-list 'acdw/button-protocols proto) | ||
509 | (setq-default browse-url-button-regexp (acdw/build-button-url-regexp))) | ||
510 | |||
511 | ;;; Browse-URL tweaks | ||
512 | |||
513 | ;; convert twitter.com to nitter | ||
514 | (defun acdw/eww-browse-twitter-url (url &rest args) | ||
515 | "Browse a Twitter.com URL using Nitter." | ||
516 | (let* ((nitter "nitter.snopyta.org") | ||
517 | (url (replace-regexp-in-string "twitter\\.com" nitter url))) | ||
518 | (eww-browse-url url args))) | ||
519 | |||
520 | |||
521 | ;;; Recentf renaming with dired | 448 | ;;; Recentf renaming with dired |
522 | ;; from ... somewhere. 'rjs', apparently? | 449 | ;; from ... somewhere. 'rjs', apparently? |
523 | ;; I'm throwing these here because they look better here than in init.el. | 450 | ;; I'm throwing these here because they look better here than in init.el. |