Add gemini to browse-url-button-regexp
Also I overengineered some other stuff around that.
This commit is contained in:
parent
1a20d6329e
commit
67c4eb7fe7
3
init.el
3
init.el
|
@ -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
|
||||
|
|
69
lisp/acdw.el
69
lisp/acdw.el
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue