Subject: Re: bug#16415: 24.3.50; Handle contiguous links correctly in shr [PATCH]

From: Nathan Trapuzzano <[email-masked]>
Date: Sat, 11 Jan 2014 07:50:14 -0500

Nathan Trapuzzano <[email-masked]> writes:

> `shr-next-link' and `shr-previous-link' currently skip over links that
> are contiguous with the current link.  The attached patch addressed this
> problem.
>
> When I say "contiguous", I'm talking in terms of Emacs "positions"--not
> in terms of HTML.

Use this one instead.  I clarified one of the comments and referenced a
bug number:

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]
# target_branch: file:///home/nathan/opt/etc/bzr-repos/emacs/trunk/
# testament_sha1: 6cb8b589f64f1b09f140c539ef23d4305646a92e
# timestamp: 2014-01-11 07:48:46 -0500
# base_revision_id: [email-masked]
# 
# Begin patch
=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2014-01-10 20:19:31 +0000
+++ lisp/ChangeLog	2014-01-11 03:16:17 +0000
@@ -1,3 +1,8 @@
+2014-01-11  Nathan Trapuzzano  <[email-masked]>
+
+	* lisp/net/shr.el (shr-next-link, shr-previous-link): Don't skip
+	over contiguous links.
+
 2014-01-10  Glenn Morris  <[email-masked]>
 
 	* emacs-lisp/authors.el (authors-fixed-entries):

=== modified file 'lisp/net/shr.el'
--- lisp/net/shr.el	2014-01-05 10:23:35 +0000
+++ lisp/net/shr.el	2014-01-11 12:48:32 +0000
@@ -242,8 +242,10 @@
 (defun shr-next-link ()
   "Skip to the next link."
   (interactive)
-  (let ((skip (text-property-any (point) (point-max) 'help-echo nil)))
-    (if (not (setq skip (text-property-not-all skip (point-max)
+  (let ((skip (and (get-text-property (point) 'help-echo)
+                   (or (next-single-property-change (point) 'help-echo)
+                       (point-max)))))
+    (if (not (setq skip (text-property-not-all (or skip (point)) (point-max)
 					       'help-echo nil)))
 	(message "No next link")
       (goto-char skip)
@@ -254,11 +256,17 @@
   (interactive)
   (let ((start (point))
 	(found nil))
-    ;; Skip past the current link.
-    (while (and (not (bobp))
-		(get-text-property (point) 'help-echo))
+    ;; Skip backwards past the current link.  Be carefule when the
+    ;; current link extends past the end of the narrowed region and
+    ;; point is at (point-max).  In such a case, we proceed as though
+    ;; point is _not_ looking at a link.  Cf. Emacs bug#16413.
+    (when (and (get-text-property (point) 'help-echo)
+               (not (and (eobp) (buffer-narrowed-p))))
+      (goto-char (or (previous-single-property-change
+                      (min (1+ (point)) (point-max)) 'help-echo)
+                     (point-min))))
+    (unless (bobp)
       (forward-char -1))
-    ;; Find the previous link.
     (while (and (not (bobp))
 		(not (setq found (get-text-property (point) 'help-echo))))
       (forward-char -1))
@@ -267,10 +275,9 @@
 	  (message "No previous link")
 	  (goto-char start))
       ;; Put point at the start of the link.
-      (while (and (not (bobp))
-		  (get-text-property (point) 'help-echo))
-	(forward-char -1))
-      (forward-char 1)
+      (goto-char (or (previous-single-property-change
+                      (min (1+ (point)) (point-max)) 'help-echo)
+                     (point-min)))
       (message "%s" (get-text-property (point) 'help-echo)))))
 
 (defun shr-show-alt-text ()

# Begin bundle