aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2018-04-17 18:53:09 +0200
committerLars Ingebrigtsen2018-04-17 18:53:23 +0200
commit950d6cc74426f8d88c1c3985efb336a3a02b3b0e (patch)
treea73fb046102f57359ee9cfc4e27f52f68442780d
parent6f572972d19397d8295727a99b687fc521bd469e (diff)
downloademacs-950d6cc74426f8d88c1c3985efb336a3a02b3b0e.tar.gz
emacs-950d6cc74426f8d88c1c3985efb336a3a02b3b0e.zip
Reimplement `shr-next-link' and `shr-previous-link'
* lisp/net/shr.el (shr-next-link): Use `text-property-search-forward'. (shr-previous-link): Use `text-property-search-backward'.
-rw-r--r--lisp/net/shr.el48
1 files changed, 9 insertions, 39 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 275b36f9009..2d913a5a92f 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -39,6 +39,7 @@
39(require 'svg) 39(require 'svg)
40(require 'image) 40(require 'image)
41(require 'puny) 41(require 'puny)
42(require 'text-property-search)
42 43
43(defgroup shr nil 44(defgroup shr nil
44 "Simple HTML Renderer" 45 "Simple HTML Renderer"
@@ -378,49 +379,18 @@ If the URL is already at the front of the kill ring act like
378(defun shr-next-link () 379(defun shr-next-link ()
379 "Skip to the next link." 380 "Skip to the next link."
380 (interactive) 381 (interactive)
381 (let ((current (get-text-property (point) 'shr-url)) 382 (let ((match (text-property-search-forward 'shr-url nil nil t)))
382 (start (point)) 383 (if (not match)
383 skip) 384 (message "No next link")
384 (while (and (not (eobp)) 385 (goto-char (prop-match-beginning match))
385 (equal (get-text-property (point) 'shr-url) current)) 386 (message "%s" (get-text-property (point) 'help-echo)))))
386 (forward-char 1))
387 (cond
388 ((and (not (eobp))
389 (get-text-property (point) 'shr-url))
390 ;; The next link is adjacent.
391 (message "%s" (get-text-property (point) 'help-echo)))
392 ((or (eobp)
393 (not (setq skip (text-property-not-all (point) (point-max)
394 'shr-url nil))))
395 (goto-char start)
396 (message "No next link"))
397 (t
398 (goto-char skip)
399 (message "%s" (get-text-property (point) 'help-echo))))))
400 387
401(defun shr-previous-link () 388(defun shr-previous-link ()
402 "Skip to the previous link." 389 "Skip to the previous link."
403 (interactive) 390 (interactive)
404 (let ((start (point)) 391 (if (not (text-property-search-backward 'shr-url nil nil t))
405 (found nil)) 392 (message "No previous link")
406 ;; Skip past the current link. 393 (message "%s" (get-text-property (point) 'help-echo))))
407 (while (and (not (bobp))
408 (get-text-property (point) 'help-echo))
409 (forward-char -1))
410 ;; Find the previous link.
411 (while (and (not (bobp))
412 (not (setq found (get-text-property (point) 'help-echo))))
413 (forward-char -1))
414 (if (not found)
415 (progn
416 (message "No previous link")
417 (goto-char start))
418 ;; Put point at the start of the link.
419 (while (and (not (bobp))
420 (get-text-property (point) 'help-echo))
421 (forward-char -1))
422 (forward-char 1)
423 (message "%s" (get-text-property (point) 'help-echo)))))
424 394
425(defun shr-show-alt-text () 395(defun shr-show-alt-text ()
426 "Show the ALT text of the image under point." 396 "Show the ALT text of the image under point."