aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2007-04-01 17:10:11 +0000
committerChong Yidong2007-04-01 17:10:11 +0000
commit1106c41b1c730d937e7c5ad02b7fea0619b2fdc6 (patch)
tree2fd23f9c299c1a29af05c47675b000e6ce90a9b0
parent574b081eca943cd8b4d82881808da4fdaaa2cc65 (diff)
downloademacs-1106c41b1c730d937e7c5ad02b7fea0619b2fdc6.tar.gz
emacs-1106c41b1c730d937e7c5ad02b7fea0619b2fdc6.zip
(previous-button): Rewrite to account for adjacent buttons.
-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."
366 (next-button pos)))) 366 (next-button pos))))
367 367
368(defun previous-button (pos &optional count-current) 368(defun previous-button (pos &optional count-current)
369 "Return the Nth button before position POS in the current buffer. 369 "Return the previous button before position POS in the current buffer.
370If COUNT-CURRENT is non-nil, count any button at POS in the search, 370If COUNT-CURRENT is non-nil, count any button at POS in the search,
371instead of starting at the next button." 371instead of starting at the next button."
372 (unless count-current 372 (let ((button (button-at pos)))
373 (setq pos (previous-single-char-property-change pos 'button))) 373 (if button
374 (and (> pos (point-min)) 374 (if count-current
375 (or (button-at (1- pos)) 375 button
376 ;; We must have originally been on a button, and are now in 376 ;; We started out on a button, so move to its start and look
377 ;; the inter-button space. Recurse to find a button. 377 ;; for the previous button boundary.
378 (previous-button pos)))) 378 (setq pos (previous-single-char-property-change
379 (button-start button) 'button))
380 (let ((new-button (button-at pos)))
381 (if new-button
382 ;; We are in a button again; this can happen if there
383 ;; are adjacent buttons (or at bob).
384 (unless (eq new-button button) new-button)
385 ;; We are now in the space between buttons.
386 (previous-button pos))))
387 ;; We started out in the space between buttons.
388 (setq pos (previous-single-char-property-change pos 'button))
389 (or (button-at pos)
390 (and (> pos (point-min))
391 (button-at (1- pos)))))))
379 392
380 393
381;; User commands 394;; User commands