diff options
-rw-r--r-- | init.el | 29 | ||||
-rw-r--r-- | lisp/+casing.el | 2 | ||||
-rw-r--r-- | lisp/+circe.el | 4 | ||||
-rw-r--r-- | lisp/+emacs.el | 9 | ||||
-rw-r--r-- | lisp/+flyspell-correct.el | 12 | ||||
-rw-r--r-- | lisp/+lookup.el | 3 | ||||
-rw-r--r-- | lisp/acdw.el | 61 | ||||
-rw-r--r-- | lisp/user-save.el | 78 |
8 files changed, 191 insertions, 7 deletions
diff --git a/init.el b/init.el index 07679e7..7f0733c 100644 --- a/init.el +++ b/init.el | |||
@@ -34,10 +34,15 @@ | |||
34 | "C-x 4 n" #'clone-buffer | 34 | "C-x 4 n" #'clone-buffer |
35 | "C-c v" #'visible-mode | 35 | "C-c v" #'visible-mode |
36 | "C-M-;" #'+lisp-comment-or-uncomment-sexp | 36 | "C-M-;" #'+lisp-comment-or-uncomment-sexp |
37 | "M-j" nil) | 37 | "M-j" nil |
38 | "C-x o" (lambda () (interactive) (switch-to-buffer nil)) | ||
39 | "C-x C-o" #'+open-paragraph | ||
40 | "C-w" #'+kill-word-backward-or-region) | ||
38 | ;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults | 41 | ;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults |
39 | (global-set-key (kbd "C-h") 'delete-backward-char) | 42 | (global-set-key (kbd "C-h") 'delete-backward-char) |
40 | (keyboard-translate ?\C-h ?\C-?) | 43 | (keyboard-translate ?\C-h ?\C-?) |
44 | ;; Hooks | ||
45 | ;; Advice | ||
41 | ;; https://old.reddit.com/r/emacs/comments/rlli0u/whats_your_favorite_defadvice/hph14un/ | 46 | ;; https://old.reddit.com/r/emacs/comments/rlli0u/whats_your_favorite_defadvice/hph14un/ |
42 | (define-advice keyboard-escape-quit (:around (fn &rest r)) | 47 | (define-advice keyboard-escape-quit (:around (fn &rest r)) |
43 | "Don't close splits on `keyboard-escape-quit'." | 48 | "Don't close splits on `keyboard-escape-quit'." |
@@ -104,6 +109,9 @@ | |||
104 | (setup (:require reading) | 109 | (setup (:require reading) |
105 | (:global "C-c C-r" #'reading-mode)) | 110 | (:global "C-c C-r" #'reading-mode)) |
106 | 111 | ||
112 | (setup (:require user-save) | ||
113 | (user-save-mode +1)) | ||
114 | |||
107 | (setup +key | 115 | (setup +key |
108 | (+ensure-after-init #'+key-global-mode)) | 116 | (+ensure-after-init #'+key-global-mode)) |
109 | 117 | ||
@@ -450,7 +458,7 @@ | |||
450 | "C-c C-l" #'+org-insert-link-dwim | 458 | "C-c C-l" #'+org-insert-link-dwim |
451 | "C-c C-n" #'+org-next-heading-widen | 459 | "C-c C-n" #'+org-next-heading-widen |
452 | "C-c C-p" #'+org-previous-heading-widen) | 460 | "C-c C-p" #'+org-previous-heading-widen) |
453 | (:local-hook before-save-hook #'+org-before-save@prettify-buffer) | 461 | (:local-hook user-save-hook #'+org-before-save@prettify-buffer) |
454 | (advice-add #'org-delete-backward-char :override #'+org-delete-backward-char) | 462 | (advice-add #'org-delete-backward-char :override #'+org-delete-backward-char) |
455 | (with-eval-after-load 'org | 463 | (with-eval-after-load 'org |
456 | (org-clock-persistence-insinuate) | 464 | (org-clock-persistence-insinuate) |
@@ -584,6 +592,7 @@ | |||
584 | (:require _circe | 592 | (:require _circe |
585 | +circe) | 593 | +circe) |
586 | (:also-load circe-chanop) | 594 | (:also-load circe-chanop) |
595 | (+ensure-after-init (lambda () (defalias 'irc '+irc "Start IRC."))) | ||
587 | 596 | ||
588 | ;; Formatting options | 597 | ;; Formatting options |
589 | (:option | 598 | (:option |
@@ -704,7 +713,11 @@ | |||
704 | (add-to-list '+pulse-location-commands #'lui-track-jump-to-indicator) | 713 | (add-to-list '+pulse-location-commands #'lui-track-jump-to-indicator) |
705 | (:hook #'visual-line-mode | 714 | (:hook #'visual-line-mode |
706 | #'enable-lui-track | 715 | #'enable-lui-track |
707 | #'visual-fill-column-mode) | 716 | #'visual-fill-column-mode |
717 | (defun +disable-electric-pair-mode () | ||
718 | "Disable `electric-pair-mode' in the current buffer." | ||
719 | (interactive) | ||
720 | (electric-pair-local-mode -1))) | ||
708 | (:local-set fringes-outside-margins t | 721 | (:local-set fringes-outside-margins t |
709 | right-margin-width (length lui-time-stamp-format) | 722 | right-margin-width (length lui-time-stamp-format) |
710 | scroll-margin 0 | 723 | scroll-margin 0 |
@@ -948,9 +961,11 @@ See also `crux-reopen-as-root-mode'." | |||
948 | (:+key "M-q" #'filldent-dwim)) | 961 | (:+key "M-q" #'filldent-dwim)) |
949 | 962 | ||
950 | (setup (:straight flyspell-correct) | 963 | (setup (:straight flyspell-correct) |
964 | (:+also-load +flyspell-correct ) | ||
951 | (:option flyspell-correct--cr-key ";") | 965 | (:option flyspell-correct--cr-key ";") |
952 | (:bind-into flyspell | 966 | (:bind-into flyspell |
953 | "C-;" #'flyspell-correct-wrapper)) | 967 | "C-;" #'flyspell-correct-wrapper |
968 | "<f7>" #'+flyspell-correct-buffer)) | ||
954 | 969 | ||
955 | (setup (:straight-when (forge | 970 | (setup (:straight-when (forge |
956 | :host github :repo "magit/forge") | 971 | :host github :repo "magit/forge") |
@@ -1136,7 +1151,9 @@ See also `crux-reopen-as-root-mode'." | |||
1136 | 1151 | ||
1137 | (setup (:straight paredit) | 1152 | (setup (:straight paredit) |
1138 | (:bind "DEL" #'paredit-backward-delete | 1153 | (:bind "DEL" #'paredit-backward-delete |
1139 | "C-<backspace>" #'paredit-backward-kill-word) | 1154 | "C-<backspace>" #'paredit-backward-kill-word |
1155 | "C-w" (lambda (r) (interactive "P") | ||
1156 | (+kill-word-backward-or-region r #'paredit-backward-kill-word))) | ||
1140 | (dolist (hook '(emacs-lisp-mode-hook | 1157 | (dolist (hook '(emacs-lisp-mode-hook |
1141 | eval-expression-minibuffer-setup-hook | 1158 | eval-expression-minibuffer-setup-hook |
1142 | ielm-mode-hook | 1159 | ielm-mode-hook |
@@ -1225,7 +1242,7 @@ See also `crux-reopen-as-root-mode'." | |||
1225 | :host github | 1242 | :host github |
1226 | :repo "duckwork/titlecase.el" | 1243 | :repo "duckwork/titlecase.el" |
1227 | :files ("*"))) | 1244 | :files ("*"))) |
1228 | (:with-map +casing-map | 1245 | (:with-map +casing-mode-map |
1229 | (:bind "t" #'titlecase-dwim))) | 1246 | (:bind "t" #'titlecase-dwim))) |
1230 | 1247 | ||
1231 | (setup (:straight topsy) | 1248 | (setup (:straight topsy) |
diff --git a/lisp/+casing.el b/lisp/+casing.el index a21e710..5f39b2e 100644 --- a/lisp/+casing.el +++ b/lisp/+casing.el | |||
@@ -75,5 +75,7 @@ Otherwise, it calls `capitalize-word' on the word at point (using | |||
75 | (define-key +key-mode-map (kbd "M-c") (when +casing-mode | 75 | (define-key +key-mode-map (kbd "M-c") (when +casing-mode |
76 | +casing-mode-map))) | 76 | +casing-mode-map))) |
77 | 77 | ||
78 | (defvaralias '+casing-map '+casing-mode-map) | ||
79 | |||
78 | (provide '+casing) | 80 | (provide '+casing) |
79 | ;;; +casing.el ends here | 81 | ;;; +casing.el ends here |
diff --git a/lisp/+circe.el b/lisp/+circe.el index 501bd21..c29cea6 100644 --- a/lisp/+circe.el +++ b/lisp/+circe.el | |||
@@ -165,6 +165,7 @@ See `circe-network-options' for a list of common options." | |||
165 | (funcall +circe-server-buffer-action buffer)))) | 165 | (funcall +circe-server-buffer-action buffer)))) |
166 | 166 | ||
167 | ;;; Chat commands | 167 | ;;; Chat commands |
168 | ;; TODO: Actually ... write these~!?!?! | ||
168 | 169 | ||
169 | (defun circe-command-SHORTEN (url) | 170 | (defun circe-command-SHORTEN (url) |
170 | "Shorten URL using `0x0-shorten-uri'.") | 171 | "Shorten URL using `0x0-shorten-uri'.") |
@@ -172,6 +173,9 @@ See `circe-network-options' for a list of common options." | |||
172 | (defun circe-command-SLAP (nick) | 173 | (defun circe-command-SLAP (nick) |
173 | "Slap NICK around a bit with a large trout.") | 174 | "Slap NICK around a bit with a large trout.") |
174 | 175 | ||
176 | (defun circe-command-POKE (nick) | ||
177 | "Poke NICK like in the old Facebook days.") | ||
178 | |||
175 | ;;; Pure idiocy | 179 | ;;; Pure idiocy |
176 | 180 | ||
177 | (define-minor-mode circe-cappy-hour-mode | 181 | (define-minor-mode circe-cappy-hour-mode |
diff --git a/lisp/+emacs.el b/lisp/+emacs.el index 7453913..ecdfeaa 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el | |||
@@ -220,6 +220,15 @@ kill without asking." | |||
220 | (save-buffers-kill-emacs)) | 220 | (save-buffers-kill-emacs)) |
221 | (delete-frame nil :force))) | 221 | (delete-frame nil :force))) |
222 | 222 | ||
223 | (defun +kill-word-backward-or-region (&optional arg backward-kill-word-fn) | ||
224 | "Kill active region or ARG words backward. | ||
225 | BACKWARD-KILL-WORD-FN is the function to call to kill a word | ||
226 | backward. It defaults to `backward-kill-word'." | ||
227 | (interactive "P") | ||
228 | (call-interactively (if (region-active-p) | ||
229 | #'kill-region | ||
230 | (or backward-kill-word-fn #'backward-kill-word)))) | ||
231 | |||
223 | ;; ... and advice | 232 | ;; ... and advice |
224 | 233 | ||
225 | ;; Indent the region after a yank. | 234 | ;; Indent the region after a yank. |
diff --git a/lisp/+flyspell-correct.el b/lisp/+flyspell-correct.el new file mode 100644 index 0000000..473b054 --- /dev/null +++ b/lisp/+flyspell-correct.el | |||
@@ -0,0 +1,12 @@ | |||
1 | ;;; +flyspell-correct.el --- -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Code: | ||
4 | |||
5 | (defun +flyspell-correct-buffer (&rest _) ; Enables this to be run as a hook | ||
6 | "Run `flyspell-correct-wrapper' on all misspelled words in the buffer." | ||
7 | (interactive) | ||
8 | (+with-message "Checking spelling" | ||
9 | (flyspell-correct-move (point-min) :forward :rapid))) | ||
10 | |||
11 | (provide '+flyspell-correct) | ||
12 | ;;; +flyspell-correct.el ends here | ||
diff --git a/lisp/+lookup.el b/lisp/+lookup.el index f13f535..755f84e 100644 --- a/lisp/+lookup.el +++ b/lisp/+lookup.el | |||
@@ -15,9 +15,12 @@ | |||
15 | :keymap (let ((map (make-sparse-keymap))) | 15 | :keymap (let ((map (make-sparse-keymap))) |
16 | (define-key map "f" #'find-function) | 16 | (define-key map "f" #'find-function) |
17 | (define-key map "l" #'find-library) | 17 | (define-key map "l" #'find-library) |
18 | (define-key map "v" #'find-variable) | ||
18 | map) | 19 | map) |
19 | (define-key +key-mode-map (kbd "C-c l") (when +lookup-mode | 20 | (define-key +key-mode-map (kbd "C-c l") (when +lookup-mode |
20 | +lookup-mode-map))) | 21 | +lookup-mode-map))) |
21 | 22 | ||
23 | (defvaralias '+lookup-map '+lookup-mode-map) | ||
24 | |||
22 | (provide '+lookup) | 25 | (provide '+lookup) |
23 | ;;; +lookup.el ends here | 26 | ;;; +lookup.el ends here |
diff --git a/lisp/acdw.el b/lisp/acdw.el index 71905d2..8b9c7b9 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el | |||
@@ -44,7 +44,6 @@ the filesystem, unless INHIBIT-MKDIR is non-nil." | |||
44 | (make-directory (file-name-directory file-name) :parents)) | 44 | (make-directory (file-name-directory file-name) :parents)) |
45 | file-name)))) | 45 | file-name)))) |
46 | 46 | ||
47 | |||
48 | (defun +suppress-messages (oldfn &rest args) ; from pkal | 47 | (defun +suppress-messages (oldfn &rest args) ; from pkal |
49 | "Advice wrapper for suppressing `message'. | 48 | "Advice wrapper for suppressing `message'. |
50 | OLDFN is the wrapped function, that is passed the arguments | 49 | OLDFN is the wrapped function, that is passed the arguments |
@@ -126,5 +125,65 @@ I keep forgetting how they differ." | |||
126 | (declare (doc-string 3)) | 125 | (declare (doc-string 3)) |
127 | `(setq ,var ,value)) | 126 | `(setq ,var ,value)) |
128 | 127 | ||
128 | (defmacro +with-message (message &rest body) | ||
129 | "Execute BODY, with MESSAGE. | ||
130 | If body executes without errors, MESSAGE...Done will be displayed." | ||
131 | ;; ^ TODO | ||
132 | `(prog1 (progn (message ,(concat message "...")) | ||
133 | ,@body) | ||
134 | (message ,(concat message "...Done.")))) | ||
135 | |||
136 | (defun +mapc-some-buffers (func &optional predicate) | ||
137 | "Perform FUNC on all buffers satisfied by PREDICATE. | ||
138 | By default, act on all buffers. | ||
139 | |||
140 | PREDICATE is a function called with one argument, the current | ||
141 | buffer. FUNC is called with no arguments. Both are called | ||
142 | within a `with-current-buffer' form." | ||
143 | (let ((pred (or predicate t))) | ||
144 | (dolist (buf (buffer-list)) | ||
145 | (with-current-buffer buf | ||
146 | (when (funcall pred buf) | ||
147 | (funcall func)))))) | ||
148 | |||
149 | ;; https://github.com/cstby/emacs.d/blob/main/init.el#L67 | ||
150 | (defun +clean-empty-lines (&optional begin end) | ||
151 | "Remove duplicate empty lines from BEGIN to END. | ||
152 | Called interactively, this function acts on the region, if | ||
153 | active, or else the entire buffer." | ||
154 | (interactive "*r") | ||
155 | (unless (region-active-p) | ||
156 | (setq begin (point-min) | ||
157 | end (save-excursion | ||
158 | (goto-char (point-max)) | ||
159 | (skip-chars-backward "\n[:space:]") | ||
160 | (point)))) | ||
161 | (save-excursion | ||
162 | (save-restriction | ||
163 | (narrow-to-region begin end) | ||
164 | (goto-char (point-min)) | ||
165 | (while (re-search-forward "\n\n\n+" nil :move) | ||
166 | (replace-match "\n\n")) | ||
167 | ;; Insert a newline at the end. | ||
168 | (goto-char (point-max)) | ||
169 | (unless (= (line-beginning-position) (line-end-position)) | ||
170 | (insert "\n"))))) | ||
171 | |||
172 | (defun +open-paragraph () | ||
173 | "Open a paragraph after paragraph at point. | ||
174 | A paragraph is defined as continguous non-empty lines of text | ||
175 | surrounded by empty lines, so opening a paragraph means to make | ||
176 | three blank lines, then place the point on the second one." | ||
177 | (interactive "*") | ||
178 | (unless (derived-mode-p 'special-mode 'lui-mode 'comint-mode) | ||
179 | ;; Go to next blank line. This /isn't/ `end-of-paragraph-text' because | ||
180 | ;; that's weird with org, and I'm guessing other modes too. | ||
181 | (while (not (looking-at "^$")) | ||
182 | (forward-line 1)) | ||
183 | (newline) | ||
184 | (delete-blank-lines) | ||
185 | (newline 2) | ||
186 | (previous-line))) | ||
187 | |||
129 | (provide 'acdw) | 188 | (provide 'acdw) |
130 | ;;; acdw.el ends here | 189 | ;;; acdw.el ends here |
diff --git a/lisp/user-save.el b/lisp/user-save.el new file mode 100644 index 0000000..63fe424 --- /dev/null +++ b/lisp/user-save.el | |||
@@ -0,0 +1,78 @@ | |||
1 | ;;; user-save.el -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;; Because `super-save-mode' automatically saves every time we move away from a | ||
4 | ;; buffer, it tends to run a lot of `before-save-hook's that don't need to be | ||
5 | ;; run that often. For that reason, I'm writing a mode where C-x C-s saves | ||
6 | ;; /and/ runs all the "real" before-save-hooks, so that super-save won't | ||
7 | ;; automatically do things like format the buffer all the time. | ||
8 | |||
9 | ;;; Code: | ||
10 | |||
11 | (defgroup user-save nil | ||
12 | "Group for `user-save-mode' customizations." | ||
13 | :group 'emacs | ||
14 | :prefix "user-save-") | ||
15 | |||
16 | (defcustom user-save-hook-into-kill-emacs nil | ||
17 | "Add a hook to perform `user-save' to `kill-emacs-hook'. | ||
18 | This option is only useful is `user-save-mode' is active when | ||
19 | Emacs is killed." | ||
20 | :type 'boolean) | ||
21 | |||
22 | (defvar user-save-hook nil | ||
23 | "Hook to run when the user, not Emacs, saves the buffer.") | ||
24 | |||
25 | (defvar user-save-mode-map (let ((map (make-sparse-keymap))) | ||
26 | (define-key map (kbd "C-x C-s") #'user-save-buffer) | ||
27 | map) | ||
28 | "Keymap for `user-save-mode'. | ||
29 | This map shadows the default map for `save-buffer'.") | ||
30 | |||
31 | (defun user-save-buffer (&optional arg) | ||
32 | "Save current buffer in visited file if modified. | ||
33 | This function is precisely the same as `save-buffer', but with | ||
34 | one modification: it also runs functions in `user-save-hook'. | ||
35 | This means that if you have some functionality in Emacs to | ||
36 | automatically save buffers periodically, but have hooks you want | ||
37 | to automatically run when the buffer saves that are | ||
38 | computationally expensive or just aren't something you want to | ||
39 | run all the time, put them in `user-save-hook'. | ||
40 | |||
41 | ARG is passed directly to `save-buffer'." | ||
42 | (interactive '(called-interactively)) | ||
43 | (message "Saving the buffer...") | ||
44 | (with-demoted-errors (run-hooks 'user-save-hook)) | ||
45 | (save-buffer arg) | ||
46 | (message "Saving the buffer...Done.")) | ||
47 | |||
48 | (defun user-save-some-buffers (&optional pred) | ||
49 | "Save some buffers as though the user saved them. | ||
50 | This function does not ask the user about each buffer, but PRED | ||
51 | is used in almost the same way as `save-some-buffers': if it's | ||
52 | nil or t, it will save all file-visiting modified buffers; if | ||
53 | it's a zero-argument function, that will be called to determine | ||
54 | whether the buffer needs to be saved." | ||
55 | ;; This could maybe be much better. | ||
56 | (interactive "P") | ||
57 | (unless pred (setq pred save-some-buffers-default-predicate)) | ||
58 | (dolist (buf (buffer-list)) | ||
59 | (with-current-buffer buf | ||
60 | (when (and (buffer-modified-p) | ||
61 | (buffer-file-name) | ||
62 | (or (null pred) | ||
63 | (if (functionp pred) (funcall pred) pred))) | ||
64 | (user-save-buffer))))) | ||
65 | |||
66 | ;;;###autoload | ||
67 | (define-minor-mode user-save-mode | ||
68 | "Mode to enable an an extra user-save hook." | ||
69 | :lighter " US" | ||
70 | :global t | ||
71 | :keymap 'user-save-mode-map | ||
72 | (if user-save-mode | ||
73 | (when user-save-hook-into-kill-emacs | ||
74 | (add-hook 'kill-emacs-hook #'user-save-some-buffers)) | ||
75 | (remove-hook 'kill-emacs-hook #'user-save-some-buffers))) | ||
76 | |||
77 | (provide 'user-save) | ||
78 | ;;; user-save.el ends here | ||