comparison man/custom.texi @ 68914:5036e00f1d0b

(Safe File Variables): Lots of clarification. Renamed from Unsafe File Variables.
author Richard M. Stallman <rms@gnu.org>
date Wed, 15 Feb 2006 04:33:01 +0000
parents 775681e7a2ad
children 5b3262d81466 9e490faa9f6b
comparison
equal deleted inserted replaced
68913:08407ff48591 68914:5036e00f1d0b
1043 specifications; it automatically makes these variables local to the 1043 specifications; it automatically makes these variables local to the
1044 buffer, and sets them to the values specified in the file. 1044 buffer, and sets them to the values specified in the file.
1045 1045
1046 @menu 1046 @menu
1047 * Specifying File Variables:: Specifying file local variables. 1047 * Specifying File Variables:: Specifying file local variables.
1048 * Unsafe File Variables:: Handling local variables that may not 1048 * Safe File Variables:: Making sure file local variables are safe.
1049 be safe.
1050 @end menu 1049 @end menu
1051 1050
1052 @node Specifying File Variables 1051 @node Specifying File Variables
1053 @subsubsection Specifying File Variables 1052 @subsubsection Specifying File Variables
1054 1053
1055 There are two ways to specify local variable values: in the first 1054 There are two ways to specify file local variable values: in the first
1056 line, or with a local variables list. Here's how to specify them in the 1055 line, or with a local variables list. Here's how to specify them in the
1057 first line: 1056 first line:
1058 1057
1059 @example 1058 @example
1060 -*- mode: @var{modename}; @var{var}: @var{value}; @dots{} -*- 1059 -*- mode: @var{modename}; @var{var}: @var{value}; @dots{} -*-
1096 evaluated; they are used literally. If a file has both a local 1095 evaluated; they are used literally. If a file has both a local
1097 variables list and a @samp{-*-} line, Emacs processes @emph{everything} 1096 variables list and a @samp{-*-} line, Emacs processes @emph{everything}
1098 in the @samp{-*-} line first, and @emph{everything} in the local 1097 in the @samp{-*-} line first, and @emph{everything} in the local
1099 variables list afterward. 1098 variables list afterward.
1100 1099
1101 Here is an example of a local variables list: 1100 Here is an example of a local variables list:
1102 1101
1103 @example 1102 @example
1104 ;;; Local Variables: *** 1103 ;;; Local Variables: ***
1105 ;;; mode:lisp *** 1104 ;;; mode:lisp ***
1106 ;;; comment-column:0 *** 1105 ;;; comment-column:0 ***
1177 1176
1178 Use the command @code{normal-mode} to reset the local variables and 1177 Use the command @code{normal-mode} to reset the local variables and
1179 major mode of a buffer according to the file name and contents, 1178 major mode of a buffer according to the file name and contents,
1180 including the local variables list if any. @xref{Choosing Modes}. 1179 including the local variables list if any. @xref{Choosing Modes}.
1181 1180
1182 @node Unsafe File Variables 1181 @node Safe File Variables
1183 @subsubsection Unsafe File Variables 1182 @subsubsection Safety of File Variables
1184 1183
1185 File variables create a certain amount of risk; when you visit 1184 File-local variables can be dangerous; when you visit someone else's
1186 someone else's file, its variables could affect your Emacs in 1185 file, there's no telling what its local variables list could do to
1187 arbitrary ways. A special risk is posed by the @code{eval} 1186 your Emacs. Improper values of the @code{eval} ``variable,'' and
1188 ``variable,'' which can potentially execute arbitrary code, and 1187 other variables such as @code{load-path}, could execute Lisp code you
1189 certain actual variables such as @code{load-path}. 1188 didn't intend to run.
1190 1189
1191 Therefore, whenever Emacs encounters file variables that are not 1190 Therefore, whenever Emacs encounters file local variable values that
1192 known to be safe, it displays the entire list of variables defined in 1191 are not known to be safe, it displays the file's entire local
1193 that file, and asks you for confirmation before setting them. You can 1192 variables list, and asks you for confirmation before setting them.
1194 type @samp{y} or @samp{SPC} to apply the local variables list, or 1193 You can type @kbd{y} or @key{SPC} to put the local variables list into
1195 @samp{n} to ignore it. 1194 effect, or @kbd{n} to ignore it. When Emacs is run in batch mode
1196 1195 (@pxref{Initial Options}), it can't really ask you, so it assumes the
1197 When Emacs is run in batch mode (@pxref{Initial Options}), it 1196 answer @samp{n}.
1198 assumes that the answer is @samp{n}. 1197
1199 1198 Emacs normally recognizes certain variables/value pairs as safe.
1200 There is a set of file variables and values that are known to be 1199 For instance, it is safe to give @code{comment-column} or
1201 safe. For instance, it is safe to give @code{comment-column} or
1202 @code{fill-column} any integer value. If a file specifies only safe 1200 @code{fill-column} any integer value. If a file specifies only safe
1203 variable-value pairs, Emacs will not ask for confirmation before 1201 variable/value pairs, Emacs does not ask for confirmation before
1204 setting them. You can also tell Emacs that a set of variable-value 1202 setting them. Otherwise, you can tell Emacs to record that all the
1205 pairs is safe, by entering @samp{!} at the file variables confirmation 1203 variable/value pairs in the file are safe, by typing @kbd{!} at the
1206 prompt. In that case, Emacs will not ask for confirmation if it 1204 confirmation prompt. When Emacs encounters these variable/value pairs
1207 encounters these variable-value pairs in the future. You can directly 1205 subsequently, in the same file or others, it will assume they are
1208 edit the list of safe variable-value pairs by customizing 1206 safe.
1207
1208 @vindex safe-local-variable-values
1209 @cindex risky variable
1210 Some variables, such as @code{load-path}, are considered
1211 particularly @dfn{risky}: there is seldom any reason to specify them
1212 as local variables, and changing them can be dangerous. Even if you
1213 enter @kbd{!} at the confirmation prompt, Emacs will not record any
1214 values as safe for these variables. If you really want to record safe
1215 values for these variables, do it directly by customizing
1209 @samp{safe-local-variable-values} (@pxref{Easy Customization}). 1216 @samp{safe-local-variable-values} (@pxref{Easy Customization}).
1210 1217
1211 Some variables, such as @code{load-path}, are considered 1218 @vindex enable-local-variables
1212 @dfn{risky}: there is seldom any reason to specify them as file
1213 variables, and changing them can be dangerous. Even if you enter
1214 @samp{!} at the confirmation prompt, Emacs will not save these values
1215 for the future. Therefore, you will be prompted each time the
1216 variable is encountered. If you really want to allow such a variable,
1217 you can avoid the prompt by editing @samp{safe-local-variable-values}.
1218
1219 @findex enable-local-variables
1220 The variable @code{enable-local-variables} allows you to change the 1219 The variable @code{enable-local-variables} allows you to change the
1221 way Emacs processes local variables. Its default value is @code{t}, 1220 way Emacs processes local variables. Its default value is @code{t},
1222 which means the behavior described above. If you set the value to 1221 which specifies the behavior described above. If it is @code{nil},
1223 @code{nil}, Emacs simply ignores local variables in files. Any other 1222 Emacs simply ignores all file local variables. Any other value says
1224 value says to query you about each file that has local variables, even 1223 to query you about each file that has local variables, without trying
1225 if the variables are known to be safe. 1224 to determine whether the values are known to be safe.
1226 1225
1227 @findex enable-local-eval 1226 @vindex enable-local-eval
1228 The variable @code{enable-local-eval} controls whether Emacs 1227 The variable @code{enable-local-eval} controls whether Emacs
1229 processes @code{eval} variables. The three possibilities for the 1228 processes @code{eval} variables. The three possibilities for the
1230 variable's value are @code{t}, @code{nil}, and anything else, just as 1229 variable's value are @code{t}, @code{nil}, and anything else, just as
1231 for @code{enable-local-variables}. The default is @code{maybe}, which 1230 for @code{enable-local-variables}. The default is @code{maybe}, which
1232 is neither @code{t} nor @code{nil}, so normally Emacs does ask for 1231 is neither @code{t} nor @code{nil}, so normally Emacs does ask for
1233 confirmation about processes @code{eval} variables. 1232 confirmation about processes @code{eval} variables.
1234 1233
1235 @findex safe-local-eval-forms 1234 @vindex safe-local-eval-forms
1236 The @code{safe-local-eval-forms} is a customizable list of eval 1235 The @code{safe-local-eval-forms} is a customizable list of eval
1237 forms which are safe to eval, so Emacs should not ask for 1236 forms which are safe to eval, so Emacs should not ask for
1238 confirmation to evaluate these forms. 1237 confirmation to evaluate these forms.
1239 1238
1240 @node Key Bindings 1239 @node Key Bindings