X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=elpher.git;a=blobdiff_plain;f=elpher.el;h=f94b33f22c3b42cf6d3540da8a20ce60a2752872;hp=c0032487a2411ee3ae3133670069892e1f143f8a;hb=e3fca3512d458c4a78ef9b3d87b66e952f2b5f94;hpb=545af85cbcb053783ccce78128da2afc8cbc94c4 diff --git a/elpher.el b/elpher.el index c003248..f94b33f 100644 --- a/elpher.el +++ b/elpher.el @@ -156,7 +156,7 @@ (defcustom elpher-open-urls-with-eww nil "If non-nil, open URL selectors using eww. -Otherwise, use the system browser via the BROWSE-URL function." +Otherwise, use the system browser via the `browse-url' function." :type '(boolean)) (defcustom elpher-use-header t @@ -1271,6 +1271,11 @@ that the response was malformed." (error "Gemini server response unknown: %s %s" response-code response-meta)))))) +(unless (fboundp 'read-answer) + (defun read-answer (question answers) + "Backfill for the new read-answer code." + (completing-read question (mapcar 'identity answers)))) + (defun elpher-choose-client-certificate () "Prompt for a client certificate to use to establish a TLS connection." (let* ((read-answer-short t)) @@ -1487,7 +1492,7 @@ width defined by `elpher-gemini-max-fill-width'." (propertize text-line 'face 'elpher-gemini-quoted)) (t text-line)) text-line)) - (adaptive-fill-mode nil)) + (adaptive-fill-mode t)) (insert (elpher-process-text-for-display processed-text-line)) (newline))) @@ -1779,6 +1784,13 @@ If ADDRESS is already bookmarked, update the label only." ;;; Integrations ;; +;;; Org + +;; Avoid byte compilation warnings. +(eval-when-compile + (declare-function org-link-store-props "ol") + (declare-function org-link-set-parameters "ol")) + (defun elpher-org-export-link (link description format protocol) "Export a LINK with DESCRIPTION for the given PROTOCOL and FORMAT. @@ -1796,8 +1808,6 @@ of gemini, gopher or finger." url (format "%s (%s)" desc url)))))) -;; Avoid byte compilation warnings. -(declare-function org-link-store-props "ol") (defun elpher-org-store-link () "Store link to an `elpher' page in Org." (when (eq major-mode 'elpher-mode) @@ -1817,15 +1827,13 @@ of gemini, gopher or finger." (defun elpher-org-follow-link (link protocol) "Visit a LINK for the given PROTOCOL. -PROTOCOL may be one of gemini, gopher or finger. This method also support old -paramter elpher, where link is self-contained." +PROTOCOL may be one of gemini, gopher or finger. This method also +supports the old protocol elpher, where the link is self-contained." (let ((url (if (equal protocol "elpher") (string-remove-prefix "elpher:" link) (format "%s:%s" protocol link)))) (elpher-go url))) -;; Avoid byte compilation warnings. -(declare-function org-link-set-parameters "ol") (with-eval-after-load 'org (org-link-set-parameters "elpher" @@ -1849,6 +1857,12 @@ paramter elpher, where link is self-contained." (elpher-org-export-link link description format "finger")) :follow (lambda (link _arg) (elpher-org-follow-link link "finger")))) +;;; Browse URL + +;; Avoid byte compilation warnings. +(eval-when-compile + (defvar thing-at-point-uri-schemes)) + ;;;###autoload (defun elpher-browse-url-elpher (url &rest _args) "Browse URL using Elpher. This function is used by `browse-url'." @@ -1856,20 +1870,34 @@ paramter elpher, where link is self-contained." (elpher-go url)) ;; Use elpher to open gopher, finger and gemini links -(with-eval-after-load 'browse-url - (add-to-list - 'browse-url-default-handlers - '("^\\(gopher\\|finger\\|gemini\\)://" . elpher-browse-url-elpher))) - -;; Avoid byte compilation warnings. -(eval-when-compile - (defvar thing-at-point-uri-schemes) - (defvar mu4e~view-beginning-of-url-regexp)) +;; For recent version of `browse-url' package +(if (boundp 'browse-url-default-handlers) + (add-to-list + 'browse-url-default-handlers + '("^\\(gopher\\|finger\\|gemini\\)://" . elpher-browse-url-elpher)) + ;; Patch `browse-url-browser-function' for older ones. The value of + ;; that variable is `browse-url-default-browser' by default, so + ;; that's the function that gets advised. + (advice-add browse-url-browser-function :before-while + (lambda (url &rest _args) + "Handle gemini, gopher, and finger schemes using Elpher." + (let ((scheme (downcase (car (split-string url ":" t))))) + (if (member scheme '("gemini" "gopher" "finger")) + ;; `elpher-go' always returns nil, which will stop the + ;; advice chain here in a before-while + (elpher-go url) + ;; chain must continue, then return t. + t))))) ;; Register "gemini://" as a URI scheme so `browse-url' does the right thing (with-eval-after-load 'thingatpt (add-to-list 'thing-at-point-uri-schemes "gemini://")) +;;; Mu4e: + +(eval-when-compile + (defvar mu4e~view-beginning-of-url-regexp)) + (with-eval-after-load 'mu4e-view ;; Make mu4e aware of the gemini world (setq mu4e~view-beginning-of-url-regexp