diff options
author | Case Duckworth | 2021-11-21 23:57:41 -0600 |
---|---|---|
committer | Case Duckworth | 2021-11-21 23:57:41 -0600 |
commit | a2657993bad828af6743c68931a0e848bfcdec53 (patch) | |
tree | 1e9220389184a0c68bc9f6bfe08edca3f2a362e6 /lisp/acdw-browse-url.el | |
parent | Un-stupidify org-mode filling (diff) | |
download | emacs-a2657993bad828af6743c68931a0e848bfcdec53.tar.gz emacs-a2657993bad828af6743c68931a0e848bfcdec53.zip |
I DECLARE BANKRUPTCY ... 8
Didn't think to do this till pretty .. written, so here we are.
Diffstat (limited to 'lisp/acdw-browse-url.el')
-rw-r--r-- | lisp/acdw-browse-url.el | 129 |
1 files changed, 0 insertions, 129 deletions
diff --git a/lisp/acdw-browse-url.el b/lisp/acdw-browse-url.el deleted file mode 100644 index 9f8e484..0000000 --- a/lisp/acdw-browse-url.el +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
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'. | ||
42 | If Emacs' version is 28 or higher, set `browse-url-handlers'. | ||
43 | Else, 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'. | ||
69 | I used `xr' (not included in Emacs) to get the RX form of the | ||
70 | default, so I can easily splice the list into it. THIS IS | ||
71 | BRITTLE 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' | ||
108 | First, add PROTO to `acdw/button-protocols'. | ||
109 | Then, 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 reddit.com to teddit | ||
116 | (defun acdw/eww-browse-reddit-url (url &rest args) | ||
117 | "Browse a Reddit.com URL using Teddit." | ||
118 | (let* ((teddit "teddit.com") | ||
119 | (url (replace-regexp-in-string "reddit\\.com" teddit url))) | ||
120 | (eww-browse-url url args))) | ||
121 | |||
122 | ;; convert twitter.com to nitter | ||
123 | (defun acdw/eww-browse-twitter-url (url &rest args) | ||
124 | "Browse a Twitter.com URL using Nitter." | ||
125 | (let* ((nitter "nitter.snopyta.org") | ||
126 | (url (replace-regexp-in-string "twitter\\.com" nitter url))) | ||
127 | (eww-browse-url url args))) | ||
128 | |||
129 | (provide 'acdw-browse-url) | ||