diff options
Diffstat (limited to 'init.el')
-rw-r--r-- | init.el | 178 |
1 files changed, 45 insertions, 133 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)) |