Mercurial > hg > octave-lyh
annotate scripts/prefs/rmpref.m @ 17420:95bfa04ab514
Fix bug in colorbar demo #24.
set() is broken from deep within listener hierarchy. Workaround it.
* scripts/plot/colorbar.m(update_colorbar_clim): Set axis limits in listener
and then jiggle the axis position to force a redraw.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 11 Sep 2013 16:05:40 -0700 |
parents | ac8520c03fc9 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13943
diff
changeset
|
1 ## Copyright (C) 2012 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 -*- |
14540
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
20 ## @deftypefn {Function File} {} rmpref (@var{group}) |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
21 ## @deftypefnx {Function File} {} rmpref (@var{group}, @var{pref}) |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 ## Remove the named preference @var{pref} from the preference group |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 ## @var{group}. |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 ## |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 ## The named preference group must be a character string. |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 ## |
14540
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
27 ## The preference @var{pref} may be a character string or cell array |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
28 ## of strings. |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 ## |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 ## If @var{pref} is not specified, remove the preference group |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 ## @var{group}. |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 ## |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 ## 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
|
34 ## @seealso{addpref, ispref, setpref, getpref} |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 ## @end deftypefn |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 ## Author: jwe |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 function retval = rmpref (group, pref) |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
14540
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
41 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
|
42 print_usage (); |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 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
|
47 endif |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 if (nargin == 1) |
14540
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
50 if (ispref (group)) |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
51 prefs = loadprefs (); |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
52 prefs = rmfield (prefs, group); |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 saveprefs (prefs); |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 else |
14540
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 error ("rmpref: group <%s> does not exist", group); |
13261
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 endif |
9134ca9d4ec8
new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 else |
14540
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 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
|
59 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
|
60 prefs = loadprefs (); |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 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
|
62 saveprefs (prefs); |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
63 else |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 if (! ispref (group)) |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 error ("rmpref: group <%s> does not exist", group); |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
66 else |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
67 idx = find (! valid, 1); |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 error ("rmpref: pref <%s> does not exist", (cellstr (pref)){idx} ); |
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 |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 ## Testing these functions will require some care to avoid wiping out |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
77 ## existing (or creating unwanted) preferences for the user running the |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
78 ## tests. |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
79 |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
80 ## 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
|
81 %!error rmpref () |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
82 %!error rmpref (1,2,3) |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 %!error rmpref ({"__group1__"}) |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
84 %!error rmpref ("__group1__", 1) |
ac8520c03fc9
rmpref.m: Fix function to delete, not just return, preference. (Bug #35712)
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
85 |