summaryrefslogtreecommitdiff
path: root/devdocs/elisp/system-environment.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/system-environment.html
new repository
Diffstat (limited to 'devdocs/elisp/system-environment.html')
-rw-r--r--devdocs/elisp/system-environment.html104
1 files changed, 104 insertions, 0 deletions
diff --git a/devdocs/elisp/system-environment.html b/devdocs/elisp/system-environment.html
new file mode 100644
index 00000000..b51bc671
--- /dev/null
+++ b/devdocs/elisp/system-environment.html
@@ -0,0 +1,104 @@
+ <h3 class="section">Operating System Environment</h3> <p>Emacs provides access to variables in the operating system environment through various functions. These variables include the name of the system, the user’s <acronym>UID</acronym>, and so on. </p> <dl> <dt id="system-configuration">Variable: <strong>system-configuration</strong>
+</dt> <dd><p>This variable holds the standard GNU configuration name for the hardware/software configuration of your system, as a string. For example, a typical value for a 64-bit GNU/Linux system is ‘<samp>"x86_64-unknown-linux-gnu"</samp>’. </p></dd>
+</dl> <dl> <dt id="system-type">Variable: <strong>system-type</strong>
+</dt> <dd>
+<p>The value of this variable is a symbol indicating the type of operating system Emacs is running on. The possible values are: </p> <dl compact> <dt><code>aix</code></dt> <dd>
+<p>IBM’s AIX. </p> </dd> <dt><code>berkeley-unix</code></dt> <dd>
+<p>Berkeley BSD and its variants. </p> </dd> <dt><code>cygwin</code></dt> <dd>
+<p>Cygwin, a POSIX layer on top of MS-Windows. </p> </dd> <dt><code>darwin</code></dt> <dd>
+<p>Darwin (macOS). </p> </dd> <dt><code>gnu</code></dt> <dd>
+<p>The GNU system (using the GNU kernel, which consists of the HURD and Mach). </p> </dd> <dt><code>gnu/linux</code></dt> <dd>
+<p>A GNU/Linux system—that is, a variant GNU system, using the Linux kernel. (These systems are the ones people often call “Linux”, but actually Linux is just the kernel, not the whole system.) </p> </dd> <dt><code>gnu/kfreebsd</code></dt> <dd>
+<p>A GNU (glibc-based) system with a FreeBSD kernel. </p> </dd> <dt><code>hpux</code></dt> <dd>
+<p>Hewlett-Packard HPUX operating system. </p> </dd> <dt><code>nacl</code></dt> <dd>
+<p>Google Native Client (<acronym>NaCl</acronym>) sandboxing system. </p> </dd> <dt><code>ms-dos</code></dt> <dd>
+<p>Microsoft’s DOS. Emacs compiled with DJGPP for MS-DOS binds <code>system-type</code> to <code>ms-dos</code> even when you run it on MS-Windows. </p> </dd> <dt><code>usg-unix-v</code></dt> <dd>
+<p>AT&amp;T Unix System V. </p> </dd> <dt><code>windows-nt</code></dt> <dd>
+<p>Microsoft Windows NT, 9X and later. The value of <code>system-type</code> is always <code>windows-nt</code>, e.g., even on Windows 10. </p> </dd> </dl> <p>We do not wish to add new symbols to make finer distinctions unless it is absolutely necessary! In fact, we hope to eliminate some of these alternatives in the future. If you need to make a finer distinction than <code>system-type</code> allows for, you can test <code>system-configuration</code>, e.g., against a regexp. </p>
+</dd>
+</dl> <dl> <dt id="system-name">Function: <strong>system-name</strong>
+</dt> <dd><p>This function returns the name of the machine you are running on, as a string. </p></dd>
+</dl> <dl> <dt id="mail-host-address">User Option: <strong>mail-host-address</strong>
+</dt> <dd><p>If this variable is non-<code>nil</code>, it is used instead of <code>system-name</code> for purposes of generating email addresses. For example, it is used when constructing the default value of <code>user-mail-address</code>. See <a href="user-identification">User Identification</a>. </p></dd>
+</dl> <dl> <dt id="getenv">Command: <strong>getenv</strong> <em>var &amp;optional frame</em>
+</dt> <dd>
+ <p>This function returns the value of the environment variable <var>var</var>, as a string. <var>var</var> should be a string. If <var>var</var> is undefined in the environment, <code>getenv</code> returns <code>nil</code>. It returns ‘<samp>""</samp>’ if <var>var</var> is set but null. Within Emacs, a list of environment variables and their values is kept in the variable <code>process-environment</code>. </p> <div class="example"> <pre class="example">(getenv "USER")
+ ⇒ "lewis"
+</pre>
+</div> <p>The shell command <code>printenv</code> prints all or part of the environment: </p> <div class="example"> <pre class="example">bash$ printenv
+PATH=/usr/local/bin:/usr/bin:/bin
+USER=lewis
+</pre>
+<pre class="example">TERM=xterm
+SHELL=/bin/bash
+HOME=/home/lewis
+</pre>
+<pre class="example">…
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="setenv">Command: <strong>setenv</strong> <em>variable &amp;optional value substitute</em>
+</dt> <dd>
+<p>This command sets the value of the environment variable named <var>variable</var> to <var>value</var>. <var>variable</var> should be a string. Internally, Emacs Lisp can handle any string. However, normally <var>variable</var> should be a valid shell identifier, that is, a sequence of letters, digits and underscores, starting with a letter or underscore. Otherwise, errors may occur if subprocesses of Emacs try to access the value of <var>variable</var>. If <var>value</var> is omitted or <code>nil</code> (or, interactively, with a prefix argument), <code>setenv</code> removes <var>variable</var> from the environment. Otherwise, <var>value</var> should be a string. </p> <p>If the optional argument <var>substitute</var> is non-<code>nil</code>, Emacs calls the function <code>substitute-env-vars</code> to expand any environment variables in <var>value</var>. </p> <p><code>setenv</code> works by modifying <code>process-environment</code>; binding that variable with <code>let</code> is also reasonable practice. </p> <p><code>setenv</code> returns the new value of <var>variable</var>, or <code>nil</code> if it removed <var>variable</var> from the environment. </p>
+</dd>
+</dl> <dl> <dt id="with-environment-variables">Macro: <strong>with-environment-variables</strong> <em>variables body…</em>
+</dt> <dd>
+<p>This macro sets the environment variables according to <var>variables</var> temporarily when executing <var>body</var>. The previous values are restored when the form finishes. The argument <var>variables</var> should be a list of pairs of strings of the form <code>(<var>var</var> <var>value</var>)</code>, where <var>var</var> is the name of the environment variable and <var>value</var> is that variable’s value. </p> <div class="lisp"> <pre class="lisp">(with-environment-variables (("LANG" "C")
+ ("LANGUAGE" "en_US:en"))
+ (call-process "ls" nil t))
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="process-environment">Variable: <strong>process-environment</strong>
+</dt> <dd>
+<p>This variable is a list of strings, each describing one environment variable. The functions <code>getenv</code> and <code>setenv</code> work by means of this variable. </p> <div class="example"> <pre class="example">process-environment
+⇒ ("PATH=/usr/local/bin:/usr/bin:/bin"
+ "USER=lewis"
+</pre>
+<pre class="example"> "TERM=xterm"
+ "SHELL=/bin/bash"
+ "HOME=/home/lewis"
+ …)
+</pre>
+</div> <p>If <code>process-environment</code> contains multiple elements that specify the same environment variable, the first of these elements specifies the variable, and the others are ignored. </p>
+</dd>
+</dl> <dl> <dt id="initial-environment">Variable: <strong>initial-environment</strong>
+</dt> <dd><p>This variable holds the list of environment variables Emacs inherited from its parent process when Emacs started. </p></dd>
+</dl> <dl> <dt id="path-separator">Variable: <strong>path-separator</strong>
+</dt> <dd><p>This variable holds a string that says which character separates directories in a search path (as found in an environment variable). Its value is <code>":"</code> for Unix and GNU systems, and <code>";"</code> for MS systems. </p></dd>
+</dl> <dl> <dt id="path-separator">Function: <strong>path-separator</strong>
+</dt> <dd><p>This function returns the connection-local value of variable <code>path-separator</code>. That is <code>";"</code> for MS systems and a local <code>default-directory</code>, and <code>":"</code> for Unix and GNU systems, or a remote <code>default-directory</code>. </p></dd>
+</dl> <dl> <dt id="parse-colon-path">Function: <strong>parse-colon-path</strong> <em>path</em>
+</dt> <dd>
+<p>This function takes a search path string such as the value of the <code>PATH</code> environment variable, and splits it at the separators, returning a list of directories. <code>nil</code> in this list means the current directory. Although the function’s name says “colon”, it actually uses the value of variable <code>path-separator</code>. </p> <div class="example"> <pre class="example">(parse-colon-path ":/foo:/bar")
+ ⇒ (nil "/foo/" "/bar/")
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="invocation-name">Variable: <strong>invocation-name</strong>
+</dt> <dd><p>This variable holds the program name under which Emacs was invoked. The value is a string, and does not include a directory name. </p></dd>
+</dl> <dl> <dt id="invocation-directory">Variable: <strong>invocation-directory</strong>
+</dt> <dd><p>This variable holds the directory in which the Emacs executable was located when it was run, or <code>nil</code> if that directory cannot be determined. </p></dd>
+</dl> <dl> <dt id="installation-directory">Variable: <strong>installation-directory</strong>
+</dt> <dd><p>If non-<code>nil</code>, this is a directory within which to look for the <samp>lib-src</samp> and <samp>etc</samp> subdirectories. In an installed Emacs, it is normally <code>nil</code>. It is non-<code>nil</code> when Emacs can’t find those directories in their standard installed locations, but can find them in a directory related somehow to the one containing the Emacs executable (i.e., <code>invocation-directory</code>). </p></dd>
+</dl> <dl> <dt id="load-average">Function: <strong>load-average</strong> <em>&amp;optional use-float</em>
+</dt> <dd>
+<p>This function returns the current 1-minute, 5-minute, and 15-minute system load averages, in a list. The load average indicates the number of processes trying to run on the system. </p> <p>By default, the values are integers that are 100 times the system load averages, but if <var>use-float</var> is non-<code>nil</code>, then they are returned as floating-point numbers without multiplying by 100. </p> <p>If it is impossible to obtain the load average, this function signals an error. On some platforms, access to load averages requires installing Emacs as setuid or setgid so that it can read kernel information, and that usually isn’t advisable. </p> <p>If the 1-minute load average is available, but the 5- or 15-minute averages are not, this function returns a shortened list containing the available averages. </p> <div class="example"> <pre class="example">(load-average)
+ ⇒ (169 48 36)
+</pre>
+<pre class="example">(load-average t)
+ ⇒ (1.69 0.48 0.36)
+</pre>
+</div> <p>The shell command <code>uptime</code> returns similar information. </p>
+</dd>
+</dl> <dl> <dt id="emacs-pid">Function: <strong>emacs-pid</strong>
+</dt> <dd><p>This function returns the process <acronym>ID</acronym> of the Emacs process, as an integer. </p></dd>
+</dl> <dl> <dt id="tty-erase-char">Variable: <strong>tty-erase-char</strong>
+</dt> <dd><p>This variable holds the erase character that was selected in the system’s terminal driver, before Emacs was started. </p></dd>
+</dl> <dl> <dt id="null-device">Variable: <strong>null-device</strong>
+</dt> <dd><p>This variable holds the system null device. Its value is <code>"/dev/null"</code> for Unix and GNU systems, and <code>"NUL"</code> for MS systems. </p></dd>
+</dl> <dl> <dt id="null-device">Function: <strong>null-device</strong>
+</dt> <dd><p>This function returns the connection-local value of variable <code>null-device</code>. That is <code>"NUL"</code> for MS systems and a local <code>default-directory</code>, and <code>"/dev/null"</code> for Unix and GNU systems, or a remote <code>default-directory</code>. </p></dd>
+</dl><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 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/System-Environment.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/System-Environment.html</a>
+ </p>
+</div>