From: Stefan Kangas Date: Sun, 10 Jul 2022 12:30:52 +0000 (+0200) Subject: New user option browse-url-guess-default-scheme X-Git-Tag: emacs-29.0.90~1447^2~1043 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=118e05f570b127f9272c5dea1ae9a739531e238c;p=emacs.git New user option browse-url-guess-default-scheme * lisp/net/browse-url.el (browse-url-guess-default-scheme): New user option. (browse-url-url-at-point): Use above new user option. --- diff --git a/etc/NEWS b/etc/NEWS index c2e2f1b7b72..2ab1361a9ed 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1924,6 +1924,12 @@ related 'auth-sources' entry were wrong. ** Browse URL +--- +*** New user option 'browse-url-guess-default-scheme'. +This user option affects the URL scheme that 'browse-url' and related +functions will assume when it has to guess. You could customize this +to "https" to always prefer HTTPS URLs. + --- *** Support for the Netscape web browser has been removed. This support has been obsolete since Emacs 25.1. The final version of diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index b988fbf9a65..198c86f935e 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -652,11 +652,24 @@ regarding its parameter treatment." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; URL input +(defcustom browse-url-guess-default-scheme "http" + "URL scheme to use when `browse-url' (and related commands) has to guess. + +For example, when point is on an URL fragment like +\"www.example.org\", `browse-url' will assume that this is an +\"http\" URL by default (i.e. \"http://www.example.org\"). + +Note that if you set this to \"https\", websites that do not yet +support HTTPS may not load correctly in your web browser. Such +websites are increasingly rare, but they do still exist." + :type 'string + :version "29.1") + (defun browse-url-url-at-point () (or (thing-at-point 'url t) ;; assume that the user is pointing at something like gnu.org/gnu (let ((f (thing-at-point 'filename t))) - (and f (concat "http://" f))))) + (and f (concat browse-url-guess-default-scheme "://" f))))) ;; Having this as a separate function called by the browser-specific ;; functions allows them to be stand-alone commands, making it easier