annotate scripts/miscellaneous/edit.m @ 8746:5dd06f19e9be

handle commands in the lexer
author John W. Eaton <jwe@octave.org>
date Sun, 15 Feb 2009 23:49:15 -0500
parents bc982528de11
children bb38a86efa1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2001, 2007 Paul Kienzle
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
2 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
4 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
8 ## your option) any later version.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
9 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
14 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
18
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Command} edit @var{name}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Command} edit @var{field} @var{value}
7650
eb7bdde776f2 Texinfo fixes
John W. Eaton <jwe@octave.org>
parents: 7540
diff changeset
22 ## @deftypefnx {Command} {@var{value} =} edit get @var{field}
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
23 ## Edit the named function, or change editor settings.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
24 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
25 ## If @code{edit} is called with the name of a file or function as
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
26 ## its argument it will be opened in a text editor.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
27 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
28 ## @itemize @bullet
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
29 ## @item
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
30 ## If the function @var{name} is available in a file on your path and
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
31 ## that file is modifiable, then it will be edited in place. If it
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
32 ## is a system function, then it will first be copied to the directory
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
33 ## @code{HOME} (see further down) and then edited.
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
34 ## If no file is found, then the m-file
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
35 ## variant, ending with ".m", will be considered. If still no file
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
36 ## is found, then variants with a leading "@@" and then with both a
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
37 ## leading "@@" and trailing ".m" will be considered.
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
38 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
39 ## @item
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
40 ## If @var{name} is the name of a function defined in the interpreter but
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
41 ## not in an m-file, then an m-file will be created in @code{HOME}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
42 ## to contain that function along with its current definition.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
43 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
44 ## @item
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
45 ## If @code{name.cc} is specified, then it will search for @code{name.cc}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
46 ## in the path and try to modify it, otherwise it will create a new
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
47 ## @file{.cc} file in @code{HOME}. If @var{name} happens to be an
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
48 ## m-file or interpreter defined function, then the text of that
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
49 ## function will be inserted into the .cc file as a comment.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
50 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
51 ## @item
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
52 ## If @var{name.ext} is on your path then it will be editted, otherwise
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
53 ## the editor will be started with @file{HOME/name.ext} as the
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
54 ## filename. If @file{name.ext} is not modifiable, it will be copied to
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
55 ## @code{HOME} before editing.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
56 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
57 ## @strong{WARNING!} You may need to clear name before the new definition
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
58 ## is available. If you are editing a .cc file, you will need
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
59 ## to mkoctfile @file{name.cc} before the definition will be available.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
60 ## @end itemize
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
61 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
62 ## If @code{edit} is called with @var{field} and @var{value} variables,
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
63 ## the value of the control field @var{field} will be @var{value}.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
64 ## If an output argument is requested and the first argument is @code{get}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
65 ## then @code{edit} will return the value of the control field @var{field}.
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
66 ## If the control field does not exist, edit will return a structure
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
67 ## containing all fields and values. Thus, @code{edit get all} returns
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
68 ## a complete control structure.
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
69 ## The following control fields are used:
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
70 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
71 ## @table @samp
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
72 ## @item editor
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
73 ## This is the editor to use to modify the functions. By default it uses
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
74 ## Octave's @code{EDITOR} built-in function, which comes from
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
75 ## @code{getenv("EDITOR")} and defaults to @code{emacs}. Use @code{%s}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
76 ## In place of the function name. For example,
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
77 ## @table @samp
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
78 ## @item [EDITOR, " %s"]
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
79 ## Use the editor which Octave uses for @code{bug_report}.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
80 ## @item "xedit %s &"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
81 ## pop up simple X11 editor in a separate window
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
82 ## @item "gnudoit -q \"(find-file \\\"%s\\\")\""
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
83 ## Send it to current Emacs; must have @code{(gnuserv-start)} in @file{.emacs}.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
84 ## @end table
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
85 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
86 ## On cygwin, you will need to convert the cygwin path to a windows
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
87 ## path if you are using a native Windows editor. For example
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
88 ## @example
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
89 ## '"C:/Program Files/Good Editor/Editor.exe" "$(cygpath -wa %s)"'
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
90 ## @end example
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
91 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
92 ## @item home
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
93 ## This is the location of user local m-files. Be be sure it is in your
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
94 ## path. The default is @file{~/octave}.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
95 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
96 ## @item author
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
97 ## This is the name to put after the "## Author:" field of new functions.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
98 ## By default it guesses from the @code{gecos} field of password database.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
99 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
100 ## @item email
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
101 ## This is the e-mail address to list after the name in the author field.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
102 ## By default it guesses @code{<$LOGNAME@@$HOSTNAME>}, and if @code{$HOSTNAME}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
103 ## is not defined it uses @code{uname -n}. You probably want to override this.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
104 ## Be sure to use @code{<user@@host>} as your format.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
105 ##
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
106 ## @item license
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
107 ## @table @samp
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
108 ## @item gpl
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
109 ## GNU General Public License (default).
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
110 ## @item bsd
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
111 ## BSD-style license without advertising clause.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
112 ## @item pd
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
113 ## Public domain.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
114 ## @item "text"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
115 ## Your own default copyright and license.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
116 ## @end table
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
117 ##
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
118 ## Unless you specify @samp{pd}, edit will prepend the copyright statement
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
119 ## with "Copyright (C) yyyy Function Author".
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
120 ##
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
121 ## @item mode
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
122 ## This value determines whether the editor should be started in async mode
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
123 ## or sync mode. Set it to "async" to start the editor in async mode. The
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
124 ## default is "sync" (see also "system").
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
125 ##
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
126 ## @item editinplace
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
127 ## Determines whether files should be edited in place, without regard to
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
128 ## whether they are modifiable or not. The default is @code{false}.
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
129 ## @end table
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
130 ## @end deftypefn
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
131
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
132 ## Author: Paul Kienzle <pkienzle@users.sf.net>
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
133
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
134 ## Original version by Paul Kienzle distributed as free software in the
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
135 ## public domain.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
136
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
137 function ret = edit (file, state)
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
138
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
139 ## Pick up globals or default them.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
140
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
141 persistent FUNCTION = struct ("EDITOR", cstrcat (EDITOR (), " %s"),
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
142 "HOME", fullfile (default_home, "octave"),
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
143 "AUTHOR", default_user(1),
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
144 "EMAIL", [],
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
145 "LICENSE", "GPL",
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
146 "MODE", "sync",
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
147 "EDITINPLACE", false);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
148
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
149 ## Make sure the state variables survive "clear functions".
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7650
diff changeset
150 mlock;
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
151
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
152 if (nargin == 2)
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
153 switch (toupper (file))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
154 case "EDITOR"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
155 FUNCTION.EDITOR = state;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
156 case "HOME"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
157 if (! isempty (state) && state(1) == "~")
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
158 state = [ default_home, state(2:end) ];
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
159 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
160 FUNCTION.HOME = state;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
161 case "AUTHOR"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
162 FUNCTION.AUTHOR = state;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
163 case "EMAIL"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
164 FUNCTION.EMAIL = state;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
165 case "LICENSE"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
166 FUNCTION.LICENSE = state;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
167 case "MODE"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
168 if (strcmp (state, "sync") || strcmp (state, "async"))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
169 FUNCTION.MODE = state;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
170 else
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
171 error('expected "edit MODE sync|async"');
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
172 endif
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
173 case "EDITINPLACE"
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
174 if (ischar (state))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
175 if (strcmpi (state, "true"))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
176 state = true;
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
177 elseif (strcmpi (state, "false"))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
178 state = false;
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
179 else
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
180 state = eval (state);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
181 endif
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
182 endif
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
183 FUNCTION.EDITINPLACE = state;
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
184 case "GET"
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
185 if (isfield (FUNCTION, toupper(state)))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
186 ret = FUNCTION.(toupper (state));
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
187 else
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
188 ret = FUNCTION;
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
189 endif
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
190 otherwise
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
191 error ("expected \"edit EDITOR|HOME|AUTHOR|EMAIL|LICENSE|MODE val\"");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
192 endswitch
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
193 return
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
194 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
195
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
196 ## Start the editor without a file if no file is given.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
197 if (nargin < 1)
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
198 if (exist (FUNCTION.HOME, "dir") == 7 && (isunix () || ! ispc ()))
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
199 system (cstrcat ("cd \"", FUNCTION.HOME, "\" ; ",
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
200 sprintf (FUNCTION.EDITOR, "")),
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
201 [], FUNCTION.MODE);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
202 else
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
203 system (sprintf (FUNCTION.EDITOR,""), [], FUNCTION.MODE);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
204 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
205 return;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
206 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
207
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
208 ## Check whether the user is trying to edit a builtin of compiled function.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
209 switch (exist (file))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
210 case {3, 5}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
211 error ("unable to edit a built-in or compiled function");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
212 endswitch
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
213
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
214 ## Checks for whether the file is
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
215 ## absolute or relative should be handled inside file_in_loadpath.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
216 ## That way, it will be possible to look up files correctly given
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
217 ## partial path information. For example, you should be able to
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
218 ## edit a particular overloaded function by doing any one of
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
219 ##
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
220 ## edit classname/foo
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
221 ## edit classname/foo.m
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
222 ## edit @classname/foo
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
223 ## edit @classname/foo.m
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
224 ##
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
225 ## This functionality is needed for other functions as well (at least
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
226 ## help and type; there may be more). So the place to fix that is in
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
227 ## file_in_loadpath, possibly with some help from the load_path class.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
228
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
229 ## The code below includes a portion that serves as a place-holder for
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
230 ## the changes suggested above.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
231
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
232 ## Create list of explicit and implicit file names.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
233 filelist = {file};
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
234 ## If file has no extension, add file.m and file.cc to the list.
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
235 idx = rindex (file, ".");
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
236 if (idx == 0)
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
237 ## Create the list of files to look for
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
238 filelist = {file};
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
239 if (isempty (regexp (file, "\\.m$")))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
240 ## No ".m" at the end of the file, add to the list.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
241 filelist{end+1} = cat (2, file, ".m");
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
242 endif
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
243 if (isempty (regexp (file, "\\.cc$")))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
244 ## No ".cc" at the end of the file, add to the list.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
245 filelist{end+1} = cat (2, file, ".cc");
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
246 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
247 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
248
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
249 ## If the file includes a path, it may be an overloaded function.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
250 if (! strcmp (file, "@") && index (file, filesep))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
251 ## No "@" at the beginning of the file, add to the list.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
252 numfiles = numel(filelist);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
253 for n = 1:numfiles
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
254 filelist{n+numfiles} = cat (2, "@", filelist{n});
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
255 endfor
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
256 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
257
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
258 ## Search the entire path for the 1st instance of a file in the list.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
259 fileandpath = "";
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
260 for n = 1:numel(filelist)
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
261 filetoedit = file_in_path (path, filelist{n});
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
262 if (! isempty (filetoedit))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
263 ## The path is explicitly included.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
264 fileandpath = filetoedit;
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
265 break;
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
266 endif
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
267 endfor
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
268
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
269 if (! isempty (fileandpath))
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
270 ## If the file exists, then edit it.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
271 if (FUNCTION.EDITINPLACE)
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
272 ## Edit in place even if it is protected.
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
273 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")),
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
274 [], FUNCTION.MODE);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
275 return;
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
276 else
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
277 ## If the file is modifiable in place then edit it, otherwise make
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
278 ## a copy in HOME and then edit it.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
279 fid = fopen (fileandpath, "r+t");
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
280 if (fid < 0)
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
281 from = fileandpath;
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
282 fileandpath = cstrcat (FUNCTION.HOME, from (rindex (from, filesep):end));
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
283 [status, msg] = copyfile (from, fileandpath, 1);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
284 if (status == 0)
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
285 error (msg);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
286 endif
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
287 else
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
288 fclose (fid);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
289 endif
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
290 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")),
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
291 [], FUNCTION.MODE);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
292 return;
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
293 endif
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
294 endif
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
295
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
296 ## If editing a new file that is neither a m-file or an oct-file,
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
297 ## just edit it.
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
298 fileandpath = file;
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
299 idx = rindex (file, ".");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
300 name = file(1:idx-1);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
301 ext = file(idx+1:end);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
302 switch (ext)
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
303 case {"cc", "m"}
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
304 0;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
305 otherwise
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
306 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")),
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
307 [], FUNCTION.MODE);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
308 return;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
309 endswitch
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
310
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
311 ## The file doesn't exist in path so create it, put in the function
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
312 ## template and edit it.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
313
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
314 ## Guess the email name if it was not given.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
315 if (isempty (FUNCTION.EMAIL))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
316 host = getenv("HOSTNAME");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
317 if (isempty (host) && ispc ())
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
318 host = getenv ("COMPUTERNAME");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
319 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
320 if (isempty (host))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
321 [status, host] = system ("uname -n");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
322 ## trim newline from end of hostname
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
323 if (! isempty (host))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
324 host = host(1:end-1);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
325 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
326 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
327 if (isempty (host))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
328 FUNCTION.EMAIL = " ";
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
329 else
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
330 FUNCTION.EMAIL = cstrcat ("<", default_user(0), "@", host, ">");
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
331 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
332 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
333
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
334 ## Fill in the revision string.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
335 now = localtime (time);
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
336 revs = cstrcat ("Created: ", strftime ("%Y-%m-%d", now));
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
337
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
338 ## Fill in the copyright string.
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
339 copyright = cstrcat (strftime ("Copyright (C) %Y ", now), FUNCTION.AUTHOR);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
340
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
341 ## Fill in the author tag field.
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
342 author = cstrcat ("Author: ", FUNCTION.AUTHOR, " ", FUNCTION.EMAIL);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
343
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
344 ## Fill in the header.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
345 uclicense = toupper (FUNCTION.LICENSE);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
346 switch (uclicense)
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
347 case "GPL"
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
348 head = cstrcat (copyright, "\n\n", "\
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
349 This program is free software; you can redistribute it and/or modify\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
350 it under the terms of the GNU General Public License as published by\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
351 the Free Software Foundation; either version 2 of the License, or\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
352 (at your option) any later version.\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
353 \n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
354 This program is distributed in the hope that it will be useful,\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
355 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
356 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
357 GNU General Public License for more details.\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
358 \n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
359 You should have received a copy of the GNU General Public License\n\
7444
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7434
diff changeset
360 along with Octave; see the file COPYING. If not, see\n\
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7434
diff changeset
361 <http://www.gnu.org/licenses/>.\
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
362 ");
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
363 tail = cstrcat (author, "\n", revs);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
364
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
365 case "BSD"
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
366 head = cstrcat (copyright, "\n\n", "\
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
367 This program is free software; redistribution and use in source and\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
368 binary forms, with or without modification, are permitted provided that\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
369 the following conditions are met:\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
370 \n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
371 1.Redistributions of source code must retain the above copyright\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
372 notice, this list of conditions and the following disclaimer.\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
373 2.Redistributions in binary form must reproduce the above copyright\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
374 notice, this list of conditions and the following disclaimer in the\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
375 documentation and/or other materials provided with the distribution.\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
376 \n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
377 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
378 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
379 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
380 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
381 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
382 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
383 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
384 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
385 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
386 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
387 SUCH DAMAGE.\
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
388 ");
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
389 tail = cstrcat (author, "\n", revs);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
390
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
391 case "PD"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
392 head = "";
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
393 tail = cstrcat (author, "\n", revs, "\n\n",
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
394 "This program is granted to the public domain.");
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
395
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
396 otherwise
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
397 head = "";
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
398 tail = cstrcat (copyright, "\n\n", FUNCTION.LICENSE, "\n",
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
399 author, "\n", revs);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
400 endswitch
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
401
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
402 ## Generate the function template.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
403 exists = exist (name);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
404 switch (ext)
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
405 case {"cc", "C", "cpp"}
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
406 if (isempty (head))
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
407 comment = cstrcat ("/*\n", tail, "\n\n*/\n\n");
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
408 else
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
409 comment = cstrcat ("/*\n", head, "\n\n", tail, "\n\n*/\n\n");
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
410 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
411 ## If we are shadowing an m-file, paste the code for the m-file.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
412 if (any (exists == [2, 103]))
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
413 code = cstrcat ("\\ ", strrep (type (name), "\n", "\n// "));
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
414 else
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
415 code = " ";
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
416 endif
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
417 body = cstrcat ("#include <octave/oct.h>\n\n",
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
418 "DEFUN_DLD(", name, ",args,nargout,\"\\\n",
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
419 name, "\\n\\\n\")\n{\n",
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
420 " octave_value_list retval;\n",
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
421 " int nargin = args.length();\n\n",
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
422 code, "\n return retval;\n}\n");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
423
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
424 text = cstrcat (comment, body);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
425 case "m"
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
426 ## If we are editing a function defined on the fly, paste the
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
427 ## code.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
428 if (any (exists == [2, 103]))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
429 body = type (name);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
430 else
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
431 body = cstrcat ("function [ ret ] = ", name, " ()\n\nendfunction\n");
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
432 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
433 if (isempty (head))
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
434 comment = cstrcat ("## ", name, "\n\n",
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
435 "## ", strrep (tail, "\n", "\n## "), "\n\n");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
436 else
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
437 comment = cstrcat ("## ", strrep(head,"\n","\n## "), "\n\n", ...
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
438 "## ", name, "\n\n", ...
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
439 "## ", strrep (tail, "\n", "\n## "), "\n\n");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
440 endif
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
441 text = cstrcat (comment, body);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
442 endswitch
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
443
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
444 ## Write the initial file (if there is anything to write)
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
445 fid = fopen (fileandpath, "wt");
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
446 if (fid < 0)
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
447 error ("edit: could not create %s", fileandpath);
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
448 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
449 fputs (fid, text);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
450 fclose (fid);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
451
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
452 ## Finally we are ready to edit it!
7540
3422f39573b1 strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents: 7502
diff changeset
453 system (sprintf (FUNCTION.EDITOR, cstrcat ("\"", fileandpath, "\"")),
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
454 [], FUNCTION.MODE);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
455
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
456 endfunction
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
457
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
458 function ret = default_home ()
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
459
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
460 ret = getenv ("HOME");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
461 if (isempty (ret))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
462 ret = glob ("~");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
463 if (! isempty (ret))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
464 ret = ret{1};
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
465 else
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
466 ret = "";
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
467 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
468 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
469
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
470 endfunction
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
471
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
472 ## Return the name associated with the current user ID.
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
473 ##
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
474 ## If LONG_FORM is 1, return the full name. This will be the
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
475 ## default author. Otherwise return the login name.
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
476 ## login@host will be the default email address.
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
477
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
478 function ret = default_user (long_form)
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
479
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
480 ent = getpwuid (getuid);
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
481 if (! isstruct (ent))
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
482 ret = getenv ("USER");
7330
55f35e469c43 [project @ 2007-12-20 17:53:36 by jwe]
jwe
parents: 7325
diff changeset
483 if (isempty (ret))
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
484 ret = getenv ("USERNAME");
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
485 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
486 elseif (long_form)
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
487 ret = ent.gecos;
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
488 pos = strfind (ret, ",");
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
489 if (! isempty (pos))
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
490 ret = ret(1:pos-1);
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7340
diff changeset
491 endif
7325
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
492 else
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
493 ret = ent.name;
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
494 endif
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
495
67aef14de9c2 [project @ 2007-12-19 20:21:11 by jwe]
jwe
parents:
diff changeset
496 endfunction
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
497
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
498 %!test
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
499 %! s.editor = edit ("get", "editor");
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
500 %! s.home = edit ("get", "home");
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
501 %! s.author = edit ("get", "author");
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
502 %! s.email = edit ("get", "email");
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
503 %! s.license = edit ("get", "license");
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
504 %! s.editinplace = edit ("get", "editinplace");
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
505 %! s.mode = edit ("get", "mode");
7502
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
506 %! edit editor none
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
507 %! edit home none
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
508 %! edit author none
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
509 %! edit email none
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
510 %! edit license none
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
511 %! edit ("editinplace", !s.editinplace)
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
512 %! if (s.mode(1) == "a")
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
513 %! edit mode sync
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
514 %! else
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
515 %! edit mode async
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
516 %! endif
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
517 %! edit ("editor", s.editor);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
518 %! edit ("home", s.home);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
519 %! edit ("author", s.author);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
520 %! edit ("email", s.email);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
521 %! edit ("license", s.license);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
522 %! edit ("editinplace", s.editinplace);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
523 %! edit ("mode", s.mode);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
524 %! assert (edit ("get", "editor"), s.editor);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
525 %! assert (edit ("get", "home"), s.home);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
526 %! assert (edit ("get", "author"), s.author);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
527 %! assert (edit ("get", "email"), s.email);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
528 %! assert (edit ("get", "license"), s.license);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
529 %! assert (edit ("get", "editinplace"), s.editinplace);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
530 %! assert (edit ("get", "mode"), s.mode);
2ce6b4258e96 Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents: 7444
diff changeset
531