Commit a32e1feb authored by Lars Ingebrigtsen's avatar Lars Ingebrigtsen
Browse files

Enable browse-url to buttonize buffers

This patch also moves the internal/external browser logic from
shr to browse-url, where it belongs more naturally.

* doc/misc/eww.texi (Basics): Adjust to browse-url-external-browser.

* doc/misc/gnus.texi (Article Commands): Ditto.

* lisp/gnus/gnus-art.el (gnus-button-url-regexp): Default to
`browse-url-button-regexp', which has taken over the definition
previously enjoyed by this variable.

* lisp/gnus/gnus-sum.el (gnus-summary-browse-url): Adjust usage.

* lisp/net/browse-url.el (browse-url--browser-defcustom-type): New
internal variable...
(browse-url-browser-function, browse-url-external-browser): Used
by these two; the latter of which is a new variable.
(browse-url-botton-regexp): New variable.
(browse-url-button-map): New keymap.
(browse-url-button): New face.
(browse-url-add-buttons): New function to add clickable browse-url
buttons to almost any buffer.
(browse-url-button-open): New command.
(browse-url-button-copy): New command.

* lisp/net/eww.el (eww-browse-with-external-browser)
(eww-follow-link): Adjust usage.

* lisp/net/shr.el (shr-external-browser): Make an obsolete alias
of `browse-url-external-browser'.
(shr-browse-url): Adjust usage.
parent dcba39b4
Pipeline #2627 passed with stage
in 85 minutes and 57 seconds
......@@ -187,7 +187,7 @@ switch EWW buffers through a minibuffer prompt, press @kbd{s}
@findex eww-browse-with-external-browser
@vindex shr-external-browser
@vindex browse-url-external-browser
@vindex eww-use-external-browser-for-content-type
@kindex &
@cindex External Browser
......@@ -197,7 +197,7 @@ or are not implemented (E.g., JavaScript). If you have trouble
viewing a website with EWW then hit @kbd{&}
(@code{eww-browse-with-external-browser}) inside the EWW buffer to
open the website in the external browser specified by
@code{shr-external-browser}. Some content types, such as video or
@code{browse-url-external-browser}. Some content types, such as video or
audio content, do not make sense to display in GNU Emacs at all. You
can tell EWW to open specific content automatically in an external
browser by customizing
......@@ -10164,7 +10164,7 @@ do so.
@findex gnus-summary-browse-url
Scan the article buffer for links, and offer them to the user for
browsing with @code{browse-url}. With a prefix argument, browse with
@code{shr-external-browser} instead.
@code{browse-url-external-browser} instead.
@end table
......@@ -765,6 +765,12 @@ start of a sentence or at '(point-min)', else '@ref'.
It now treats the optional 2nd argument to mean that the URL should be
shown in the currently selected window.
*** A new function, 'browse-url-add-buttons' can be used to add clickable
links to most ordinary special-mode buffers that display text that
have URLs embedded. 'browse-url-button-regexp' controls what's
considered a button.
*** A new variable, 'browse-url-external-browser', has been added.
** Comint
......@@ -1037,6 +1043,10 @@ has been executed.
If set, shr will not render tags with attribute 'aria-hidden="true"'.
This attribute is meant to tell screen readers to ignore a tag.
*** 'shr-external-browser' has been made into an obsolete alias
of 'browse-url-external-browser'.
*** 'shr-tag-ol' now respects the ordered list 'start' attribute.
......@@ -7343,27 +7343,9 @@ groups."
;; Written by Per Abrahamsen <>.
;;; Internal Variables:
(defcustom gnus-button-url-regexp
(let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
(punct "!?:;.,"))
;; Match paired parentheses, e.g. in Wikipedia URLs:
"[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
"\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
"[" chars punct "]+" "[" chars "]"
(defcustom gnus-button-url-regexp browse-url-button-regexp
"Regular expression that matches URLs."
:version "24.4"
:version "27.1"
:group 'gnus-article-buttons
:type 'regexp)
......@@ -9478,7 +9478,7 @@ The 1st element is the widget named by `gnus-collect-urls-primary-text'."
"Scan the current article body for links, and offer to browse them.
Links are opened using `browse-url' unless a prefix argument is
given: Then `shr-external-browser' is used instead.
given: Then `browse-url-external-browser' is used instead.
If only one link is found, browse that directly, otherwise use
completion to select a link. The first link marked in the
......@@ -9502,7 +9502,7 @@ default."
(car urls)))))
(if target
(if external
(funcall shr-external-browser target)
(funcall browse-url-external-browser target)
(browse-url target))
(message "No URLs found.")))))
This diff is collapsed.
......@@ -1501,13 +1501,15 @@ See URL `'.")
(defun eww-browse-with-external-browser (&optional url)
"Browse the current URL with an external browser.
The browser to used is specified by the `shr-external-browser' variable."
The browser to used is specified by the `browse-url-external-browser' variable."
(funcall shr-external-browser (or url (plist-get eww-data :url))))
(funcall browse-url-external-browser (or url (plist-get eww-data :url))))
(defun eww-follow-link (&optional external mouse-event)
"Browse the URL under point.
If EXTERNAL is single prefix, browse the URL using `shr-external-browser'.
If EXTERNAL is single prefix, browse the URL using
If EXTERNAL is double prefix, browse in new buffer."
(interactive (list current-prefix-arg last-nonmenu-event))
(mouse-set-point mouse-event)
......@@ -1518,7 +1520,7 @@ If EXTERNAL is double prefix, browse in new buffer."
((string-match "^mailto:" url)
(browse-url-mail url))
((and (consp external) (<= (car external) 4))
(funcall shr-external-browser url)
(funcall browse-url-external-browser url)
;; This is a #target url in the same page as the current one.
((and (url-target (url-generic-parse-url url))
......@@ -53,53 +53,44 @@ width and height of the window. If they are larger than this,
and Emacs supports it, then the images will be rescaled down to
fit these criteria."
:version "24.1"
:group 'shr
:type 'float)
(defcustom shr-blocked-images nil
"Images that have URLs matching this regexp will be blocked."
:version "24.1"
:group 'shr
:type '(choice (const nil) regexp))
(defcustom shr-use-fonts t
"If non-nil, use proportional fonts for text."
:version "25.1"
:group 'shr
:type 'boolean)
(defcustom shr-discard-aria-hidden nil
"If non-nil, don't render tags with `aria-hidden=\"true\"'.
This attribute is meant to tell screen readers to ignore a tag."
:version "27.1"
:group 'shr
:type 'boolean)
(defcustom shr-use-colors t
"If non-nil, respect color specifications in the HTML."
:version "26.1"
:group 'shr
:type 'boolean)
(defcustom shr-table-horizontal-line nil
"Character used to draw horizontal table lines.
If nil, don't draw horizontal table lines."
:group 'shr
:type '(choice (const nil) character))
(defcustom shr-table-vertical-line ?\s
"Character used to draw vertical table lines."
:group 'shr
:type 'character)
(defcustom shr-table-corner ?\s
"Character used to draw table corners."
:group 'shr
:type 'character)
(defcustom shr-hr-line ?-
"Character used to draw hr lines."
:group 'shr
:type 'character)
(defcustom shr-width nil
......@@ -110,8 +101,7 @@ If `shr-use-fonts' is set, the mean character width is used to
compute the pixel width, which is used instead."
:version "25.1"
:type '(choice (integer :tag "Fixed width in characters")
(const :tag "Use the width of the window" nil))
:group 'shr)
(const :tag "Use the width of the window" nil)))
(defcustom shr-bullet "* "
"Bullet used for unordered lists.
......@@ -119,19 +109,14 @@ Alternative suggestions are:
- \" \"
- \" \""
:version "24.4"
:type 'string
:group 'shr)
:type 'string)
(defcustom shr-external-browser 'browse-url-default-browser
"Function used to launch an external browser."
:version "24.4"
:group 'shr
:type 'function)
(define-obsolete-variable-alias 'shr-external-browser
'browse-url-external-browser "27.1")
(defcustom shr-image-animate t
"Non nil means that images that can be animated will be."
:version "24.4"
:group 'shr
:type 'boolean)
(defvar shr-content-function nil
......@@ -144,28 +129,24 @@ cid: URL as the argument.")
(defface shr-strike-through '((t :strike-through t))
"Face for <s> elements."
:version "24.1"
:group 'shr)
:version "24.1")
(defface shr-link
'((t :inherit link))
"Face for link elements."
:version "24.1"
:group 'shr)
:version "24.1")
(defface shr-selected-link
'((t :inherit shr-link :background "red"))
"Temporary face for externally visited link elements.
When a link is visited with an external browser, the link
temporarily blinks with this face."
:version "27.1"
:group 'shr)
:version "27.1")
(defface shr-abbreviation
'((t :inherit underline :underline (:style wave)))
"Face for <abbr> elements."
:version "27.1"
:group 'shr)
:version "27.1")
(defvar shr-inhibit-images nil
"If non-nil, inhibit loading images.")
......@@ -973,7 +954,7 @@ size, and full-buffer size."
(defun shr-browse-url (&optional external mouse-event)
"Browse the URL at point using `browse-url'.
If EXTERNAL is non-nil (interactively, the prefix argument), browse
the URL using `shr-external-browser'.
the URL using `browse-url-external-browser'.
If this function is invoked by a mouse click, it will browse the URL
at the position of the click. Optional argument MOUSE-EVENT describes
the mouse click event."
......@@ -988,7 +969,7 @@ the mouse click event."
(if external
(funcall shr-external-browser url)
(funcall browse-url-external-browser url)
(browse-url url))))))
......@@ -1534,7 +1515,6 @@ The key element should be a regexp matched against the type of the source or
url if no type is specified. The value should be a float in the range 0.0 to
1.0. Media elements with higher value are preferred."
:version "24.4"
:group 'shr
:type '(alist :key-type regexp :value-type float))
(defun shr--get-media-pref (elem)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment