1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

When opening external links in eww, blink the link

* lisp/net/eww.el (eww-follow-link): Ditto.

* lisp/net/shr.el (shr-selected-link): New face (bug#25096).
(shr--blink-link): New function to blink links.
(shr--current-link-region): New utility function.
(shr-browse-url): Use it to blink external links.

Blinking the link allows the user to get immediate feedback that the
action has been performed.  Opening the external browser may take a
while, and may not be obvious that is going on.
This commit is contained in:
Lars Ingebrigtsen 2018-04-13 14:17:51 +02:00
parent c7abc5760b
commit 4f4c7b8083
2 changed files with 34 additions and 2 deletions

View file

@ -142,6 +142,11 @@ cid: URL as the argument.")
"Font for link elements."
:group 'shr)
(defface shr-selected-link
'((t (:inherit shr-link :background "red")))
"Font for link elements."
:group 'shr)
(defvar shr-inhibit-images nil
"If non-nil, inhibit loading images.")
@ -344,6 +349,30 @@ If the URL is already at the front of the kill ring act like
(shr-probe-and-copy-url url)
(shr-copy-url url)))
(defun shr--current-link-region ()
(let ((current (get-text-property (point) 'shr-url))
start)
(save-excursion
;; Go to the beginning.
(while (and (not (bobp))
(equal (get-text-property (point) 'shr-url) current))
(forward-char -1))
(unless (equal (get-text-property (point) 'shr-url) current)
(forward-char 1))
(setq start (point))
;; Go to the end.
(while (and (not (eobp))
(equal (get-text-property (point) 'shr-url) current))
(forward-char 1))
(list start (point)))))
(defun shr--blink-link ()
(let* ((region (shr--current-link-region))
(overlay (make-overlay (car region) (cadr region))))
(overlay-put overlay 'face 'shr-selected-link)
(run-at-time 1 nil (lambda ()
(delete-overlay overlay)))))
(defun shr-next-link ()
"Skip to the next link."
(interactive)
@ -950,7 +979,9 @@ the mouse click event."
(browse-url-mail url))
(t
(if external
(funcall shr-external-browser url)
(progn
(funcall shr-external-browser url)
(shr--blink-link))
(browse-url url))))))
(defun shr-save-contents (directory)