]> git.eshelyaron.com Git - emacs.git/commitdiff
Reimplement `shr-next-link' and `shr-previous-link'
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 17 Apr 2018 16:53:09 +0000 (18:53 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 17 Apr 2018 16:53:23 +0000 (18:53 +0200)
* lisp/net/shr.el (shr-next-link): Use
`text-property-search-forward'.
(shr-previous-link): Use `text-property-search-backward'.

lisp/net/shr.el

index 275b36f90097b1e9a33e676cb46a66e4cfca39bc..2d913a5a92f7d9781ac902cd08ef71bf164e79cb 100644 (file)
@@ -39,6 +39,7 @@
 (require 'svg)
 (require 'image)
 (require 'puny)
+(require 'text-property-search)
 
 (defgroup shr nil
   "Simple HTML Renderer"
@@ -378,49 +379,18 @@ If the URL is already at the front of the kill ring act like
 (defun shr-next-link ()
   "Skip to the next link."
   (interactive)
-  (let ((current (get-text-property (point) 'shr-url))
-        (start (point))
-        skip)
-    (while (and (not (eobp))
-                (equal (get-text-property (point) 'shr-url) current))
-      (forward-char 1))
-    (cond
-     ((and (not (eobp))
-           (get-text-property (point) 'shr-url))
-      ;; The next link is adjacent.
-      (message "%s" (get-text-property (point) 'help-echo)))
-     ((or (eobp)
-          (not (setq skip (text-property-not-all (point) (point-max)
-                                                 'shr-url nil))))
-      (goto-char start)
-      (message "No next link"))
-     (t
-      (goto-char skip)
-      (message "%s" (get-text-property (point) 'help-echo))))))
+  (let ((match (text-property-search-forward 'shr-url nil nil t)))
+    (if (not match)
+        (message "No next link")
+      (goto-char (prop-match-beginning match))
+      (message "%s" (get-text-property (point) 'help-echo)))))
 
 (defun shr-previous-link ()
   "Skip to the previous link."
   (interactive)
-  (let ((start (point))
-       (found nil))
-    ;; Skip past the current link.
-    (while (and (not (bobp))
-               (get-text-property (point) 'help-echo))
-      (forward-char -1))
-    ;; Find the previous link.
-    (while (and (not (bobp))
-               (not (setq found (get-text-property (point) 'help-echo))))
-      (forward-char -1))
-    (if (not found)
-       (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)
-      (message "%s" (get-text-property (point) 'help-echo)))))
+  (if (not (text-property-search-backward 'shr-url nil nil t))
+      (message "No previous link")
+    (message "%s" (get-text-property (point) 'help-echo))))
 
 (defun shr-show-alt-text ()
   "Show the ALT text of the image under point."