From 67c4eb7fe7ab8b9402bc375f09dc39ce766bbe50 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 24 May 2021 18:00:23 -0500 Subject: [PATCH] Add gemini to browse-url-button-regexp Also I overengineered some other stuff around that. --- init.el | 3 +++ lisp/acdw.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/init.el b/init.el index 2c18993..759541a 100644 --- a/init.el +++ b/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 diff --git a/lisp/acdw.el b/lisp/acdw.el index 9ac315c..ce3e9f8 100644 --- a/lisp/acdw.el +++ b/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