summaryrefslogtreecommitdiff
path: root/lisp/button.el
diff options
context:
space:
mode:
authorChong Yidong <cyd@stupidchicken.com>2008-07-31 22:15:45 +0000
committerChong Yidong <cyd@stupidchicken.com>2008-07-31 22:15:45 +0000
commitf09c915a69104f7b28e443ed8269f46518272d0f (patch)
tree092a6dbc28832b355559e72ffff9a46568bc8f10 /lisp/button.el
parent9aa6a26ca089317bd01df18e1c54929eed35d8c6 (diff)
downloademacs-f09c915a69104f7b28e443ed8269f46518272d0f.tar.gz
(forward-button): Avoid infloop.
Diffstat (limited to 'lisp/button.el')
-rw-r--r--lisp/button.el11
1 files changed, 9 insertions, 2 deletions
diff --git a/lisp/button.el b/lisp/button.el
index 6a558af445a..b474a74da9c 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -437,15 +437,22 @@ Returns the button found."
(goto-char (button-start button)))
;; Move to Nth next button
(let ((iterator (if (> n 0) #'next-button #'previous-button))
- (wrap-start (if (> n 0) (point-min) (point-max))))
+ (wrap-start (if (> n 0) (point-min) (point-max)))
+ opoint fail)
(setq n (abs n))
(setq button t) ; just to start the loop
- (while (and (> n 0) button)
+ (while (and (null fail) (> n 0) button)
(setq button (funcall iterator (point)))
(when (and (not button) wrap)
(setq button (funcall iterator wrap-start t)))
(when button
(goto-char (button-start button))
+ ;; Avoid looping forever (e.g., if all the buttons have
+ ;; the `skip' property).
+ (cond ((null opoint)
+ (setq opoint (point)))
+ ((= opoint (point))
+ (setq fail t)))
(unless (button-get button 'skip)
(setq n (1- n)))))))
(if (null button)