diff options
| author | Luc Teirlinck | 2003-11-05 04:31:43 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2003-11-05 04:31:43 +0000 |
| commit | f36e17982d9de253a8819db80a3562e9a2a4938e (patch) | |
| tree | baaf971bc04f7aba610e1f4f45c50325b0fc29ea | |
| parent | 40ebe9bdd7e71e180478e85583899b9a96456666 (diff) | |
| download | emacs-f36e17982d9de253a8819db80a3562e9a2a4938e.tar.gz emacs-f36e17982d9de253a8819db80a3562e9a2a4938e.zip | |
(Defining Variables): Second argument to `defconst' is not optional.
(Setting Variables): Mention optional argument APPEND to `add-to-list'.
(Creating Buffer-Local): Expand description of `make-variable-buffer-local'.
(Frame-Local Variables): Expand description of `make-variable-frame-local'.
(Variable Aliases): Correct description of optional argument DOCSTRING
to `defvaralias'. Mention return value of `defvaralias'.
(File Local Variables): Add xref to `File variables' in Emacs Manual.
Correct description of `hack-local-variables'. Mention
`safe-local-variable' property. Mention optional second argument to
`risky-local-variable-p'.
| -rw-r--r-- | lispref/variables.texi | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/lispref/variables.texi b/lispref/variables.texi index d9431b7fd9e..36cc2e47fe4 100644 --- a/lispref/variables.texi +++ b/lispref/variables.texi | |||
| @@ -518,7 +518,7 @@ The @code{defvar} form returns @var{symbol}, but it is normally used | |||
| 518 | at top level in a file where its value does not matter. | 518 | at top level in a file where its value does not matter. |
| 519 | @end defspec | 519 | @end defspec |
| 520 | 520 | ||
| 521 | @defspec defconst symbol [value [doc-string]] | 521 | @defspec defconst symbol value [doc-string] |
| 522 | This special form defines @var{symbol} as a value and initializes it. | 522 | This special form defines @var{symbol} as a value and initializes it. |
| 523 | It informs a person reading your code that @var{symbol} has a standard | 523 | It informs a person reading your code that @var{symbol} has a standard |
| 524 | global value, established here, that should not be changed by the user | 524 | global value, established here, that should not be changed by the user |
| @@ -526,10 +526,10 @@ or by other programs. Note that @var{symbol} is not evaluated; the | |||
| 526 | symbol to be defined must appear explicitly in the @code{defconst}. | 526 | symbol to be defined must appear explicitly in the @code{defconst}. |
| 527 | 527 | ||
| 528 | @code{defconst} always evaluates @var{value}, and sets the value of | 528 | @code{defconst} always evaluates @var{value}, and sets the value of |
| 529 | @var{symbol} to the result if @var{value} is given. If @var{symbol} | 529 | @var{symbol} to the result. If @var{symbol} does have a buffer-local |
| 530 | does have a buffer-local binding in the current buffer, @code{defconst} | 530 | binding in the current buffer, @code{defconst} sets the default value, |
| 531 | sets the default value, not the buffer-local value. (But you should not | 531 | not the buffer-local value. (But you should not be making |
| 532 | be making buffer-local bindings for a symbol that is defined with | 532 | buffer-local bindings for a symbol that is defined with |
| 533 | @code{defconst}.) | 533 | @code{defconst}.) |
| 534 | 534 | ||
| 535 | Here, @code{pi} is a constant that presumably ought not to be changed | 535 | Here, @code{pi} is a constant that presumably ought not to be changed |
| @@ -858,11 +858,16 @@ always affects the most local existing binding. | |||
| 858 | One other function for setting a variable is designed to add | 858 | One other function for setting a variable is designed to add |
| 859 | an element to a list if it is not already present in the list. | 859 | an element to a list if it is not already present in the list. |
| 860 | 860 | ||
| 861 | @defun add-to-list symbol element | 861 | @defun add-to-list symbol element &optional append |
| 862 | This function sets the variable @var{symbol} by consing @var{element} | 862 | This function sets the variable @var{symbol} by consing @var{element} |
| 863 | onto the old value, if @var{element} is not already a member of that | 863 | onto the old value, if @var{element} is not already a member of that |
| 864 | value. It returns the resulting list, whether updated or not. The | 864 | value. It returns the resulting list, whether updated or not. The |
| 865 | value of @var{symbol} had better be a list already before the call. | 865 | value of @var{symbol} had better be a list already before the call. |
| 866 | Membership is tested using @code{equal}. | ||
| 867 | |||
| 868 | Normally, if @var{element} is added, it is added to the front of | ||
| 869 | @var{symbol}, but if the optional argument @var{append} is | ||
| 870 | non-@code{nil}, it is added at the end. | ||
| 866 | 871 | ||
| 867 | The argument @var{symbol} is not implicitly quoted; @code{add-to-list} | 872 | The argument @var{symbol} is not implicitly quoted; @code{add-to-list} |
| 868 | is an ordinary function, like @code{set} and unlike @code{setq}. Quote | 873 | is an ordinary function, like @code{set} and unlike @code{setq}. Quote |
| @@ -1296,7 +1301,14 @@ local to the current buffer at the time. | |||
| 1296 | A peculiar wrinkle of this feature is that binding the variable (with | 1301 | A peculiar wrinkle of this feature is that binding the variable (with |
| 1297 | @code{let} or other binding constructs) does not create a buffer-local | 1302 | @code{let} or other binding constructs) does not create a buffer-local |
| 1298 | binding for it. Only setting the variable (with @code{set} or | 1303 | binding for it. Only setting the variable (with @code{set} or |
| 1299 | @code{setq}) does so. | 1304 | @code{setq}), while the variable does not have a @code{let}-style |
| 1305 | binding that was made in the current buffer, does so. | ||
| 1306 | |||
| 1307 | If @var{variable} does not have a default value, then calling this | ||
| 1308 | command will give it a default value of @code{nil}. If @var{variable} | ||
| 1309 | already has a default value, that value remains unchanged. | ||
| 1310 | Subsequently calling @code{makunbound} on @var{variable} will result | ||
| 1311 | in a void buffer-local value and leave the default value unaffected. | ||
| 1300 | 1312 | ||
| 1301 | The value returned is @var{variable}. | 1313 | The value returned is @var{variable}. |
| 1302 | 1314 | ||
| @@ -1556,11 +1568,17 @@ not in itself create any frame-local bindings for the variable; however, | |||
| 1556 | if some frame already has a value for @var{variable} as a frame | 1568 | if some frame already has a value for @var{variable} as a frame |
| 1557 | parameter, that value automatically becomes a frame-local binding. | 1569 | parameter, that value automatically becomes a frame-local binding. |
| 1558 | 1570 | ||
| 1571 | If @var{variable} does not have a default value, then calling this | ||
| 1572 | command will give it a default value of @code{nil}. If @var{variable} | ||
| 1573 | already has a default value, that value remains unchanged. | ||
| 1574 | |||
| 1559 | If the variable is terminal-local, this function signals an error, | 1575 | If the variable is terminal-local, this function signals an error, |
| 1560 | because such variables cannot have frame-local bindings as well. | 1576 | because such variables cannot have frame-local bindings as well. |
| 1561 | @xref{Multiple Displays}. A few variables that are implemented | 1577 | @xref{Multiple Displays}. A few variables that are implemented |
| 1562 | specially in Emacs can be (and usually are) buffer-local, but can never | 1578 | specially in Emacs can be (and usually are) buffer-local, but can never |
| 1563 | be frame-local. | 1579 | be frame-local. |
| 1580 | |||
| 1581 | This command returns @var{variable}. | ||
| 1564 | @end deffn | 1582 | @end deffn |
| 1565 | 1583 | ||
| 1566 | Buffer-local bindings take precedence over frame-local bindings. Thus, | 1584 | Buffer-local bindings take precedence over frame-local bindings. Thus, |
| @@ -1675,7 +1693,11 @@ value of @var{alias-var} changes the value of @var{base-var}. | |||
| 1675 | 1693 | ||
| 1676 | If the @var{docstring} argument is non-@code{nil}, it specifies the | 1694 | If the @var{docstring} argument is non-@code{nil}, it specifies the |
| 1677 | documentation for @var{alias-var}; otherwise, the alias gets the same | 1695 | documentation for @var{alias-var}; otherwise, the alias gets the same |
| 1678 | documentation as @var{base-var} has, if any. | 1696 | documentation as @var{base-var} has, if any, unless @var{base-var} is |
| 1697 | itself an alias, in which case @var{alias-var} gets the documentation | ||
| 1698 | of the variable at the end of the chain of aliases. | ||
| 1699 | |||
| 1700 | This function returns @var{base-var}. | ||
| 1679 | @end defun | 1701 | @end defun |
| 1680 | 1702 | ||
| 1681 | @defun indirect-variable variable | 1703 | @defun indirect-variable variable |
| @@ -1693,8 +1715,10 @@ not defined as an alias, the function returns @var{variable}. | |||
| 1693 | (setq bar 2) | 1715 | (setq bar 2) |
| 1694 | bar | 1716 | bar |
| 1695 | @result{} 2 | 1717 | @result{} 2 |
| 1718 | @group | ||
| 1696 | foo | 1719 | foo |
| 1697 | @result{} 2 | 1720 | @result{} 2 |
| 1721 | @end group | ||
| 1698 | (setq foo 0) | 1722 | (setq foo 0) |
| 1699 | bar | 1723 | bar |
| 1700 | @result{} 0 | 1724 | @result{} 0 |
| @@ -1706,7 +1730,9 @@ foo | |||
| 1706 | @section File Local Variables | 1730 | @section File Local Variables |
| 1707 | 1731 | ||
| 1708 | This section describes the functions and variables that affect | 1732 | This section describes the functions and variables that affect |
| 1709 | processing of local variables lists in files. | 1733 | processing of local variables lists in files. @xref{File variables, , |
| 1734 | Local Variables in Files, emacs, The GNU Emacs Manual}, for basic | ||
| 1735 | information about file local variables. | ||
| 1710 | 1736 | ||
| 1711 | @defopt enable-local-variables | 1737 | @defopt enable-local-variables |
| 1712 | This variable controls whether to process file local variables lists. A | 1738 | This variable controls whether to process file local variables lists. A |
| @@ -1715,13 +1741,19 @@ unconditionally; @code{nil} means ignore them; anything else means ask | |||
| 1715 | the user what to do for each file. The default value is @code{t}. | 1741 | the user what to do for each file. The default value is @code{t}. |
| 1716 | @end defopt | 1742 | @end defopt |
| 1717 | 1743 | ||
| 1718 | @defun hack-local-variables &optional force | 1744 | @defun hack-local-variables &optional mode-only |
| 1719 | This function parses, and binds or evaluates as appropriate, any local | 1745 | This function parses, and binds or evaluates as appropriate, any local |
| 1720 | variables specified by the contents of the current buffer. The variable | 1746 | variables specified by the contents of the current buffer. The variable |
| 1721 | @code{enable-local-variables} has its effect here. | 1747 | @code{enable-local-variables} has its effect here. However, this |
| 1722 | 1748 | function does not look for the @samp{mode:} local variable in the | |
| 1723 | The argument @var{force} usually comes from the argument @var{find-file} | 1749 | @w{@samp{-*-}} line. @code{set-auto-mode} does that, also taking |
| 1724 | given to @code{normal-mode}. | 1750 | @code{enable-local-variables} into account. |
| 1751 | |||
| 1752 | If the optional argument @var{mode-only} is non-@code{nil}, then all | ||
| 1753 | this function does is return @code{t} if the @w{@samp{-*-}} line | ||
| 1754 | specifies a mode and @code{nil} otherwise. It does not set the mode | ||
| 1755 | nor any other file local variable. It does not check whether a mode | ||
| 1756 | is specified in the local variables list at the end of the file. | ||
| 1725 | @end defun | 1757 | @end defun |
| 1726 | 1758 | ||
| 1727 | If a file local variable list could specify a function that will | 1759 | If a file local variable list could specify a function that will |
| @@ -1738,7 +1770,15 @@ you should use such a name whenever it is appropriate for the | |||
| 1738 | variable's meaning. The variables @samp{font-lock-keywords}, | 1770 | variable's meaning. The variables @samp{font-lock-keywords}, |
| 1739 | @samp{font-lock-keywords-[0-9]}, and | 1771 | @samp{font-lock-keywords-[0-9]}, and |
| 1740 | @samp{font-lock-syntactic-keywords} cannot be set in a local variable | 1772 | @samp{font-lock-syntactic-keywords} cannot be set in a local variable |
| 1741 | list, either. | 1773 | list, either. These rules can be overridden by giving the variable's |
| 1774 | name a non-@code{nil} @code{safe-local-variable} property. If one | ||
| 1775 | gives it a @code{safe-local-variable} property of @code{t}, then one | ||
| 1776 | can give the variable any file local value. One can also give any | ||
| 1777 | symbol, including the above, a @code{safe-local-variable} property | ||
| 1778 | that is a function taking exactly one argument. In that case, giving | ||
| 1779 | a variable with that name a file local value is only allowed if the | ||
| 1780 | function returns non-@code{nil} when called with that value as | ||
| 1781 | argument. | ||
| 1742 | 1782 | ||
| 1743 | In addition, any variable whose name has a non-@code{nil} | 1783 | In addition, any variable whose name has a non-@code{nil} |
| 1744 | @code{risky-local-variable} property is also ignored. So are all | 1784 | @code{risky-local-variable} property is also ignored. So are all |
| @@ -1750,9 +1790,12 @@ set by a file's local variables list. Any value specified | |||
| 1750 | for one of these variables is ignored. | 1790 | for one of these variables is ignored. |
| 1751 | @end defvar | 1791 | @end defvar |
| 1752 | 1792 | ||
| 1753 | @defun risky-local-variable-p sym | 1793 | @defun risky-local-variable-p sym &optional val |
| 1754 | Returns non-@code{nil} if @var{sym} is risky for any of the reasons | 1794 | If @var{val} is non-@code{nil}, returns non-@code{nil} if giving |
| 1755 | stated above. | 1795 | @var{sym} a file local value of @var{val} would be risky, for any of |
| 1796 | the reasons stated above. If @var{val} is @code{nil} or omitted, only | ||
| 1797 | returns @code{nil} if @var{sym} can be safely assigned any file local | ||
| 1798 | value whatsoever. | ||
| 1756 | @end defun | 1799 | @end defun |
| 1757 | 1800 | ||
| 1758 | The @samp{Eval:} ``variable'' is also a potential loophole, so Emacs | 1801 | The @samp{Eval:} ``variable'' is also a potential loophole, so Emacs |