661
edits
Carandraug (talk | contribs) (preferences -- change default figure size) |
Carandraug (talk | contribs) |
||
Line 12: | Line 12: | ||
This is a list of tiny helper functions (the equivalent of e.g., shell aliases), the kind one would have on its {{Path|.octaverc}} file. | This is a list of tiny helper functions (the equivalent of e.g., shell aliases), the kind one would have on its {{Path|.octaverc}} file. | ||
=== Reload 'octave.rc' after 'clear' === | |||
When using {{Codeline|clear}}, one may accidentally remove functions (alias) or other variables set on the {{Path|octave.rc}} file. This can fixed by shadowing the {{Codeline|clear}} function with the following: | |||
{{Code|reload octave.rc after clear|<pre> | |||
function clear (varargin) | |||
args = sprintf (', "%s"', varargin{:}); | |||
evalin ("caller", ['builtin ("clear"' args ')']); | |||
source ("~/.octaverc"); | |||
endfunction</pre>}} | |||
The problem with this approach is if there's path manipulation on the {{Path|octave.rc}} file, such as {{Codeline|addpath}}. A workaround is needed for each case since it is not possible to obtain a reliable list of what's in Octave load path. But basically should be to undo what the file does, before {{Codeline|source ("~/.octaverc")}}. | |||
If there's a {{Codeline|pkg unload all}} on it, this would also unload all packages. The following adjustment will keep the packages loaded | |||
{{Code|reload octave.rc after clear but keep packages loaded|<pre> | |||
function clear (varargin) | |||
args = sprintf (', "%s"', varargin{:}); | |||
evalin ("caller", ['builtin ("clear"' args ')']); | |||
pkglist = pkg ("list"); | |||
loadedpkg = cell (0); | |||
for ii = 1:numel (pkglist) | |||
if (pkglist{ii}.loaded) | |||
loadedpkg{end+1} = pkglist{ii}.name; | |||
endif | |||
endfor | |||
source ("~/.octaverc"); | |||
if (numel (loadedpkg) != 0) | |||
pkg ("load", loadedpkg{:}); | |||
endif | |||
endfunction</pre>}} | |||
=== replace help with man === | === replace help with man === |