File: Manipulating-the-Load-Path.html

package info (click to toggle)
octave 10.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 145,388 kB
  • sloc: cpp: 335,976; ansic: 82,241; fortran: 20,963; objc: 9,402; sh: 8,756; yacc: 4,392; lex: 4,333; perl: 1,544; java: 1,366; awk: 1,259; makefile: 659; xml: 192
file content (406 lines) | stat: -rw-r--r-- 26,994 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Manipulating the Load Path (GNU Octave (version 10.3.0))</title>

<meta name="description" content="Manipulating the Load Path (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Manipulating the Load Path (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Function-Files.html" rel="up" title="Function Files">
<link href="Subfunctions.html" rel="next" title="Subfunctions">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<div class="subsection-level-extent" id="Manipulating-the-Load-Path">
<div class="nav-panel">
<p>
Next: <a href="Subfunctions.html" accesskey="n" rel="next">Subfunctions</a>, Up: <a href="Function-Files.html" accesskey="u" rel="up">Function Files</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Manipulating-the-Load-Path-1"><span>11.10.1 Manipulating the Load Path<a class="copiable-link" href="#Manipulating-the-Load-Path-1"> &para;</a></span></h4>

<p>When a function is called, Octave searches a list of directories for
a file that contains the function declaration.  This list of directories
is known as the load path.  By default the load path contains
a list of directories distributed with Octave plus the current
working directory.  To see your current load path call the <code class="code">path</code>
function without any input or output arguments.
</p>
<p>It is possible to add or remove directories to or from the load path
using <code class="code">addpath</code> and <code class="code">rmpath</code>.  As an example, the following
code adds &lsquo;<samp class="samp">~/Octave</samp>&rsquo; to the load path.
</p>
<div class="example">
<pre class="example-preformatted">addpath (&quot;~/Octave&quot;)
</pre></div>

<p>After this the directory &lsquo;<samp class="samp">~/Octave</samp>&rsquo; will be searched for functions.
</p>
<a class="anchor" id="XREFaddpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-addpath"><span><strong class="def-name">addpath</strong> <code class="def-code-arguments">(<var class="var">dir1</var>, &hellip;)</code><a class="copiable-link" href="#index-addpath"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-addpath-1"><span><strong class="def-name">addpath</strong> <code class="def-code-arguments">(<var class="var">dir1</var>, &hellip;, <var class="var">option</var>)</code><a class="copiable-link" href="#index-addpath-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-addpath-2"><span><code class="def-type"><var class="var">oldpath</var> =</code> <strong class="def-name">addpath</strong> <code class="def-code-arguments">(&hellip;)</code><a class="copiable-link" href="#index-addpath-2"> &para;</a></span></dt>
<dd><p>Add named directories to the function search path.
</p>
<p>If <var class="var">option</var> is <code class="code">&quot;-begin&quot;</code> or 0 (the default), prepend the directory
name(s) to the current path.  If <var class="var">option</var> is <code class="code">&quot;-end&quot;</code> or 1, append
the directory name(s) to the current path.  Directories added to the path must
exist.
</p>
<p>In addition to accepting individual directory arguments, lists of
directory names separated by <code class="code">pathsep</code> are also accepted.  For example:
</p>
<div class="example">
<pre class="example-preformatted">addpath (&quot;dir1:/dir2:~/dir3&quot;)
</pre></div>

<p>The newly added paths appear in the load path in the same order that they
appear in the arguments of <code class="code">addpath</code>.  When extending the load path to
the front, the last path in the list of arguments is added first.  When
extending the load path to the end, the first path in the list of arguments
is added first.
</p>
<p>For each directory that is added, and that was not already in the path,
<code class="code">addpath</code> checks for the existence of a file named <samp class="file">PKG_ADD</samp>
(note lack of .m extension) and runs it if it exists.
</p>

<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFrmpath">rmpath</a>, <a class="ref" href="#XREFgenpath">genpath</a>, <a class="ref" href="#XREFpathdef">pathdef</a>, <a class="ref" href="#XREFsavepath">savepath</a>, <a class="ref" href="#XREFpathsep">pathsep</a>.
</p></dd></dl>


<a class="anchor" id="XREFgenpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-genpath"><span><code class="def-type"><var class="var">pathstr</var> =</code> <strong class="def-name">genpath</strong> <code class="def-code-arguments">(<var class="var">dir</var>)</code><a class="copiable-link" href="#index-genpath"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-genpath-1"><span><code class="def-type"><var class="var">pathstr</var> =</code> <strong class="def-name">genpath</strong> <code class="def-code-arguments">(<var class="var">dir</var>, <var class="var">skipdir1</var>, &hellip;)</code><a class="copiable-link" href="#index-genpath-1"> &para;</a></span></dt>
<dd><p>Return a path constructed from <var class="var">dir</var> and all its subdirectories.
</p>
<p>The path does not include package directories (beginning with &lsquo;<samp class="samp">+</samp>&rsquo;),
old-style class directories (beginning with &lsquo;<samp class="samp">@</samp>&rsquo;), <samp class="file">private</samp>
directories, or any subdirectories of these types.
</p>
<p>If additional string parameters are given, the resulting path will exclude
directories with those names.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFaddpath">addpath</a>.
</p></dd></dl>


<a class="anchor" id="XREFrmpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-rmpath"><span><strong class="def-name">rmpath</strong> <code class="def-code-arguments">(<var class="var">dir1</var>, &hellip;)</code><a class="copiable-link" href="#index-rmpath"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-rmpath-1"><span><code class="def-type"><var class="var">oldpath</var> =</code> <strong class="def-name">rmpath</strong> <code class="def-code-arguments">(<var class="var">dir1</var>, &hellip;)</code><a class="copiable-link" href="#index-rmpath-1"> &para;</a></span></dt>
<dd><p>Remove <var class="var">dir1</var>, &hellip; from the current function search path.
</p>
<p>In addition to accepting individual directory arguments, lists of
directory names separated by <code class="code">pathsep</code> are also accepted.  For example:
</p>
<div class="example">
<pre class="example-preformatted">rmpath (&quot;dir1:/dir2:~/dir3&quot;)
</pre></div>

<p>For each directory that is removed, <code class="code">rmpath</code> checks for the
existence of a file named <samp class="file">PKG_DEL</samp> (note lack of .m extension)
and runs it if it exists.
</p>

<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFaddpath">addpath</a>, <a class="ref" href="#XREFgenpath">genpath</a>, <a class="ref" href="#XREFpathdef">pathdef</a>, <a class="ref" href="#XREFsavepath">savepath</a>, <a class="ref" href="#XREFpathsep">pathsep</a>.
</p></dd></dl>


<a class="anchor" id="XREFsavepath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-savepath"><span><strong class="def-name">savepath</strong><a class="copiable-link" href="#index-savepath"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-savepath-1"><span><strong class="def-name">savepath</strong> <code class="def-code-arguments"><var class="var">file</var></code><a class="copiable-link" href="#index-savepath-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-savepath-2"><span><code class="def-type"><var class="var">status</var> =</code> <strong class="def-name">savepath</strong> <code class="def-code-arguments">(&hellip;)</code><a class="copiable-link" href="#index-savepath-2"> &para;</a></span></dt>
<dd><p>Save the unique portion of the current function search path to <var class="var">file</var>.
</p>
<p>The list of folders that are saved in <var class="var">file</var> does <em class="emph">not</em> include
the folders that are added for Octave&rsquo;s own functions, those that belong to
Octave packages (see <a class="ref" href="Installing-and-Removing-Packages.html#XREFpkg">pkg load</a>), and those added via command
line switches.
</p>
<p>If <var class="var">file</var> is omitted, Octave looks in the current directory for a
project-specific <samp class="file">.octaverc</samp> file in which to save the path
information.  If no such file is present then the user&rsquo;s configuration file
<samp class="file">~/.octaverc</samp> is used.
</p>
<p>If successful, <code class="code">savepath</code> returns 0.
</p>
<p>The <code class="code">savepath</code> function makes it simple to customize a user&rsquo;s
configuration file to restore the working paths necessary for a particular
instance of Octave.  Assuming no filename is specified, Octave will
automatically restore the saved directory paths from the appropriate
<samp class="file">.octaverc</samp> file when starting up.  If a filename has been specified
then the paths may be restored manually by calling <code class="code">source <var class="var">file</var></code>.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFaddpath">addpath</a>, <a class="ref" href="#XREFrmpath">rmpath</a>, <a class="ref" href="#XREFgenpath">genpath</a>, <a class="ref" href="#XREFpathdef">pathdef</a>.
</p></dd></dl>


<a class="anchor" id="XREFpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-path"><span><strong class="def-name">path</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-path"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-path-1"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">path</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-path-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-path-2"><span><code class="def-type"><var class="var">str</var> =</code> <strong class="def-name">path</strong> <code class="def-code-arguments">(<var class="var">path1</var>, &hellip;)</code><a class="copiable-link" href="#index-path-2"> &para;</a></span></dt>
<dd><p>Modify or display Octave&rsquo;s load path.
</p>
<p>If <var class="var">nargin</var> and <var class="var">nargout</var> are zero, display the elements of
Octave&rsquo;s load path in an easy to read format.
</p>
<p>If <var class="var">nargin</var> is zero and nargout is greater than zero, return the
current load path.
</p>
<p>If <var class="var">nargin</var> is greater than zero, concatenate the arguments,
separating them with <code class="code">pathsep</code>.  Set the internal search path
to the result and return it.
</p>
<p>No checks are made for duplicate elements.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFaddpath">addpath</a>, <a class="ref" href="#XREFrmpath">rmpath</a>, <a class="ref" href="#XREFgenpath">genpath</a>, <a class="ref" href="#XREFpathdef">pathdef</a>, <a class="ref" href="#XREFsavepath">savepath</a>, <a class="ref" href="#XREFpathsep">pathsep</a>.
</p></dd></dl>


<a class="anchor" id="XREFpathdef"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-pathdef"><span><code class="def-type"><var class="var">val</var> =</code> <strong class="def-name">pathdef</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-pathdef"> &para;</a></span></dt>
<dd><p>Return the default path for Octave.
</p>
<p>The path information is extracted from one of four sources.
The possible sources, in order of preference, are:
</p>
<ol class="enumerate">
<li> <samp class="file">.octaverc</samp>

</li><li> <samp class="file">~/.octaverc</samp>

</li><li> <samp class="file">&lt;OCTAVE_HOME&gt;/&hellip;/&lt;version&gt;/m/startup/octaverc</samp>

</li><li> Octave&rsquo;s path prior to changes by any octaverc file.
</li></ol>

<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFaddpath">addpath</a>, <a class="ref" href="#XREFrmpath">rmpath</a>, <a class="ref" href="#XREFgenpath">genpath</a>, <a class="ref" href="#XREFsavepath">savepath</a>.
</p></dd></dl>


<a class="anchor" id="XREFpathsep"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-pathsep"><span><code class="def-type"><var class="var">val</var> =</code> <strong class="def-name">pathsep</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-pathsep"> &para;</a></span></dt>
<dd><p>Query the character used to separate directories in a path.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Filesystem-Utilities.html#XREFfilesep">filesep</a>.
</p></dd></dl>


<a class="anchor" id="XREFrehash"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-rehash"><span><strong class="def-name">rehash</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-rehash"> &para;</a></span></dt>
<dd><p>Reinitialize Octave&rsquo;s load path directory cache.
</p></dd></dl>


<a class="anchor" id="XREFfile_005fin_005floadpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-file_005fin_005floadpath"><span><code class="def-type"><var class="var">fname</var> =</code> <strong class="def-name">file_in_loadpath</strong> <code class="def-code-arguments">(<var class="var">file</var>)</code><a class="copiable-link" href="#index-file_005fin_005floadpath"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-file_005fin_005floadpath-1"><span><code class="def-type"><var class="var">fname</var> =</code> <strong class="def-name">file_in_loadpath</strong> <code class="def-code-arguments">(<var class="var">file</var>, &quot;all&quot;)</code><a class="copiable-link" href="#index-file_005fin_005floadpath-1"> &para;</a></span></dt>
<dd><p>Return the absolute name of <var class="var">file</var> if it can be found in the list of
directories specified by <code class="code">path</code>.
</p>
<p>If no file is found, return an empty character string.
</p>
<p>When <var class="var">file</var> is already an absolute name, the name is checked against the
file system instead of Octave&rsquo;s loadpath.  In this case, if <var class="var">file</var> exists
it will be returned in <var class="var">fname</var>, otherwise an empty string is returned.
</p>
<p>If the first argument is a cell array of strings, search each directory of
the loadpath for element of the cell array and return the first that
matches.
</p>
<p>If the second optional argument <code class="code">&quot;all&quot;</code> is supplied, return a cell
array containing the list of all files that have the same name in the path.
If no files are found, return an empty cell array.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Filesystem-Utilities.html#XREFfile_005fin_005fpath">file_in_path</a>, <a class="ref" href="#XREFdir_005fin_005floadpath">dir_in_loadpath</a>, <a class="ref" href="#XREFpath">path</a>.
</p></dd></dl>


<a class="anchor" id="XREFrestoredefaultpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-restoredefaultpath"><span><code class="def-type"><var class="var">pathstr</var> =</code> <strong class="def-name">restoredefaultpath</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-restoredefaultpath"> &para;</a></span></dt>
<dd><p>Restore Octave&rsquo;s path to its initial state at startup.
</p>
<p>The re-initialized path is returned as an output.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFaddpath">addpath</a>, <a class="ref" href="#XREFrmpath">rmpath</a>, <a class="ref" href="#XREFgenpath">genpath</a>, <a class="ref" href="#XREFpathdef">pathdef</a>, <a class="ref" href="#XREFsavepath">savepath</a>, <a class="ref" href="#XREFpathsep">pathsep</a>.
</p></dd></dl>


<a class="anchor" id="XREFcommand_005fline_005fpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-command_005fline_005fpath"><span><code class="def-type"><var class="var">pathstr</var> =</code> <strong class="def-name">command_line_path</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-command_005fline_005fpath"> &para;</a></span></dt>
<dd><p>Return the path argument given to Octave at the command line when the
interpreter was started (<code class="env">--path&nbsp;<var class="var">arg</var></code><!-- /@w -->).
</p>

<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFaddpath">addpath</a>, <a class="ref" href="#XREFrmpath">rmpath</a>, <a class="ref" href="#XREFgenpath">genpath</a>, <a class="ref" href="#XREFpathdef">pathdef</a>, <a class="ref" href="#XREFsavepath">savepath</a>, <a class="ref" href="#XREFpathsep">pathsep</a>.
</p></dd></dl>


<a class="anchor" id="XREFdir_005fin_005floadpath"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-dir_005fin_005floadpath"><span><code class="def-type"><var class="var">dirname</var> =</code> <strong class="def-name">dir_in_loadpath</strong> <code class="def-code-arguments">(<var class="var">dir</var>)</code><a class="copiable-link" href="#index-dir_005fin_005floadpath"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-dir_005fin_005floadpath-1"><span><code class="def-type"><var class="var">dirname</var> =</code> <strong class="def-name">dir_in_loadpath</strong> <code class="def-code-arguments">(<var class="var">dir</var>, &quot;all&quot;)</code><a class="copiable-link" href="#index-dir_005fin_005floadpath-1"> &para;</a></span></dt>
<dd><p>Return the absolute name of the loadpath element matching <var class="var">dir</var> if it can
be found in the list of directories specified by <code class="code">path</code>.
</p>
<p>If no match is found, return an empty character string.
</p>
<p>The match is performed at the end of each path element.  For example, if
<var class="var">dir</var> is <code class="code">&quot;foo/bar&quot;</code>, it matches the path element
<code class="code">&quot;/some/dir/foo/bar&quot;</code>, but not
<code class="code">&quot;/some/dir/foo/bar/baz&quot;</code>
<code class="code">&quot;/some/dir/allfoo/bar&quot;</code>.  When <var class="var">dir</var> is an absolute name,
rather than just a path fragment, it is matched against the file system
instead of Octave&rsquo;s loadpath.  In this case, if <var class="var">dir</var> exists it will be
returned in <var class="var">dirname</var>, otherwise an empty string is returned.
</p>
<p>If the optional second argument is supplied, return a cell array containing
all name matches rather than just the first.
</p>
<p><strong class="strong">See also:</strong> <a class="ref" href="Filesystem-Utilities.html#XREFfile_005fin_005fpath">file_in_path</a>, <a class="ref" href="#XREFfile_005fin_005floadpath">file_in_loadpath</a>, <a class="ref" href="#XREFpath">path</a>.
</p></dd></dl>


<a class="anchor" id="XREFmfile_005fencoding"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-mfile_005fencoding"><span><code class="def-type"><var class="var">current_encoding</var> =</code> <strong class="def-name">mfile_encoding</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href="#index-mfile_005fencoding"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-mfile_005fencoding-1"><span><strong class="def-name">mfile_encoding</strong> <code class="def-code-arguments">(<var class="var">new_encoding</var>)</code><a class="copiable-link" href="#index-mfile_005fencoding-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-mfile_005fencoding-2"><span><code class="def-type"><var class="var">old_encoding</var> =</code> <strong class="def-name">mfile_encoding</strong> <code class="def-code-arguments">(<var class="var">new_encoding</var>)</code><a class="copiable-link" href="#index-mfile_005fencoding-2"> &para;</a></span></dt>
<dd><p>Query or set the encoding that is used for reading m-files.
</p>
<p>The input and output are strings naming an encoding, e.g.,
<code class="code">&quot;utf-8&quot;</code>.
</p>
<p>This encoding is used by Octave&rsquo;s parser when reading m-files unless a
different encoding was set for a specific directory containing m-files using
the function <code class="code">dir_encoding</code> or in a file <samp class="file">.oct-config</samp> in that
directory.
</p>
<p>The special value <code class="code">&quot;system&quot;</code> selects the encoding that matches the system
locale.
</p>
<p>If the m-file encoding is changed after the m-files have already been parsed,
the files have to be parsed again for that change to take effect.  That can be
triggered with the command <code class="code">clear all</code>.
</p>
<p>Additionally, this encoding is used to load and save files with the built-in
editor in Octave&rsquo;s GUI.
</p>

<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFdir_005fencoding">dir_encoding</a>.
</p></dd></dl>


<a class="anchor" id="XREFdir_005fencoding"></a><span style="display:block; margin-top:-4.5ex;">&nbsp;</span>


<dl class="first-deftypefn">
<dt class="deftypefn" id="index-dir_005fencoding"><span><code class="def-type"><var class="var">current_encoding</var> =</code> <strong class="def-name">dir_encoding</strong> <code class="def-code-arguments">(<var class="var">dir</var>)</code><a class="copiable-link" href="#index-dir_005fencoding"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-dir_005fencoding-1"><span><strong class="def-name">dir_encoding</strong> <code class="def-code-arguments">(<var class="var">dir</var>, <var class="var">new_encoding</var>)</code><a class="copiable-link" href="#index-dir_005fencoding-1"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-dir_005fencoding-2"><span><strong class="def-name">dir_encoding</strong> <code class="def-code-arguments">(<var class="var">dir</var>, &quot;delete&quot;)</code><a class="copiable-link" href="#index-dir_005fencoding-2"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-dir_005fencoding-3"><span><code class="def-type"><var class="var">old_encoding</var> =</code> <strong class="def-name">dir_encoding</strong> <code class="def-code-arguments">(<var class="var">dir</var>, <var class="var">new_encoding</var>)</code><a class="copiable-link" href="#index-dir_005fencoding-3"> &para;</a></span></dt>
<dd><p>Query or set the <var class="var">encoding</var> that is used for reading m-files in <var class="var">dir</var>.
</p>
<p>The per-directory encoding overrides the (globally set) m-file encoding,
see <a class="pxref" href="#XREFmfile_005fencoding"><code class="code">mfile_encoding</code></a>.
</p>
<p>The string <var class="var">DIR</var> must match how the directory would appear in the load
path.
</p>
<p>The <var class="var">new_encoding</var> input must be a valid encoding identifier or
<code class="code">&quot;delete&quot;</code>.  In the latter case, any per-directory encoding is removed
and the (globally set) m-file encoding will be used for the given <var class="var">dir</var>.
</p>
<p>The currently or previously used encoding is returned only if an output
argument is requested.
</p>
<p>The directory encoding is automatically read from the file <samp class="file">.oct-config</samp>
when a new path is added to the load path (for example with <code class="code">addpath</code>).
To set the encoding for all files in the same folder, that file must contain
a line starting with <code class="code">&quot;encoding=&quot;</code> followed by the encoding identifier.
</p>
<p>For example to set the file encoding for all files in the same folder to
ISO 8859-1 (Latin-1), create a file <samp class="file">.oct-config</samp> with the following
content:
</p>
<div class="example">
<pre class="example-preformatted">encoding=iso8859-1
</pre></div>

<p>If the file encoding is changed after the files have already been parsed, the
files have to be parsed again for that change to take effect.  That can be done
with the command <code class="code">clear all</code>.
</p>

<p><strong class="strong">See also:</strong> <a class="ref" href="#XREFaddpath">addpath</a>, <a class="ref" href="#XREFpath">path</a>, <a class="ref" href="#XREFmfile_005fencoding">mfile_encoding</a>.
</p></dd></dl>


</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Subfunctions.html">Subfunctions</a>, Up: <a href="Function-Files.html">Function Files</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>