summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-08-15 21:27:09 -0500
committerCase Duckworth2021-08-15 21:27:09 -0500
commit48301bdcfeb29783b9704991ae104c375d9972ea (patch)
treebea0673f52ff7913eab977b02778f3a122977993
parentDisconnect erc on kill-emacs (diff)
parentUm-lambdafy a variable (diff)
downloademacs-48301bdcfeb29783b9704991ae104c375d9972ea.tar.gz
emacs-48301bdcfeb29783b9704991ae104c375d9972ea.zip
Merge branch 'main' of tildegit.org:acdw/emacs
-rw-r--r--init.el157
-rw-r--r--lisp/acdw-org.el97
-rw-r--r--lisp/acdw.el31
3 files changed, 127 insertions, 158 deletions
diff --git a/init.el b/init.el index 208cfe8..cbdec9a 100644 --- a/init.el +++ b/init.el
@@ -19,7 +19,7 @@
19;;; Setup 19;;; Setup
20 20
21;;;; `setup' 21;;;; `setup'
22(straight-use-package '(setup :host nil :repo "https://git.sr.ht/~zge/setup")) 22(straight-use-package '(setup :host nil :repo "https://git.sr.ht/~pkal/setup"))
23(require 'setup) 23(require 'setup)
24 24
25(setup setup 25(setup setup
@@ -174,25 +174,31 @@
174 custom-unlispify-tag-names nil 174 custom-unlispify-tag-names nil
175 custom-variable-default-form 'lisp) 175 custom-variable-default-form 'lisp)
176 176
177 (defun unpackaged/custom-toggle-all-more-hide (&rest _) 177 ;; `Custom-mode-hook' fires /before/ the widgets are built, so I have to
178 "Toggle all \"More/Hide\" widgets in current buffer." 178 ;; install advice after the widgets are made.
179 (interactive) 179 (advice-add
180 (widget-map-buttons (lambda (widget _) 180 'custom-buffer-create :after
181 (pcase (widget-get widget :off) 181 (defun custom-buffer@expand-widgets (&rest _)
182 ("More" (widget-apply-action widget))) 182 "Expand descriptions and values of variables in `Custom-mode' buffers."
183 nil))) 183 (interactive)
184 (advice-add 'custom-buffer-create 184 ;; "More/Hide" widgets (thanks alphapapa!)
185 :after #'unpackaged/custom-toggle-all-more-hide) 185 (widget-map-buttons (lambda (widget _)
186 186 (pcase (widget-get widget :off)
187 (defun acdw/custom-toggle-showing-all-values (&rest _) 187 ("More" (widget-apply-action widget)))
188 "Toggle all \"Show Value\" widgets in current buffer." 188 nil))
189 (interactive) 189 ;; "Show Value" widgets (the little triangles)
190 (widget-map-buttons (lambda (widget _) 190 (widget-map-buttons (lambda (widget _)
191 (pcase (widget-get widget :off) 191 (pcase (widget-get widget :off)
192 ("Show Value" (widget-apply-action widget))) 192 ("Show Value" (widget-apply-action widget)))
193 nil))) 193 nil))))
194 (advice-add 'custom-buffer-create 194
195 :after #'acdw/custom-toggle-showing-all-values)) 195 (add-hook ; thanks u/oantolin!
196 'Custom-mode-hook
197 (defun custom-mode@imenu ()
198 "Build `imenu' for `Custom-mode'."
199 (setq imenu-generic-expression
200 '(("Faces" "^\\(?:Show\\|Hide\\) \\(.*\\) face: \\[sample\\]" 1)
201 ("Variables" "^\\(?:Show Value\\|Hide\\) \\([^:\n]*\\)" 1))))))
196 202
197(setup debugger 203(setup debugger
198 (:hook visual-line-mode) 204 (:hook visual-line-mode)
@@ -337,8 +343,7 @@
337 erc-fill-static-center 14 343 erc-fill-static-center 14
338 erc-format-nick-function #'erc-format-truncate-@nick 344 erc-format-nick-function #'erc-format-truncate-@nick
339 erc-header-line-face-method #'erc/update-header-line-show-disconnected 345 erc-header-line-face-method #'erc/update-header-line-show-disconnected
340 erc-hide-list '("NICK" "MODE" "JOIN" "NICK" "PART" "QUIT" 346 erc-hide-list '("NICK" "MODE" "JOIN" "PART" "QUIT")
341 "324" "329" "332" "333" "353" "477")
342 erc-interpret-controls-p t 347 erc-interpret-controls-p t
343 erc-interpret-mirc-color t 348 erc-interpret-mirc-color t
344 erc-join-buffer 'bury 349 erc-join-buffer 'bury
@@ -347,7 +352,7 @@
347 erc-kill-server-buffer-on-quit t 352 erc-kill-server-buffer-on-quit t
348 erc-nick "acdw" 353 erc-nick "acdw"
349 erc-nick-truncate (- erc-fill-static-center 1) 354 erc-nick-truncate (- erc-fill-static-center 1)
350 erc-prompt (lambda () (acdw-erc/prompt)) 355 erc-prompt #'acdw-erc/prompt
351 erc-prompt-for-password nil ; use ~/.authinfo 356 erc-prompt-for-password nil ; use ~/.authinfo
352 erc-rename-buffers t 357 erc-rename-buffers t
353 erc-server erc-default-server 358 erc-server erc-default-server
@@ -356,7 +361,8 @@
356 (mapcar #'car erc-autojoin-channels-alist)) 361 (mapcar #'car erc-autojoin-channels-alist))
357 erc-server-coding-system '(utf-8 . utf-8) 362 erc-server-coding-system '(utf-8 . utf-8)
358 erc-track-exclude-types (append erc-hide-list 363 erc-track-exclude-types (append erc-hide-list
359 '("AWAY")) 364 '("AWAY"
365 "353" "324" "329" "332" "333" "477"))
360 erc-track-exclude-server-buffer t 366 erc-track-exclude-server-buffer t
361 erc-track-position-in-mode-line 'before-modes 367 erc-track-position-in-mode-line 'before-modes
362 erc-track-visibility nil ; only the selected frame 368 erc-track-visibility nil ; only the selected frame
@@ -845,12 +851,6 @@ like a dumbass."
845 "M-u" upcase-dwim 851 "M-u" upcase-dwim
846 "M-l" downcase-dwim) 852 "M-l" downcase-dwim)
847 853
848 ;; (when (display-graphic-p)
849 ;; (:global "<escape>" keyboard-escape-quit))
850
851 ;; Remap C-h to DEL -- <f1> can be the "help" key
852 ;; (define-key key-translation-map [?\C-h] [?\C-?])
853
854 (:global "C-c t" acdw/insert-iso-date 854 (:global "C-c t" acdw/insert-iso-date
855 "C-z" nil)) 855 "C-z" nil))
856 856
@@ -939,7 +939,6 @@ if ripgrep is installed, otherwise `consult-grep'."
939 ;; C-x bindings (`ctl-x-map') 939 ;; C-x bindings (`ctl-x-map')
940 "C-x M-:" consult-complex-command 940 "C-x M-:" consult-complex-command
941 "C-x b" consult-buffer 941 "C-x b" consult-buffer
942 "<f1>" consult-buffer ; trying this out ...
943 "C-x 4 b" consult-buffer-other-window 942 "C-x 4 b" consult-buffer-other-window
944 "C-x 5 b" consult-buffer-other-frame 943 "C-x 5 b" consult-buffer-other-frame
945 ;; Custom M-# bindings for fast register access 944 ;; Custom M-# bindings for fast register access
@@ -1006,15 +1005,14 @@ if ripgrep is installed, otherwise `consult-grep'."
1006 (:advise completing-read-multiple 1005 (:advise completing-read-multiple
1007 :filter-args #'crm-indicator)) 1006 :filter-args #'crm-indicator))
1008 1007
1009 (with-eval-after-load 'vertico 1008 (with-eval-after-loads (vertico consult)
1010 (with-eval-after-load 'consult 1009 (when (boundp 'consult-crm-map)
1011 (when (boundp 'consult-crm-map) 1010 (define-key consult-crm-map "\r" #'+vertico-crm-exit)
1012 (define-key consult-crm-map "\r" #'+vertico-crm-exit) 1011 (define-key consult-crm-map "\t" #'vertico-exit)
1013 (define-key consult-crm-map "\t" #'vertico-exit) 1012 (defun +vertico-crm-exit ()
1014 (defun +vertico-crm-exit () 1013 (interactive)
1015 (interactive) 1014 (run-at-time 0 nil #'vertico-exit)
1016 (run-at-time 0 nil #'vertico-exit) 1015 (funcall #'vertico-exit)))))
1017 (funcall #'vertico-exit))))))
1018 1016
1019(setup (:straight crux) 1017(setup (:straight crux)
1020 1018
@@ -1086,11 +1084,10 @@ if ripgrep is installed, otherwise `consult-grep'."
1086 #'which-key--hide-popup-ignore-command) 1084 #'which-key--hide-popup-ignore-command)
1087 embark-become-indicator embark-action-indicator) 1085 embark-become-indicator embark-action-indicator)
1088 1086
1089 (with-eval-after-load 'embark 1087 (with-eval-after-loads (embark consult)
1090 (with-eval-after-load 'consult 1088 (setup (:straight embark-consult)
1091 (setup (:straight embark-consult) 1089 (add-hook 'embark-collect-mode-hook
1092 (add-hook 'embark-collect-mode-hook 1090 #'consult-preview-at-point-mode))))
1093 #'consult-preview-at-point-mode)))))
1094 1091
1095(setup (:straight epithet) 1092(setup (:straight epithet)
1096 (add-hook 'Info-selection-hook #'epithet-rename-buffer) 1093 (add-hook 'Info-selection-hook #'epithet-rename-buffer)
@@ -1201,6 +1198,7 @@ if ripgrep is installed, otherwise `consult-grep'."
1201(setup (:straight (mastodon 1198(setup (:straight (mastodon
1202 :host github 1199 :host github
1203 :repo "mooseyboots/mastodon.el")) 1200 :repo "mooseyboots/mastodon.el"))
1201 (:straight request)
1204 (:option mastodon-instance-url "https://writing.exchange" 1202 (:option mastodon-instance-url "https://writing.exchange"
1205 mastodon-auth-source-file (car auth-sources) 1203 mastodon-auth-source-file (car auth-sources)
1206 mastodon-client--token-file (acdw/dir "mastodon.plstore"))) 1204 mastodon-client--token-file (acdw/dir "mastodon.plstore")))
@@ -1301,35 +1299,39 @@ if ripgrep is installed, otherwise `consult-grep'."
1301(setup (:straight org) 1299(setup (:straight org)
1302 (:straight org-contrib) 1300 (:straight org-contrib)
1303 (require 'acdw-org) ; so I don't clutter up init.el 1301 (require 'acdw-org) ; so I don't clutter up init.el
1304 (:option org-adapt-indentation nil 1302 (:option
1305 org-catch-invisible-edits 'smart 1303 org-adapt-indentation nil
1306 org-clock-clocked-in-display 'mode-line 1304 org-catch-invisible-edits 'smart
1307 org-clock-string-limit 7 ; gives time and not title 1305 org-clock-clocked-in-display 'mode-line
1308 org-confirm-babel-evaluate nil 1306 org-clock-string-limit 7 ; gives time and not title
1309 org-ellipsis " …" 1307 org-confirm-babel-evaluate nil
1310 org-export-coding-system 'utf-8-unix 1308 org-directory "~/org"
1311 org-export-headline-levels 8 1309 org-ellipsis " …"
1312 org-export-with-section-numbers nil 1310 org-export-coding-system 'utf-8-unix
1313 org-export-with-smart-quotes t 1311 org-export-headline-levels 8
1314 org-export-with-sub-superscripts t 1312 org-export-with-section-numbers nil
1315 org-export-with-toc nil 1313 org-export-with-smart-quotes t
1316 org-fontify-done-headline t 1314 org-export-with-sub-superscripts t
1317 org-fontify-quote-and-verse-blocks t 1315 org-export-with-toc nil
1318 org-fontify-whole-heading-line t 1316 org-fontify-done-headline t
1319 org-hide-emphasis-markers t 1317 org-fontify-quote-and-verse-blocks t
1320 org-html-coding-system 'utf-8-unix 1318 org-fontify-whole-heading-line t
1321 org-imenu-depth 3 1319 org-hide-emphasis-markers t
1322 org-outline-path-complete-in-steps nil 1320 org-html-coding-system 'utf-8-unix
1323 org-pretty-entities t 1321 org-image-actual-width '(300)
1324 org-refile-use-outline-path 'file 1322 org-imenu-depth 3
1325 org-special-ctrl-a/e t 1323 org-outline-path-complete-in-steps nil
1326 org-special-ctrl-k t 1324 org-pretty-entities t
1327 org-src-fontify-natively t 1325 org-refile-use-outline-path 'file
1328 org-src-tab-acts-natively t 1326 org-special-ctrl-a/e t
1329 org-src-window-setup 'current-window 1327 org-special-ctrl-k t
1330 org-startup-truncated nil 1328 org-src-fontify-natively t
1331 org-tags-column 0 ; (- 0 fill-column -3) 1329 org-src-tab-acts-natively t
1332 org-directory "~/org") 1330 org-src-window-setup 'current-window
1331 org-startup-truncated nil
1332 org-startup-with-inline-images t
1333 org-tags-column 0 ; (- 0 fill-column -3)
1334 )
1333 1335
1334 (:bind "RET" acdw-org/return-dwim 1336 (:bind "RET" acdw-org/return-dwim
1335 "<S-return>" acdw-org/org-table-copy-down 1337 "<S-return>" acdw-org/org-table-copy-down
@@ -1348,7 +1350,10 @@ if ripgrep is installed, otherwise `consult-grep'."
1348 acdw/org-fix-lines-before-save) 1350 acdw/org-fix-lines-before-save)
1349 1351
1350 (advice-add 'org-delete-backward-char 1352 (advice-add 'org-delete-backward-char
1351 :override #'acdw-org/delete-backward-char)) 1353 :override #'acdw-org/delete-backward-char)
1354
1355 (setup (:straight org-appear)
1356 (:hook-into org-mode)))
1352 1357
1353(setup (:straight paredit) 1358(setup (:straight paredit)
1354 1359
@@ -1463,6 +1468,8 @@ if ripgrep is installed, otherwise `consult-grep'."
1463 1468
1464 (global-undo-fu-session-mode +1)) 1469 (global-undo-fu-session-mode +1))
1465 1470
1471(setup (:straight unfill))
1472
1466(setup (:straight (unfocused 1473(setup (:straight (unfocused
1467 :host github 1474 :host github
1468 :repo "duckwork/unfocused")) 1475 :repo "duckwork/unfocused"))
diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 189ac67..f8f23c6 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el
@@ -243,74 +243,13 @@ the deletion might narrow the column."
243 (org-table-copy-down n) 243 (org-table-copy-down n)
244 (acdw-org/return-dwim n))) 244 (acdw-org/return-dwim n)))
245 245
246(defun acdw-org/count-words (start end)
247 "Count words between START and END, respecting `org-mode' conventions."
248 (interactive (list nil nil))
249 (require 'cl-lib)
250 (require 'ox)
251 (message "Counting words...")
252 (cond ((not (called-interactively-p 'any))
253 (let ((words 0))
254 (save-excursion
255 (save-restriction
256 (narrow-to-region start end)
257 (goto-char (point-min))
258 (while (< (point) (point-max))
259 (cond
260 ;; Ignore comments
261 ((or (org-at-comment-p)
262 (org-in-commented-heading-p)) nil)
263 ;; Ignore tables
264 ((org-at-table-p) nil)
265 ;; Ignore hyperlinks, but count the descriptions
266 ((looking-at org-bracket-link-analytic-regexp)
267 (when-let ((desc (match-string-no-properties 5)))
268 (save-match-data
269 (setq words (+ words
270 (length (remove ""
271 (org-split-string
272 desc "\\W")))))))
273 (goto-char (match-end 0)))
274 ;; Ignore source code blocks
275 ((org-in-src-block-p) nil)
276 ;; Ignore footnotes
277 ((or (org-footnote-at-definition-p)
278 (org-footnote-at-reference-p))
279 nil)
280 ;; else... check the context
281 (t (let ((contexts (org-context)))
282 (cond
283 ;; Ignore tags, TODO keywords, etc.
284 ((or (assoc :todo-keyword contexts)
285 (assoc :priority contexts)
286 (assoc :keyword contexts)
287 (assoc :checkbox contexts))
288 nil)
289 ;; Ignore sections tagged :no-export
290 ((assoc :tags contexts)
291 (if (cl-intersection (org-get-tags-at)
292 org-export-exclude-tags
293 :test 'equal)
294 (org-forward-same-level 1)
295 nil))
296 ;; else... count the word
297 (t (setq words (1+ words)))))))
298 (re-search-forward "\\w+\\W*")))
299 words)))
300 ((use-region-p)
301 (message "%d words in region"
302 (acdw-org/count-words (region-beginning) (region-end))))
303 (t
304 (message "%d words in buffer"
305 (acdw-org/count-words (point-min) (point-max))))))
306
307;; This isn't the best code, but it'll do. 246;; This isn't the best code, but it'll do.
308(defun acdw-org/count-words-stupidly (start end &optional limit) 247(defun acdw-org/count-words-stupidly (start end &optional limit)
309 "Count words between START and END, ignoring a lot. 248 "Count words between START and END, ignoring a lot.
310 249
311Since this function is, for some reason, pricy, the optional 250Since this function is, for some reason, pricy, the optional
312parameter LIMIT sets a word limit at which to stop counting. 251parameter LIMIT sets a word limit at which to stop counting.
313Once the function hits that number, it'll return \"-LIMIT\" 252Once the function hits that number, it'll return -LIMIT
314instead of the true count." 253instead of the true count."
315 (interactive (list nil nil)) 254 (interactive (list nil nil))
316 (cond ((not (called-interactively-p 'any)) 255 (cond ((not (called-interactively-p 'any))
@@ -334,13 +273,35 @@ instead of the true count."
334 ((or (looking-at org-drawer-regexp) 273 ((or (looking-at org-drawer-regexp)
335 (looking-at org-clock-drawer-re)) 274 (looking-at org-clock-drawer-re))
336 (search-forward ":END:" nil :noerror)) 275 (search-forward ":END:" nil :noerror))
276 ;; Ignore tables
277 ((org-at-table-p) (forward-line))
278 ;; Ignore hyperlinks, but count the descriptions
279 ((looking-at org-bracket-link-analytic-regexp)
280 (when-let ((desc (match-string-no-properties 5)))
281 (save-match-data
282 (setq words (+ words
283 (length (remove ""
284 (org-split-string
285 desc "\\W")))))))
286 (goto-char (match-end 0)))
287 ;; Ignore source blocks
288 ((org-in-src-block-p) (foreward-line))
337 ;; Count everything else 289 ;; Count everything else
338 (t (setq words (1+ words)) 290 (t
339 (if (and limit 291 ;; ... unless it's in a few weird contexts
340 (> words limit)) 292 (let ((contexts (org-context)))
341 (setq words limit 293 (cond ((or (assoc :todo-keyword contexts)
342 continue nil)) 294 (assoc :priority contexts)
343 (forward-word-strictly)))))) 295 (assoc :keyword contexts)
296 (assoc :checkbox contexts))
297 (forward-word-strictly))
298
299 (t (setq words (1+ words))
300 (if (and limit
301 (> words limit))
302 (setq words (- limit)
303 continue nil))
304 (forward-word-strictly)))))))))
344 words)) 305 words))
345 ((use-region-p) 306 ((use-region-p)
346 (message "%d words in region" 307 (message "%d words in region"
diff --git a/lisp/acdw.el b/lisp/acdw.el index eab0719..2aa6c1f 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -87,21 +87,6 @@ ARG). When called with multiple arguments or a list, it returns
87 (save-restriction 87 (save-restriction
88 (unfill-region (point-min) (point-max)))))) 88 (unfill-region (point-min) (point-max))))))
89 89
90(defun kill-ring-save-unfilled (start end &optional region)
91 "Unfill, kill, then re-fill the region defined by START and END positions.
92REGION is passed straight to `kill-ring-save'."
93 (interactive "*r")
94 (let ((sentence-end-double-space nil))
95 (unfill-region start end)
96 (kill-ring-save
97 ;; A quick hack to try and ameliorate the "Args out of range" error when
98 ;; `unfill-region' removes some newlines. I'm not sure if this will work
99 ;; if calling from Lisp or other such nonsense.
100 (max start (point-min))
101 (min end (point-max))
102 region))
103 (fill-region start end))
104
105(defmacro when-unfocused (name &rest forms) 90(defmacro when-unfocused (name &rest forms)
106 "Define a function NAME, executing FORMS, that fires when Emacs 91 "Define a function NAME, executing FORMS, that fires when Emacs
107is unfocused." 92is unfocused."
@@ -123,6 +108,22 @@ is unfocused."
123 ,@body) 108 ,@body)
124 (message "%s... Done." ,message))) 109 (message "%s... Done." ,message)))
125 110
111(defmacro with-eval-after-loads (files &rest body)
112 "Execute BODY after FILES are loaded.
113This macro simplifies `with-eval-after-load' for multiple nested
114features."
115 (declare (indent 1) (debug (form def-body)))
116 (waterfall-list 'with-eval-after-load files body))
117
118(defun waterfall-list (car list rest)
119 "Cons CAR with each element in LIST in a waterfall fashion, end with REST.
120For use with the `with-eval-after-loads' function."
121 (cond ((atom list) `(,car ',list ,@rest))
122 ((= 1 (length list)) `(,car ',(car list) ,@rest))
123 (t
124 `(,car ',(car list)
125 ,(waterfall-list car (cdr list) rest)))))
126
126 127
127;;; Comment-or-uncomment-sexp 128;;; Comment-or-uncomment-sexp
128;; from https://endlessparentheses.com/a-comment-or-uncomment-sexp-command.html 129;; from https://endlessparentheses.com/a-comment-or-uncomment-sexp-command.html