Subject: shr.el: skips over adjacent links

From: Ivan Shmakov <[email-masked]>
Date: Sat, 10 Jan 2015 20:25:58 +0000

Package:  emacs
Severity: minor

	As of ec7605b4b137 (2015-01-10 16:54:24 +0000), the
	shr-next-link and shr-previous-link commands skip over adjacent
	links, as per the example MIMEd.

	With this same example, shr-previous-link also fails to deal
	with the link at the very beginning of the buffer.

	Please consider the patch MIMEd.

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A
AB

--- a/lisp/net/shr.el	2015-01-10 16:54:24 +0000
+++ b/lisp/net/shr.el	2015-01-10 20:20:24 +0000
@@ -265,8 +269,11 @@
 (defun shr-next-link ()
   "Skip to the next link."
   (interactive)
-  (let ((skip (text-property-any (point) (point-max) 'help-echo nil)))
+  (let* ((cur (get-text-property (point) 'help-echo))
+	 (skip (text-property-not-all (point) (point-max)
+				      'help-echo cur)))
     (if (or (eobp)
+	    (not skip)
 	    (not (setq skip (text-property-not-all skip (point-max)
 						   'help-echo nil))))
 	(message "No next link")
@@ -276,25 +283,28 @@
 (defun shr-previous-link ()
   "Skip to the previous link."
   (interactive)
-  (let ((start (point))
+  (let ((cur (get-text-property (point) 'help-echo))
+	(start (point))
 	(found nil))
     ;; Skip past the current link.
     (while (and (not (bobp))
-		(get-text-property (point) 'help-echo))
+		(when-let ((h-e (get-text-property (point) 'help-echo)))
+		  (eq cur h-e)))
       (forward-char -1))
     ;; Find the previous link.
-    (while (and (not (bobp))
-		(not (setq found (get-text-property (point) 'help-echo))))
+    (while (and (not (setq found (get-text-property (point) 'help-echo)))
+		(not (bobp)))
       (forward-char -1))
-    (if (not found)
+    (if (or (not found) (eq start (point)))
 	(progn
 	  (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)
+      (when (not (bobp))
+	(while (and (not (bobp))
+		    (eq found (get-text-property (point) 'help-echo)))
+	  (forward-char -1))
+	(forward-char 1))
       (message "%s" (get-text-property (point) 'help-echo)))))
 
 (defun shr-show-alt-text ()