aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/button.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/button.el')
-rw-r--r--lisp/button.el38
1 files changed, 26 insertions, 12 deletions
diff --git a/lisp/button.el b/lisp/button.el
index d3c4cd8ea9e..423aef5f78f 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -89,9 +89,6 @@ Mode-specific keymaps may want to use this as their parent keymap.")
89;; Prevent insertions adjacent to the text-property buttons from 89;; Prevent insertions adjacent to the text-property buttons from
90;; inheriting its properties. 90;; inheriting its properties.
91(put 'default-button 'rear-nonsticky t) 91(put 'default-button 'rear-nonsticky t)
92;; Text property buttons don't have a `button' property of their own, so
93;; they inherit this.
94(put 'default-button 'button t)
95 92
96;; A `category-symbol' property for the default button type 93;; A `category-symbol' property for the default button type
97(put 'button 'button-category-symbol 'default-button) 94(put 'button 'button-category-symbol 'default-button)
@@ -316,7 +313,11 @@ Also see `insert-text-button'."
316 (setcar (cdr type-entry) 313 (setcar (cdr type-entry)
317 (button-category-symbol (car (cdr type-entry)))))) 314 (button-category-symbol (car (cdr type-entry))))))
318 ;; Now add all the text properties at once 315 ;; Now add all the text properties at once
319 (add-text-properties beg end properties) 316 (add-text-properties beg end
317 ;; Each button should have a non-eq `button'
318 ;; property so that next-single-property-change can
319 ;; detect boundaries reliably.
320 (cons 'button (cons (list t) properties)))
320 ;; Return something that can be used to get at the button. 321 ;; Return something that can be used to get at the button.
321 beg) 322 beg)
322 323
@@ -365,16 +366,29 @@ instead of starting at the next button."
365 (next-button pos)))) 366 (next-button pos))))
366 367
367(defun previous-button (pos &optional count-current) 368(defun previous-button (pos &optional count-current)
368 "Return the Nth button before position POS in the current buffer. 369 "Return the previous button before position POS in the current buffer.
369If 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,
370instead of starting at the next button." 371instead of starting at the next button."
371 (unless count-current 372 (let ((button (button-at pos)))
372 (setq pos (previous-single-char-property-change pos 'button))) 373 (if button
373 (and (> pos (point-min)) 374 (if count-current
374 (or (button-at (1- pos)) 375 button
375 ;; 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
376 ;; the inter-button space. Recurse to find a button. 377 ;; for the previous button boundary.
377 (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 (= pos (button-start 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)))))))
378 392
379 393
380;; User commands 394;; User commands