From f793d55b4ff57c3ce3a8dd0fac8de229f7c38a91 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Sat, 30 Jan 2021 10:00:06 +0100 Subject: [PATCH] make default protocol customizable This adds a defcustom to let user choose what default URL type elpher should assume when no one is explicitly given, instead of hardcoding gopher as it is now. It also improves a bit how scheme-less URL are handled: `M-x elpher-go example.com/foo/bar' is now parsed into host `example.com' and path `/foo/bar'. --- elpher.el | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/elpher.el b/elpher.el index 4c34f52..36c2ad2 100644 --- a/elpher.el +++ b/elpher.el @@ -144,6 +144,11 @@ These certificates may be used for establishing authenticated TLS connections." "The command used to launch openssl when generating TLS client certificates." :type '(file)) +(defcustom elpher-default-url-type "gopher" + "Default URL type to assume if not explicitly given." + :type '(choice (const "gopher") + (const "gemini"))) + (defcustom elpher-gemini-TLS-cert-checks nil "If non-nil, verify gemini server TLS certs using the default security level. Otherwise, certificate verification is disabled. @@ -272,13 +277,17 @@ some servers which do not support IPv6 can take a long time to time-out." (setf (url-filename url) (url-unhex-string (url-filename url))) (unless (url-type url) - (setf (url-type url) "gopher")) + (setf (url-type url) elpher-default-url-type)) + (unless (url-host url) + (let ((p (split-string (url-filename url) "/" nil nil))) + (setf (url-host url) (car p)) + (setf (url-filename url) + (if (cdr p) + (concat "/" (mapconcat #'identity (cdr p) "/")) + "")))) (when (or (equal "gopher" (url-type url)) (equal "gophers" (url-type url))) ;; Gopher defaults - (unless (url-host url) - (setf (url-host url) (url-filename url)) - (setf (url-filename url) "")) (when (or (equal (url-filename url) "") (equal (url-filename url) "/")) (setf (url-filename url) "/1"))) -- 2.20.1