summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-08-16 22:48:29 -0500
committerCase Duckworth2021-08-16 22:48:29 -0500
commita6fd6508c9f853df9f0a61079f2268cd88e3d5f7 (patch)
tree1e3eb323b6f44ed16f09a36e88624289080d7eef /lisp
parentChange work font to Inter (diff)
downloademacs-a6fd6508c9f853df9f0a61079f2268cd88e3d5f7.tar.gz
emacs-a6fd6508c9f853df9f0a61079f2268cd88e3d5f7.zip
Break out functionality into other files
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-browse-url.el122
-rw-r--r--lisp/acdw-consult.el37
-rw-r--r--lisp/acdw-lisp.el25
-rw-r--r--lisp/acdw.el79
4 files changed, 187 insertions, 76 deletions
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'.
42If Emacs' version is 28 or higher, set `browse-url-handlers'.
43Else, 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'.
69I used `xr' (not included in Emacs) to get the RX form of the
70default, so I can easily splice the list into it. THIS IS
71BRITTLE 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'
108First, add PROTO to `acdw/button-protocols'.
109Then, 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'
10if 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'.
467I used `xr' (not included in Emacs) to get the RX form of the
468default, so I can easily splice the list into it. THIS IS
469BRITTLE 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'
506First, add PROTO to `acdw/button-protocols'.
507Then, 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.