diff options
Diffstat (limited to 'lisp')
-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 |
7 files changed, 168 insertions, 1 deletions
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 | ||