summaryrefslogtreecommitdiff
path: root/lisp/button.el
diff options
context:
space:
mode:
authorChong Yidong <cyd@stupidchicken.com>2007-04-01 17:10:11 +0000
committerChong Yidong <cyd@stupidchicken.com>2007-04-01 17:10:11 +0000
commit39ffa8ff067c5445e38daf2d5ccef2024d97abdb (patch)
treebdf976fa34322e9f0931b4d2a35881ead428bffd /lisp/button.el
parent3a9545b650c1f4ee228a20c236801e1efad285a0 (diff)
downloademacs-39ffa8ff067c5445e38daf2d5ccef2024d97abdb.tar.gz
(previous-button): Rewrite to account for adjacent buttons.
Diffstat (limited to 'lisp/button.el')
-rw-r--r--lisp/button.el29
1 files changed, 21 insertions, 8 deletions
diff --git a/lisp/button.el b/lisp/button.el
index 05ea7aec5e2..9110b7867a1 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -366,16 +366,29 @@ instead of starting at the next button."
(next-button pos))))
(defun previous-button (pos &optional count-current)
- "Return the Nth button before position POS in the current buffer.
+ "Return the previous button before position POS in the current buffer.
If COUNT-CURRENT is non-nil, count any button at POS in the search,
instead of starting at the next button."
- (unless count-current
- (setq pos (previous-single-char-property-change pos 'button)))
- (and (> pos (point-min))
- (or (button-at (1- pos))
- ;; We must have originally been on a button, and are now in
- ;; the inter-button space. Recurse to find a button.
- (previous-button pos))))
+ (let ((button (button-at pos)))
+ (if button
+ (if count-current
+ button
+ ;; We started out on a button, so move to its start and look
+ ;; for the previous button boundary.
+ (setq pos (previous-single-char-property-change
+ (button-start button) 'button))
+ (let ((new-button (button-at pos)))
+ (if new-button
+ ;; We are in a button again; this can happen if there
+ ;; are adjacent buttons (or at bob).
+ (unless (eq new-button button) new-button)
+ ;; We are now in the space between buttons.
+ (previous-button pos))))
+ ;; We started out in the space between buttons.
+ (setq pos (previous-single-char-property-change pos 'button))
+ (or (button-at pos)
+ (and (> pos (point-min))
+ (button-at (1- pos)))))))
;; User commands