diff options
Diffstat (limited to 'devdocs/elisp/default-value.html')
| -rw-r--r-- | devdocs/elisp/default-value.html | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/devdocs/elisp/default-value.html b/devdocs/elisp/default-value.html deleted file mode 100644 index 559d29df..00000000 --- a/devdocs/elisp/default-value.html +++ /dev/null @@ -1,76 +0,0 @@ - <h4 class="subsection">The Default Value of a Buffer-Local Variable</h4> <p>The global value of a variable with buffer-local bindings is also called the <em>default</em> value, because it is the value that is in effect whenever neither the current buffer nor the selected frame has its own binding for the variable. </p> <p>The functions <code>default-value</code> and <code>setq-default</code> access and change a variable’s default value regardless of whether the current buffer has a buffer-local binding. For example, you could use <code>setq-default</code> to change the default setting of <code>paragraph-start</code> for most buffers; and this would work even when you are in a C or Lisp mode buffer that has a buffer-local value for this variable. </p> <p>The special forms <code>defvar</code> and <code>defconst</code> also set the default value (if they set the variable at all), rather than any buffer-local value. </p> <dl> <dt id="default-value">Function: <strong>default-value</strong> <em>symbol</em> -</dt> <dd><p>This function returns <var>symbol</var>’s default value. This is the value that is seen in buffers and frames that do not have their own values for this variable. If <var>symbol</var> is not buffer-local, this is equivalent to <code>symbol-value</code> (see <a href="accessing-variables">Accessing Variables</a>). </p></dd> -</dl> <dl> <dt id="default-boundp">Function: <strong>default-boundp</strong> <em>symbol</em> -</dt> <dd> -<p>The function <code>default-boundp</code> tells you whether <var>symbol</var>’s default value is nonvoid. If <code>(default-boundp 'foo)</code> returns <code>nil</code>, then <code>(default-value 'foo)</code> would get an error. </p> <p><code>default-boundp</code> is to <code>default-value</code> as <code>boundp</code> is to <code>symbol-value</code>. </p> -</dd> -</dl> <dl> <dt id="setq-default">Special Form: <strong>setq-default</strong> <em>[symbol form]…</em> -</dt> <dd> -<p>This special form gives each <var>symbol</var> a new default value, which is the result of evaluating the corresponding <var>form</var>. It does not evaluate <var>symbol</var>, but does evaluate <var>form</var>. The value of the <code>setq-default</code> form is the value of the last <var>form</var>. </p> <p>If a <var>symbol</var> is not buffer-local for the current buffer, and is not marked automatically buffer-local, <code>setq-default</code> has the same effect as <code>setq</code>. If <var>symbol</var> is buffer-local for the current buffer, then this changes the value that other buffers will see (as long as they don’t have a buffer-local value), but not the value that the current buffer sees. </p> <div class="example"> <pre class="example">;; <span class="roman">In buffer ‘<samp>foo</samp>’:</span> -(make-local-variable 'buffer-local) - ⇒ buffer-local -</pre> -<pre class="example">(setq buffer-local 'value-in-foo) - ⇒ value-in-foo -</pre> -<pre class="example">(setq-default buffer-local 'new-default) - ⇒ new-default -</pre> -<pre class="example">buffer-local - ⇒ value-in-foo -</pre> -<pre class="example">(default-value 'buffer-local) - ⇒ new-default -</pre> - -<pre class="example">;; <span class="roman">In (the new) buffer ‘<samp>bar</samp>’:</span> -buffer-local - ⇒ new-default -</pre> -<pre class="example">(default-value 'buffer-local) - ⇒ new-default -</pre> -<pre class="example">(setq buffer-local 'another-default) - ⇒ another-default -</pre> -<pre class="example">(default-value 'buffer-local) - ⇒ another-default -</pre> - -<pre class="example">;; <span class="roman">Back in buffer ‘<samp>foo</samp>’:</span> -buffer-local - ⇒ value-in-foo -(default-value 'buffer-local) - ⇒ another-default -</pre> -</div> </dd> -</dl> <dl> <dt id="set-default">Function: <strong>set-default</strong> <em>symbol value</em> -</dt> <dd> -<p>This function is like <code>setq-default</code>, except that <var>symbol</var> is an ordinary evaluated argument. </p> <div class="example"> <pre class="example">(set-default (car '(a b c)) 23) - ⇒ 23 -</pre> -<pre class="example">(default-value 'a) - ⇒ 23 -</pre> -</div> </dd> -</dl> <p>A variable can be let-bound (see <a href="local-variables">Local Variables</a>) to a value. This makes its global value shadowed by the binding; <code>default-value</code> will then return the value from that binding, not the global value, and <code>set-default</code> will be prevented from setting the global value (it will change the let-bound value instead). The following two functions allow to reference the global value even if it’s shadowed by a let-binding. </p> <dl> <dt id="default-toplevel-value">Function: <strong>default-toplevel-value</strong> <em>symbol</em> -</dt> <dd><p>This function returns the <em>top-level</em> default value of <var>symbol</var>, which is its value outside of any let-binding. </p></dd> -</dl> <div class="example"> <pre class="example">(defvar variable 'global-value) - ⇒ variable -</pre> -<pre class="example">(let ((variable 'let-binding)) - (default-value 'variable)) - ⇒ let-binding -</pre> -<pre class="example">(let ((variable 'let-binding)) - (default-toplevel-value 'variable)) - ⇒ global-value -</pre> -</div> <dl> <dt id="set-default-toplevel-value">Function: <strong>set-default-toplevel-value</strong> <em>symbol value</em> -</dt> <dd><p>This function sets the top-level default value of <var>symbol</var> to the specified <var>value</var>. This comes in handy when you want to set the global value of <var>symbol</var> regardless of whether your code runs in the context of <var>symbol</var>’s let-binding. </p></dd> -</dl><div class="_attribution"> - <p class="_attribution-p"> - Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> - <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Default-Value.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Default-Value.html</a> - </p> -</div> |
