Add gemini to browse-url-button-regexp

Also I overengineered some other stuff around that.
This commit is contained in:
Case Duckworth 2021-05-24 18:00:23 -05:00
parent 1a20d6329e
commit 67c4eb7fe7
2 changed files with 72 additions and 0 deletions

View File

@ -886,6 +886,9 @@ if ripgrep is installed, otherwise `consult-grep'."
(elpher-go url))
(t (apply fn url args))))
;; And buttonize gemini:// links.
(acdw/add-button-url-regexp-protocol "gemini")
(:when-loaded
(setup (:straight (gemini-write
:host nil

View File

@ -407,6 +407,75 @@ Prompt only if there are unsaved changes."
(custom-set-faces '(fringe
((t (:foreground "dim gray"))))))
;;; URL regexp
;; really, I just want to add gemini:// protocol, but I'm going to do some
;; reverse-engineering here.
(defvar acdw/button-protocols '("http"
"https"
"shttp"
"shttps"
"ftp"
"file"
"gopher"
"nntp"
"news"
"telnet"
"wais"
"mailto"
"info")
"The list of protocols to splice into `browse-url-button-regexp'.")
(defun acdw/build-button-url-regexp ()
"Build `browse-url-button-regexp' from `acdw/button-protocols'.
I used `xr' (not included in Emacs) to get the RX form of the
default, so I can easily splice the list into it. THIS IS
BRITTLE AF!!!"
(rx
(seq word-boundary
(group
(group
(or "www."
(seq
(group
(eval (cons 'or acdw/button-protocols)))
":")))
(opt
(group "//"
(one-or-more
(any "0-9a-z" "._-"))
":"
(zero-or-more
(any "0-9"))))
(or
(seq
(one-or-more
(any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word))
"("
(one-or-more
(any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word))
(zero-or-more
(any "0-9a-z" "#$%&*+/=@\\_~-" word))
")"
(opt
(one-or-more
(any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word))
(any "0-9a-z" "#$%&*+/=@\\_~-" word)))
(seq
(one-or-more
(any "0-9a-z" "!#$%&*+,./:;=?@\\_~-" word))
(any "0-9a-z" "#$%&*+/=@\\_~-" word))))))
)
(defun acdw/add-button-url-regexp-protocol (proto)
"Add PROTO to `browse-url-button-regexp'
First, add PROTO to `acdw/button-protocols'.
Then, build `browse-url-button-regexp' with the new protocol."
(add-to-list 'acdw/button-protocols proto)
(setq browse-url-button-regexp (acdw/build-button-url-regexp)))
;;; Keymaps