Mercurial > emacs
comparison lispref/variables.texi @ 27389:0eff88dd2524
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 22 Jan 2000 03:45:48 +0000 |
parents | d2e5f1b7d8e2 |
children | 10e53615a9d2 |
comparison
equal
deleted
inserted
replaced
27388:38dfea505906 | 27389:0eff88dd2524 |
---|---|
30 * Global Variables:: Variable values that exist permanently, everywhere. | 30 * Global Variables:: Variable values that exist permanently, everywhere. |
31 * Constant Variables:: Certain "variables" have values that never change. | 31 * Constant Variables:: Certain "variables" have values that never change. |
32 * Local Variables:: Variable values that exist only temporarily. | 32 * Local Variables:: Variable values that exist only temporarily. |
33 * Void Variables:: Symbols that lack values. | 33 * Void Variables:: Symbols that lack values. |
34 * Defining Variables:: A definition says a symbol is used as a variable. | 34 * Defining Variables:: A definition says a symbol is used as a variable. |
35 * Tips for Defining:: How to avoid bad results from quitting | 35 * Tips for Defining:: Things you should think about when you |
36 within the code to initialize a variable. | 36 define a variable. |
37 * Accessing Variables:: Examining values of variables whose names | 37 * Accessing Variables:: Examining values of variables whose names |
38 are known only at run time. | 38 are known only at run time. |
39 * Setting Variables:: Storing new values in variables. | 39 * Setting Variables:: Storing new values in variables. |
40 * Variable Scoping:: How Lisp chooses among local and global values. | 40 * Variable Scoping:: How Lisp chooses among local and global values. |
41 * Buffer-Local Variables:: Variable values in effect only in one buffer. | 41 * Buffer-Local Variables:: Variable values in effect only in one buffer. |
42 * Frame-Local Variables:: Variable values in effect only in one frame. | 42 * Frame-Local Variables:: Variable values in effect only in one frame. |
43 * Future Local Variables:: New kinds of local values we might add some day. | 43 * Future Local Variables:: New kinds of local values we might add some day. |
44 * File Local Variables:: Handling local variable lists in files. | |
44 @end menu | 45 @end menu |
45 | 46 |
46 @node Global Variables | 47 @node Global Variables |
47 @section Global Variables | 48 @section Global Variables |
48 @cindex global variable | 49 @cindex global variable |
570 (@pxref{Customization}). | 571 (@pxref{Customization}). |
571 | 572 |
572 @strong{Warning:} If the @code{defconst} and @code{defvar} special | 573 @strong{Warning:} If the @code{defconst} and @code{defvar} special |
573 forms are used while the variable has a local binding, they set the | 574 forms are used while the variable has a local binding, they set the |
574 local binding's value; the global binding is not changed. This is not | 575 local binding's value; the global binding is not changed. This is not |
575 what we really want. To prevent it, use these special forms at top | 576 what you usually want. To prevent it, use these special forms at top |
576 level in a file, where normally no local binding is in effect, and make | 577 level in a file, where normally no local binding is in effect, and make |
577 sure to load the file before making a local binding for the variable. | 578 sure to load the file before making a local binding for the variable. |
578 | 579 |
579 @node Tips for Defining | 580 @node Tips for Defining |
580 @section Tips for Defining Variables Robustly | 581 @section Tips for Defining Variables Robustly |
582 | |
583 When you define a variable whose value is a function, or a list of | |
584 functions, use a name that ends in @samp{-function} or | |
585 @samp{-functions}, respectively. | |
586 | |
587 There are several other variable name conventions; | |
588 here is a complete list: | |
589 | |
590 @table @samp | |
591 @item @dots{}-hook | |
592 The variable is a normal hook (@pxref{Hooks}). | |
593 | |
594 @item @dots{}-function | |
595 The value is a function. | |
596 | |
597 @item @dots{}-functions | |
598 The value is a list of functions. | |
599 | |
600 @item @dots{}-form | |
601 The value is a form (an expression). | |
602 | |
603 @item @dots{}-functions | |
604 The value is a list of forms (expressions). | |
605 | |
606 @item @dots{}-predicate | |
607 The value is a predicate---a function of one argument that returns | |
608 non-@code{nil} for ``good'' arguments and @code{nil} for ``bad'' | |
609 arguments. | |
610 | |
611 @item @dots{}-flag | |
612 The value is significant only as to whether it is @code{nil} or not. | |
613 | |
614 @item @dots{}-program | |
615 The value is a program name. | |
616 | |
617 @item @dots{}-command | |
618 The value is a whole shell command. | |
619 | |
620 @item @samp{}-switches | |
621 The value specifies options for a command. | |
622 @end table | |
623 | |
624 When you define a variable, always cvonsider whether you should mark | |
625 it as ``risky''; see @ref{File Local Variables}. | |
581 | 626 |
582 When defining and initializing a variable that holds a complicated | 627 When defining and initializing a variable that holds a complicated |
583 value (such as a keymap with bindings in it), it's best to put the | 628 value (such as a keymap with bindings in it), it's best to put the |
584 entire computation of the value into the @code{defvar}, like this: | 629 entire computation of the value into the @code{defvar}, like this: |
585 | 630 |
1603 bindings offer a way to handle these situations more robustly. | 1648 bindings offer a way to handle these situations more robustly. |
1604 | 1649 |
1605 If sufficient application is found for either of these two kinds of | 1650 If sufficient application is found for either of these two kinds of |
1606 local bindings, we will provide it in a subsequent Emacs version. | 1651 local bindings, we will provide it in a subsequent Emacs version. |
1607 | 1652 |
1608 | 1653 @node File Local Variables |
1654 @section File Local Variables | |
1655 | |
1656 This section describes the functions and variables that affect | |
1657 processing of local variables lists in files. | |
1658 | |
1659 @defopt enable-local-variables | |
1660 This variable controls whether to process file local variables lists. A | |
1661 value of @code{t} means process the local variables lists | |
1662 unconditionally; @code{nil} means ignore them; anything else means ask | |
1663 the user what to do for each file. The default value is @code{t}. | |
1664 @end defopt | |
1665 | |
1666 @defun hack-local-variables &optional force | |
1667 This function parses, and binds or evaluates as appropriate, any local | |
1668 variables specified by the contents of the current buffer. The variable | |
1669 @code{enable-local-variables} has its effect here. | |
1670 | |
1671 The argument @var{force} usually comes from the argument @var{find-file} | |
1672 given to @code{normal-mode}. | |
1673 @end defun | |
1674 | |
1675 If a file local variable list could specify the a function that will | |
1676 be called later, or an expression that will be executed later, simply | |
1677 visiting a file could take over your Emacs. To prevent this, Emacs | |
1678 takes care not to allow local variable lists to set such variables. | |
1679 | |
1680 For one thing, any variable whose name ends in @samp{-function}, | |
1681 @samp{-functions}, @samp{-hook}, @samp{-hooks}, @samp{-form}, | |
1682 @samp{-forms}, @samp{-program}, @samp{-command} or @samp{-predicate} | |
1683 cannot be set in a local variable list. In general, you should use such | |
1684 a name whenever it is appropriate for the variable's meaning. | |
1685 | |
1686 In addition, any variable whose name has a non-@code{nil} | |
1687 @code{risky-local-variable} property is also ignored. So are | |
1688 all variables listed in @code{ignored-local-variables}: | |
1689 | |
1690 @defvar ignored-local-variables | |
1691 This variable holds a list of variables that should not be | |
1692 set by a file's local variables list. Any value specified | |
1693 for one of these variables is ignored. | |
1694 @end defvar | |
1695 | |
1696 The @samp{Eval:} ``variable'' is also a potential loophole, so Emacs | |
1697 normally asks for confirmation before handling it. | |
1698 | |
1699 @defopt enable-local-eval | |
1700 This variable controls processing of @samp{Eval:} in local variables | |
1701 lists in files being visited. A value of @code{t} means process them | |
1702 unconditionally; @code{nil} means ignore them; anything else means ask | |
1703 the user what to do for each file. The default value is @code{maybe}. | |
1704 @end defopt |