aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2001-10-08 06:08:57 +0000
committerMiles Bader2001-10-08 06:08:57 +0000
commitfee34a28e25b6d44db1a90311eb019b3a6522d7a (patch)
tree51f0ec11de33045f52124975fb4066a0084bd796
parent5f351ff1f52efddc8033305f8c6ddb0dd675dbd9 (diff)
downloademacs-fee34a28e25b6d44db1a90311eb019b3a6522d7a.tar.gz
emacs-fee34a28e25b6d44db1a90311eb019b3a6522d7a.zip
(next-button, previous-button): Remove N and WRAP parameters.
Don't pay attention to `skip' properties. (forward-button): Implement wrapping, iterating, and skipping here instead.
-rw-r--r--lisp/button.el96
1 files changed, 37 insertions, 59 deletions
diff --git a/lisp/button.el b/lisp/button.el
index ed2ea106366..f1ce1fff413 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -303,72 +303,30 @@ Also see `make-text-button'."
303 ;; Must be a text-property button; return a marker pointing to it. 303 ;; Must be a text-property button; return a marker pointing to it.
304 (copy-marker pos t)))) 304 (copy-marker pos t))))
305 305
306(defun next-button (pos &optional n wrap count-current) 306(defun next-button (pos &optional count-current)
307 "Return the Nth button after position POS in the current buffer. 307 "Return the next button after position POS in the current buffer.
308If N is negative, return the Nth button before POS.
309If no Nth button is found, return nil.
310If WRAP is non-nil, the search wraps around at the end of the buffer.
311If COUNT-CURRENT is non-nil, count any button at POS in the search, 308If COUNT-CURRENT is non-nil, count any button at POS in the search,
312 instead of starting at the next button." 309instead of starting at the next button."
313 (when (null n)
314 (setq n 1))
315 (if (< n 0)
316 ;; reverse direction
317 (previous-button pos (- n) wrap)
318 (unless count-current 310 (unless count-current
319 ;; Search for the next button boundary. 311 ;; Search for the next button boundary.
320 (setq pos (next-single-char-property-change pos 'button))) 312 (setq pos (next-single-char-property-change pos 'button)))
321 (let ((button (button-at pos))) 313 (and (< pos (point-max))
322 (cond ((and button (button-get button 'skip)) 314 (or (button-at pos)
323 ;; Found a button, but the button declines to be found; recurse.
324 (next-button (button-start button) n wrap))
325 ((and button (>= n 2))
326 ;; Found a button, but we want a different one; recurse.
327 (next-button (button-start button) (1- n) wrap))
328 (button
329 ;; This is the button we want.
330 button)
331 ((= pos (point-max))
332 ;; Failed to find a button going forwards, either wrap or
333 ;; return failure.
334 (and wrap (next-button (point-min) n nil t)))
335 (t
336 ;; We must have originally been on a button, and are now in 315 ;; We must have originally been on a button, and are now in
337 ;; the inter-button space. Recurse to find a button. 316 ;; the inter-button space. Recurse to find a button.
338 (next-button pos n wrap)))))) 317 (next-button pos))))
339 318
340(defun previous-button (pos &optional n wrap count-current) 319(defun previous-button (pos &optional count-current)
341 "Return the Nth button before position POS in the current buffer. 320 "Return the Nth button before position POS in the current buffer.
342If N is negative, return the Nth button after POS.
343If no Nth button is found, return nil.
344If WRAP is non-nil, the search wraps around at the beginning of the buffer.
345If COUNT-CURRENT is non-nil, count any button at POS in the search, 321If COUNT-CURRENT is non-nil, count any button at POS in the search,
346 instead of starting at the next button." 322instead of starting at the next button."
347 (when (null n) 323 (unless count-current
348 (setq n 1)) 324 (setq pos (previous-single-char-property-change pos 'button)))
349 (if (< n 0) 325 (and (> pos (point-min))
350 ;; reverse direction 326 (or (button-at (1- pos))
351 (next-button pos (- n) wrap) 327 ;; We must have originally been on a button, and are now in
352 (unless count-current 328 ;; the inter-button space. Recurse to find a button.
353 (setq pos (previous-single-char-property-change pos 'button))) 329 (previous-button pos))))
354 (let ((button (and (> pos (point-min)) (button-at (1- pos)))))
355 (cond ((and button (button-get button 'skip))
356 ;; Found a button, but the button declines to be found; recurse.
357 (previous-button (button-start button) n wrap))
358 ((and button (>= n 2))
359 ;; Found a button, but we want a different one; recurse.
360 (previous-button (button-start button) (1- n) wrap))
361 (button
362 ;; This is the button we want.
363 button)
364 ((= pos (point-min))
365 ;; Failed to find a button going backwards, either wrap
366 ;; or return failure.
367 (and wrap (previous-button (point-max) n nil t)))
368 (t
369 ;; We must have originally been on a button, and are now in
370 ;; the inter-button space. Recurse to find a button.
371 (previous-button pos (max n 1) wrap))))))
372 330
373 331
374;; User commands 332;; User commands
@@ -400,15 +358,33 @@ return t."
400 358
401(defun forward-button (n &optional wrap display-message) 359(defun forward-button (n &optional wrap display-message)
402 "Move to the Nth next button, or Nth previous button if N is negative. 360 "Move to the Nth next button, or Nth previous button if N is negative.
361If N is 0, move to the start of any button at point.
403If WRAP is non-nil, moving past either end of the buffer continues from the 362If WRAP is non-nil, moving past either end of the buffer continues from the
404other end. 363other end.
405If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. 364If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed.
365Any button with a non-nil `skip' property is skipped over.
406Returns the button found." 366Returns the button found."
407 (interactive "p\nd\nd") 367 (interactive "p\nd\nd")
408 (let ((button (next-button (point) n wrap))) 368 (let (button)
369 (if (zerop n)
370 ;; Move to start of current button
371 (if (setq button (button-at (point)))
372 (goto-char (button-start button)))
373 ;; Move to Nth next button
374 (let ((iterator (if (> n 0) #'next-button #'previous-button))
375 (wrap-start (if (> n 0) (point-min) (point-max))))
376 (setq n (abs n))
377 (setq button t) ; just to start the loop
378 (while (and (> n 0) button)
379 (setq button (funcall iterator (point)))
380 (when (and (not button) wrap)
381 (setq button (funcall iterator wrap-start t)))
382 (when button
383 (goto-char (button-start button))
384 (unless (button-get button 'skip)
385 (setq n (1- n)))))))
409 (if (null button) 386 (if (null button)
410 (error (if wrap "No buttons!" "No more buttons")) 387 (error (if wrap "No buttons!" "No more buttons"))
411 (goto-char (button-start button))
412 (let ((msg (and display-message (button-get button 'help-echo)))) 388 (let ((msg (and display-message (button-get button 'help-echo))))
413 (when msg 389 (when msg
414 (message "%s" msg))) 390 (message "%s" msg)))
@@ -416,9 +392,11 @@ Returns the button found."
416 392
417(defun backward-button (n &optional wrap display-message) 393(defun backward-button (n &optional wrap display-message)
418 "Move to the Nth previous button, or Nth next button if N is negative. 394 "Move to the Nth previous button, or Nth next button if N is negative.
395If N is 0, move to the start of any button at point.
419If WRAP is non-nil, moving past either end of the buffer continues from the 396If WRAP is non-nil, moving past either end of the buffer continues from the
420other end. 397other end.
421If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. 398If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed.
399Any button with a non-nil `skip' property is skipped over.
422Returns the button found." 400Returns the button found."
423 (interactive "p\nd\nd") 401 (interactive "p\nd\nd")
424 (forward-button (- n) wrap display-message)) 402 (forward-button (- n) wrap display-message))