annotate scripts/prefs/rmpref.m @ 23219:3ac9f9ecfae5 stable

maint: Update copyright dates.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Feb 2017 12:39:29 -0500
parents e9a0469dedd9
children 092078913d54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
1 ## Copyright (C) 2012-2017 John W. Eaton
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## your option) any later version.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20834
diff changeset
20 ## @deftypefn {} {} rmpref ("@var{group}", "@var{pref}")
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20834
diff changeset
21 ## @deftypefnx {} {} rmpref ("@var{group}", @{"@var{pref1}", "@var{pref2}", @dots{}@})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20834
diff changeset
22 ## @deftypefnx {} {} rmpref ("@var{group}")
21546
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20852
diff changeset
23 ## Remove the named preference @var{pref} from the preference group
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20852
diff changeset
24 ## @var{group}.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 ##
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
26 ## The named preference group must be a string.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 ##
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
28 ## The preference @var{pref} may be a string or cell array of strings.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 ##
20160
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
30 ## If @var{pref} is not specified, remove the preference group @var{group}.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 ## It is an error to remove a nonexistent preference or group.
13943
5820f8ce683e doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
33 ## @seealso{addpref, ispref, setpref, getpref}
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 ## @end deftypefn
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 ## Author: jwe
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
38 function rmpref (group, pref)
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
40 if (nargin < 1 || nargin > 2)
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
41 print_usage ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
42 elseif (! ischar (group))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
43 error ("rmpref: GROUP must be a string");
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
44 elseif (nargin == 2 && ! (ischar (pref) || iscellstr (pref)))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
45 error ("rmpref: PREF must be a string or cell array of strings");
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
46 endif
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 if (nargin == 1)
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
49 if (! ispref (group))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
50 error ("rmpref: group %s does not exist", group);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 endif
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
52 prefs = loadprefs ();
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
53 prefs = rmfield (prefs, group);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
54 saveprefs (prefs);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 else
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56 valid = ispref (group, pref);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 if (all (valid))
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
58 prefs = loadprefs ();
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59 prefs.(group) = rmfield (prefs.(group), pref);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
60 saveprefs (prefs);
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 else
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62 if (! ispref (group))
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
63 error ("rmpref: group %s does not exist", group);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
64 elseif (ischar (pref))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
65 error ("rmpref: preference %s does not exist", pref);
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
66 else
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
67 idx = find (! valid, 1);
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
68 error ("rmpref: preference %s does not exist", pref{idx});
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 endif
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 endif
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 endif
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 endfunction
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
75
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
76 %!test
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
77 %! HOME = getenv ("HOME");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
78 %! unwind_protect
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
79 %! setenv ("HOME", P_tmpdir ());
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
80 %! addpref ("group1", "pref1", [1 2 3]);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
81 %! addpref ("group2", {"prefA", "prefB", "prefC"}, {"strA", "strB", "strC"});
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
82 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
83 %! assert (ispref ("group1"));
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
84 %! rmpref ("group1");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
85 %! assert (! ispref ("group1"));
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
86 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
87 %! assert (ispref ("group2", "prefB"));
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
88 %! rmpref ("group2", "prefB");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
89 %! assert (! ispref ("group2", "prefB"));
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
90 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
91 %! fail ('rmpref ("group3")', ...
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
92 %! "group group3 does not exist");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
93 %! fail ('rmpref ("group3", "prefA")', ...
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
94 %! "group group3 does not exist");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
95 %! fail ('rmpref ("group2", "prefB")',
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
96 %! "preference prefB does not exist");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
97 %! fail ('rmpref ("group2", {"prefA", "prefB"})',
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
98 %! "preference prefB does not exist");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
99 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
100 %! unwind_protect_cleanup
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
101 %! unlink (fullfile (P_tmpdir (), ".octave_prefs"));
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
102 %! if (isempty (HOME))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
103 %! unsetenv ("HOME");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
104 %! else
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
105 %! setenv ("HOME", HOME);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
106 %! endif
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
107 %! end_unwind_protect
14540
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
108
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
109 ## Test input validation
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
110 %!error rmpref ()
ac8520c03fc9 rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
111 %!error rmpref (1,2,3)
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
112 %!error <GROUP must be a string> rmpref (1)
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20160
diff changeset
113 %!error <PREF must be a string> rmpref ("group1", 1)