comparison lisp/button.el @ 60339:3cd3e3cf3529

Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-145 (make-text-button): Default button type if not specified 2005-03-02 Miles Bader <miles@gnu.org> * lisp/button.el (make-text-button): If the user doesn't specify a type, use the default. Rewrite to use `add-text-properties' and plist functions.
author Miles Bader <miles@gnu.org>
date Wed, 02 Mar 2005 09:12:54 +0000
parents 82eaf594d12a
children 6fb026ad601f e4694597cbf4
comparison
equal deleted inserted replaced
60338:e040c58e568a 60339:3cd3e3cf3529
1 ;;; button.el --- clickable buttons 1 ;;; button.el --- clickable buttons
2 ;; 2 ;;
3 ;; Copyright (C) 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 2001, 2005 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Author: Miles Bader <miles@gnu.org> 5 ;; Author: Miles Bader <miles@gnu.org>
6 ;; Keywords: extensions 6 ;; Keywords: extensions
7 ;; 7 ;;
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
296 part of the text instead of being a property of the buffer. Creating 296 part of the text instead of being a property of the buffer. Creating
297 large numbers of buttons can also be somewhat faster using 297 large numbers of buttons can also be somewhat faster using
298 `make-text-button'. 298 `make-text-button'.
299 299
300 Also see `insert-text-button'." 300 Also see `insert-text-button'."
301 (let (prop val) 301 (let ((type-entry
302 (while properties 302 (or (plist-member properties 'type)
303 (setq prop (pop properties)) 303 (plist-member properties :type))))
304 (setq val (pop properties)) 304 ;; Disallow setting the `category' property directly.
305 ;; Note that all the following code is basically equivalent to 305 (when (plist-get properties 'category)
306 ;; `button-put', but we can do it much more efficiently since we 306 (error "Button `category' property may not be set directly"))
307 ;; already have BEG and END. 307 (if (null type-entry)
308 (cond ((memq prop '(type :type)) 308 ;; The user didn't specify a `type' property, use the default.
309 ;; We translate a `type' property into a `category' 309 (setq properties (cons 'category (cons 'default-button properties)))
310 ;; property, since that's what's actually used by 310 ;; The user did specify a `type' property. Translate it into a
311 ;; text-properties for inheritance. 311 ;; `category' property, which is what's actually used by
312 (setq prop 'category) 312 ;; text-properties for inheritance.
313 (setq val (button-category-symbol val))) 313 (setcar type-entry 'category)
314 ((eq prop 'category) 314 (setcar (cdr type-entry)
315 ;; Disallow setting the `category' property directly. 315 (button-category-symbol (car (cdr type-entry))))))
316 (error "Button `category' property may not be set directly"))) 316 ;; Now add all the text properties at once
317 ;; Add the property. 317 (add-text-properties beg end properties)
318 (put-text-property beg end prop val)))
319 ;; Return something that can be used to get at the button. 318 ;; Return something that can be used to get at the button.
320 beg) 319 beg)
321 320
322 ;;;###autoload 321 ;;;###autoload
323 (defun insert-text-button (label &rest properties) 322 (defun insert-text-button (label &rest properties)