Mercurial > hg > xemacs-beta
comparison man/lispref/symbols.texi @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
376 @section Symbol Properties | 376 @section Symbol Properties |
377 @cindex property list, symbol | 377 @cindex property list, symbol |
378 @cindex plist, symbol | 378 @cindex plist, symbol |
379 | 379 |
380 A @dfn{property list} (@dfn{plist} for short) is a list of paired | 380 A @dfn{property list} (@dfn{plist} for short) is a list of paired |
381 elements, often stored in the property list cell of a symbol. Each of | 381 elements stored in the property list cell of a symbol. Each of the |
382 the pairs associates a property name (usually a symbol) with a property | 382 pairs associates a property name (usually a symbol) with a property or |
383 or value. Property lists are generally used to record information about | 383 value. Property lists are generally used to record information about a |
384 a symbol, such as its documentation as a variable, the name of the file | 384 symbol, such as its documentation as a variable, the name of the file |
385 where it was defined, or perhaps even the grammatical class of the | 385 where it was defined, or perhaps even the grammatical class of the |
386 symbol (representing a word) in a language-understanding system. | 386 symbol (representing a word) in a language-understanding system. |
387 | 387 |
388 Some objects which are not symbols also have property lists associated | 388 Many objects other than symbols can have property lists associated |
389 with them, and XEmacs provides a full complement of functions for | 389 with them, and XEmacs provides a full complement of functions for |
390 working with property lists. @xref{Property Lists}. | 390 working with property lists. @xref{Property Lists}. |
391 | 391 |
392 The property names and values in a property list can be any Lisp | 392 The property names and values in a property list can be any Lisp |
393 objects, but the names are usually symbols. They are compared using | 393 objects, but the names are usually symbols. They are compared using |
403 names, and the other two elements are the corresponding values. | 403 names, and the other two elements are the corresponding values. |
404 | 404 |
405 @menu | 405 @menu |
406 * Plists and Alists:: Comparison of the advantages of property | 406 * Plists and Alists:: Comparison of the advantages of property |
407 lists and association lists. | 407 lists and association lists. |
408 * Object Plists:: Functions to access objects' property lists. | 408 * Symbol Plists:: Functions to access symbols' property lists. |
409 * Other Plists:: Accessing property lists stored elsewhere. | 409 * Other Plists:: Accessing property lists stored elsewhere. |
410 @end menu | 410 @end menu |
411 | 411 |
412 @node Plists and Alists | 412 @node Plists and Alists |
413 @subsection Property Lists and Association Lists | 413 @subsection Property Lists and Association Lists |
439 unique, such as by including the name of the library in the property | 439 unique, such as by including the name of the library in the property |
440 name.) An association list may be used like a stack where associations | 440 name.) An association list may be used like a stack where associations |
441 are pushed on the front of the list and later discarded; this is not | 441 are pushed on the front of the list and later discarded; this is not |
442 possible with a property list. | 442 possible with a property list. |
443 | 443 |
444 @node Object Plists | 444 @node Symbol Plists |
445 @subsection Property List Functions for Objects | 445 @subsection Property List Functions for Symbols |
446 | |
447 Once upon a time, only symbols had property lists. Now, several other | |
448 object types, including strings, extents, faces and glyphs also have | |
449 property lists. | |
450 | 446 |
451 @defun symbol-plist symbol | 447 @defun symbol-plist symbol |
452 This function returns the property list of @var{symbol}. | 448 This function returns the property list of @var{symbol}. |
453 @end defun | |
454 | |
455 @defun object-plist object | |
456 This function returns the property list of @var{object}. If | |
457 @var{object} is a symbol, this is identical to @code{symbol-plist}. | |
458 @end defun | 449 @end defun |
459 | 450 |
460 @defun setplist symbol plist | 451 @defun setplist symbol plist |
461 This function sets @var{symbol}'s property list to @var{plist}. | 452 This function sets @var{symbol}'s property list to @var{plist}. |
462 Normally, @var{plist} should be a well-formed property list, but this is | 453 Normally, @var{plist} should be a well-formed property list, but this is |
470 @end smallexample | 461 @end smallexample |
471 | 462 |
472 For symbols in special obarrays, which are not used for ordinary | 463 For symbols in special obarrays, which are not used for ordinary |
473 purposes, it may make sense to use the property list cell in a | 464 purposes, it may make sense to use the property list cell in a |
474 nonstandard fashion; in fact, the abbrev mechanism does so | 465 nonstandard fashion; in fact, the abbrev mechanism does so |
475 (@pxref{Abbrevs}). But generally, its use is discouraged. Use | 466 (@pxref{Abbrevs}). |
476 @code{put} instead. @code{setplist} can only be used with symbols, not | 467 @end defun |
477 other object types. | 468 |
478 @end defun | 469 @defun get symbol property |
479 | |
480 @defun get object property &optional default | |
481 This function finds the value of the property named @var{property} in | 470 This function finds the value of the property named @var{property} in |
482 @var{object}'s property list. If there is no such property, | 471 @var{symbol}'s property list. If there is no such property, @code{nil} |
483 @code{default} (which itself defaults to @code{nil}) is returned. | 472 is returned. Thus, there is no distinction between a value of |
484 | 473 @code{nil} and the absence of the property. |
485 @var{property} is compared with the existing properties using @code{eq}, | 474 |
486 so any object is a legitimate property. | 475 The name @var{property} is compared with the existing property names |
476 using @code{eq}, so any object is a legitimate property. | |
487 | 477 |
488 See @code{put} for an example. | 478 See @code{put} for an example. |
489 @end defun | 479 @end defun |
490 | 480 |
491 @defun put object property value | 481 @defun put symbol property value |
492 This function puts @var{value} onto @var{object}'s property list under | 482 This function puts @var{value} onto @var{symbol}'s property list under |
493 the property name @var{property}, replacing any previous property value. | 483 the property name @var{property}, replacing any previous property value. |
494 The @code{put} function returns @var{value}. | 484 The @code{put} function returns @var{value}. |
495 | 485 |
496 @smallexample | 486 @smallexample |
497 (put 'fly 'verb 'transitive) | 487 (put 'fly 'verb 'transitive) |
498 @result{}'transitive | 488 @result{}'transitive |
499 (put 'fly 'noun '(a buzzing little bug)) | 489 (put 'fly 'noun '(a buzzing little bug)) |
500 @result{} (a buzzing little bug) | 490 @result{} (a buzzing little bug) |
501 (get 'fly 'verb) | 491 (get 'fly 'verb) |
502 @result{} transitive | 492 @result{} transitive |
503 (object-plist 'fly) | 493 (symbol-plist 'fly) |
504 @result{} (verb transitive noun (a buzzing little bug)) | 494 @result{} (verb transitive noun (a buzzing little bug)) |
505 @end smallexample | 495 @end smallexample |
506 @end defun | 496 @end defun |
507 | 497 |
508 @defun remprop object property | |
509 This function removes the entry for @var{property} from the property | |
510 list of @var{object}. It returns @code{t} if the property was | |
511 indeed found and removed, or @code{nil} if there was no such property. | |
512 (This function was probably omitted from Emacs originally because, | |
513 since @code{get} did not allow a @var{default}, it was very difficult | |
514 to distinguish between a missing property and a property whose value | |
515 was @code{nil}; thus, setting a property to @code{nil} was close | |
516 enough to @code{remprop} for most purposes.) | |
517 @end defun | |
518 | |
519 @node Other Plists | 498 @node Other Plists |
520 @subsection Property Lists Not Associated with Objects | 499 @subsection Property Lists Outside Symbols |
521 | 500 |
522 These functions are useful for manipulating property lists | 501 These functions are useful for manipulating property lists |
523 that are stored in places other than symbols: | 502 that are stored in places other than symbols: |
524 | 503 |
525 @defun getf plist property &optional default | 504 @defun getf plist property &optional default |