diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/command_002dline-arguments.html | |
new repository
Diffstat (limited to 'devdocs/elisp/command_002dline-arguments.html')
| -rw-r--r-- | devdocs/elisp/command_002dline-arguments.html | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/devdocs/elisp/command_002dline-arguments.html b/devdocs/elisp/command_002dline-arguments.html new file mode 100644 index 00000000..bbe6e4fb --- /dev/null +++ b/devdocs/elisp/command_002dline-arguments.html @@ -0,0 +1,30 @@ + <h4 class="subsection">Command-Line Arguments</h4> <p>You can use command-line arguments to request various actions when you start Emacs. Note that the recommended way of using Emacs is to start it just once, after logging in, and then do all editing in the same Emacs session (see <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Entering-Emacs.html#Entering-Emacs">Entering Emacs</a> in <cite>The GNU Emacs Manual</cite>). For this reason, you might not use command-line arguments very often; nonetheless, they can be useful when invoking Emacs from session scripts or debugging Emacs. This section describes how Emacs processes command-line arguments. </p> <dl> <dt id="command-line">Function: <strong>command-line</strong> +</dt> <dd><p>This function parses the command line that Emacs was called with, processes it, and (amongst other things) loads the user’s init file and displays the startup messages. </p></dd> +</dl> <dl> <dt id="command-line-processed">Variable: <strong>command-line-processed</strong> +</dt> <dd> +<p>The value of this variable is <code>t</code> once the command line has been processed. </p> <p>If you redump Emacs by calling <code>dump-emacs</code> (see <a href="building-emacs">Building Emacs</a>), you may wish to set this variable to <code>nil</code> first in order to cause the new dumped Emacs to process its new command-line arguments. </p> +</dd> +</dl> <dl> <dt id="command-switch-alist">Variable: <strong>command-switch-alist</strong> +</dt> <dd> + <p>This variable is an alist of user-defined command-line options and associated handler functions. By default it is empty, but you can add elements if you wish. </p> <p>A <em>command-line option</em> is an argument on the command line, which has the form: </p> <div class="example"> <pre class="example">-<var>option</var> +</pre> +</div> <p>The elements of the <code>command-switch-alist</code> look like this: </p> <div class="example"> <pre class="example">(<var>option</var> . <var>handler-function</var>) +</pre> +</div> <p>The <small>CAR</small>, <var>option</var>, is a string, the name of a command-line option (including the initial hyphen). The <var>handler-function</var> is called to handle <var>option</var>, and receives the option name as its sole argument. </p> <p>In some cases, the option is followed in the command line by an argument. In these cases, the <var>handler-function</var> can find all the remaining command-line arguments in the variable <code>command-line-args-left</code> (see below). (The entire list of command-line arguments is in <code>command-line-args</code>.) </p> <p>Note that the handling of <code>command-switch-alist</code> doesn’t treat equals signs in <var>option</var> specially. That is, if there’s an option like <code>--name=value</code> on the command line, then only a <code>command-switch-alist</code> member whose <code>car</code> is literally <code>--name=value</code> will match this option. If you want to parse such options, you need to use <code>command-line-functions</code> instead (see below). </p> <p>The command-line arguments are parsed by the <code>command-line-1</code> function in the <samp>startup.el</samp> file. See also <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Invocation.html#Emacs-Invocation">Command Line Arguments for Emacs Invocation</a> in <cite>The GNU Emacs Manual</cite>. </p> +</dd> +</dl> <dl> <dt id="command-line-args">Variable: <strong>command-line-args</strong> +</dt> <dd><p>The value of this variable is the list of command-line arguments passed to Emacs. </p></dd> +</dl> <dl> <dt id="command-line-args-left">Variable: <strong>command-line-args-left</strong> +</dt> <dd> + <p>The value of this variable is the list of command-line arguments that have not yet been processed. </p> +</dd> +</dl> <dl> <dt id="command-line-functions">Variable: <strong>command-line-functions</strong> +</dt> <dd> +<p>This variable’s value is a list of functions for handling an unrecognized command-line argument. Each time the next argument to be processed has no special meaning, the functions in this list are called, in order of appearance, until one of them returns a non-<code>nil</code> value. </p> <p>These functions are called with no arguments. They can access the command-line argument under consideration through the variable <code>argi</code>, which is bound temporarily at this point. The remaining arguments (not including the current one) are in the variable <code>command-line-args-left</code>. </p> <p>When a function recognizes and processes the argument in <code>argi</code>, it should return a non-<code>nil</code> value to say it has dealt with that argument. If it has also dealt with some of the following arguments, it can indicate that by deleting them from <code>command-line-args-left</code>. </p> <p>If all of these functions return <code>nil</code>, then the argument is treated as a file name to visit. </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/Command_002dLine-Arguments.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Command_002dLine-Arguments.html</a> + </p> +</div> |
