Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/edit.m @ 16447:e3b33a7530bc
improve encapsulation of history window object
* history-dockwidget.h, history-dockwidget.cc
(history_dock_widget::history_dock_widget): Set status tip here.
Connect history_dock_widget::information signal to
main_window::report_status_message.
Connect history_dock_widget::command_double_clicked signal to
main_window::handle_command_double_clicked.
(history_dock_widget::connect_visibility_changed,
history_dock_widget::focus, history_dock_widget::handle_visibility):
New functions.
* main-window.h, main-window.cc (main_window::history_window): Rename
from _history_dock_widget. Don't use a pointer. Change all uses.
(main_window::main_window): Initialize it here.
(main_window::~main_window): Don't delete _history_dock_widget.
(main_window::focus_history_window_signal): New signal.
(main_window::focus_history_window): Rename from
main_window::focus_command_history. Emit focus_history_window_signal
instead of performing actions here.
(main_window::handle_command_history_visible): Delete.
(main_window::connect_visibility_changed): Call
history_window.connect_visibility_changed instead of performing
actions here.
(main_window::construct): Don't create _history_dock_widget. Adapt
signal/slot connections for new history_window object.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Apr 2013 16:46:14 -0400 |
parents | 81ec95768520 |
children | 333243133364 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12973
diff
changeset
|
1 ## Copyright (C) 2001-2012 Paul Kienzle |
7325 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
20 ## @deftypefn {Command} {} edit @var{name} |
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
21 ## @deftypefnx {Command} {} edit @var{field} @var{value} |
7650 | 22 ## @deftypefnx {Command} {@var{value} =} edit get @var{field} |
7325 | 23 ## Edit the named function, or change editor settings. |
24 ## | |
25 ## If @code{edit} is called with the name of a file or function as | |
26 ## its argument it will be opened in a text editor. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## |
7325 | 28 ## @itemize @bullet |
29 ## @item | |
30 ## If the function @var{name} is available in a file on your path and | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
31 ## that file is modifiable, then it will be edited in place. If it |
7325 | 32 ## is a system function, then it will first be copied to the directory |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
33 ## @env{HOME} (see further down) and then edited. |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
34 ## If no file is found, then the m-file |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
35 ## variant, ending with ".m", will be considered. If still no 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
|
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 | 38 ## |
39 ## @item | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
40 ## If @var{name} is the name of a function defined in the interpreter but |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
41 ## not in an m-file, then an m-file will be created in @env{HOME} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
42 ## to contain that function along with its current definition. |
7325 | 43 ## |
44 ## @item | |
45 ## If @code{name.cc} is specified, then it will search for @code{name.cc} | |
46 ## in the path and try to modify it, otherwise it will create a new | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
47 ## @file{.cc} file in @env{HOME}. If @var{name} happens to be an |
7325 | 48 ## m-file or interpreter defined function, then the text of that |
49 ## function will be inserted into the .cc file as a comment. | |
50 ## | |
51 ## @item | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
52 ## If @var{name.ext} is on your path then it will be edited, otherwise |
7325 | 53 ## the editor will be started with @file{HOME/name.ext} as the |
54 ## filename. If @file{name.ext} is not modifiable, it will be copied to | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
55 ## @env{HOME} before editing. |
7325 | 56 ## |
12973
b80b18f537ca
doc: Correct various Texinfo warnings about incorrect use of macros.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
57 ## @strong{Warning:} You may need to clear name before the new definition |
7325 | 58 ## is available. If you are editing a .cc file, you will need |
59 ## to mkoctfile @file{name.cc} before the definition will be available. | |
60 ## @end itemize | |
61 ## | |
62 ## If @code{edit} is called with @var{field} and @var{value} variables, | |
63 ## the value of the control field @var{field} will be @var{value}. | |
64 ## If an output argument is requested and the first argument is @code{get} | |
65 ## then @code{edit} will return the value of the control field @var{field}. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
66 ## If the control field does not exist, edit will return a structure |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
67 ## containing all fields and values. Thus, @code{edit get all} returns |
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
|
68 ## a complete control structure. |
7325 | 69 ## The following control fields are used: |
70 ## | |
71 ## @table @samp | |
72 ## @item editor | |
73 ## This is the editor to use to modify the functions. By default it uses | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
74 ## Octave's @env{EDITOR} built-in function, which comes from |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
75 ## @code{getenv ("EDITOR")} and defaults to @code{emacs}. Use @code{%s} |
7325 | 76 ## In place of the function name. For example, |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
77 ## |
7325 | 78 ## @table @samp |
79 ## @item [EDITOR, " %s"] | |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12207
diff
changeset
|
80 ## Use the editor which Octave uses for @code{edit_history}. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
81 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
82 ## @item "xedit %s &" |
7325 | 83 ## pop up simple X11 editor in a separate window |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
84 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
85 ## @item "gnudoit -q \"(find-file \\\"%s\\\")\"" |
7325 | 86 ## Send it to current Emacs; must have @code{(gnuserv-start)} in @file{.emacs}. |
87 ## @end table | |
88 ## | |
8795
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
89 ## See also field 'mode', which controls how the editor is run by Octave. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
90 ## |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
91 ## On Cygwin, you will need to convert the Cygwin path to a Windows |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
92 ## path if you are using a native Windows editor. For example: |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
93 ## @c Set example in small font to prevent overfull line in TeX |
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
94 ## |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
95 ## @smallexample |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
96 ## @exdent '"C:/Program Files/Good Editor/Editor.exe" "$(cygpath -wa %s)"' |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9038
diff
changeset
|
97 ## @end smallexample |
7325 | 98 ## |
99 ## @item home | |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
100 ## This is the location of user local m-files. Be be sure it is in your |
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
101 ## path. The default is @file{~/octave}. |
7325 | 102 ## |
103 ## @item author | |
104 ## This is the name to put after the "## Author:" field of new functions. | |
105 ## By default it guesses from the @code{gecos} field of password database. | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
106 ## |
7325 | 107 ## @item email |
108 ## This is the e-mail address to list after the name in the author field. | |
109 ## By default it guesses @code{<$LOGNAME@@$HOSTNAME>}, and if @code{$HOSTNAME} | |
110 ## is not defined it uses @code{uname -n}. You probably want to override this. | |
111 ## Be sure to use @code{<user@@host>} as your format. | |
112 ## | |
113 ## @item license | |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
114 ## |
7325 | 115 ## @table @samp |
116 ## @item gpl | |
117 ## GNU General Public License (default). | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
118 ## |
7325 | 119 ## @item bsd |
120 ## BSD-style license without advertising clause. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
121 ## |
7325 | 122 ## @item pd |
123 ## Public domain. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
124 ## |
7325 | 125 ## @item "text" |
126 ## Your own default copyright and license. | |
127 ## @end table | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
128 ## |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
129 ## Unless you specify @samp{pd}, edit will prepend the copyright statement |
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
|
130 ## with "Copyright (C) yyyy Function Author". |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
131 ## |
7325 | 132 ## @item mode |
133 ## This value determines whether the editor should be started in async mode | |
8795
bb38a86efa1b
improve documentation for edit.m
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8746
diff
changeset
|
134 ## (editor is started in the background and Octave continues) or sync mode |
14485
51fd0cf227e4
doc: Fix edit command default mode description
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
135 ## (Octave waits until the editor exits). Set it to "sync" to start the editor |
51fd0cf227e4
doc: Fix edit command default mode description
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
136 ## in sync mode. The default is "async" (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
|
137 ## |
2ce6b4258e96
Modified for consistency with Matlab. Modified to respect partial paths needed for overloaded functions.
Ben Abbott <bpabbott@mac.com>
parents:
7444
diff
changeset
|
138 ## @item editinplace |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
139 ## Determines whether files should be edited in place, without regard to |
9038
fca0dc2fb042
Cleanup documentation files stmt.texi and func.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
140 ## whether they are modifiable or not. The default is @code{false}. |
7325 | 141 ## @end table |
142 ## @end deftypefn | |
143 | |
144 ## Author: Paul Kienzle <pkienzle@users.sf.net> | |
145 | |
146 ## Original version by Paul Kienzle distributed as free software in the | |
147 ## public domain. | |
148 | |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
149 function ret = edit (varargin) |
7325 | 150 |
151 ## Pick up globals or default them. | |
152 | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7502
diff
changeset
|
153 persistent FUNCTION = struct ("EDITOR", cstrcat (EDITOR (), " %s"), |
10549 | 154 "HOME", fullfile (default_home, "octave"), |
155 "AUTHOR", default_user(1), | |
156 "EMAIL", [], | |
157 "LICENSE", "GPL", | |
12207
c37f167a816a
edit.m: As most editors open their own window, change mode to "async".
Ben Abbott <bpabbott@mac.com>
parents:
11587
diff
changeset
|
158 "MODE", "async", |
10549 | 159 "EDITINPLACE", false); |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
160 ## Make sure the stateval variables survive "clear functions". |
8506 | 161 mlock; |
7325 | 162 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
163 if (nargin == 1) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
164 ## User has supplied one arg, this can be a single file name |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
165 ## or a cell array of strings containing multiple files to be |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
166 ## opened |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
167 if (iscellstr(varargin{1})) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
168 ## If first arg is a cell array of strings, it becomes the |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
169 ## list of files to be edited |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
170 editfilelist = varargin{1}; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
171 elseif (ischar(varargin{1})) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
172 ## If first arg is a string, create a cell array of strings |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
173 ## of length one (by copying the input cell array) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
174 editfilelist = varargin(1); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
175 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
176 error('edit: expected file to be a string or cell array of strings'); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
177 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
178 elseif (nargin == 2) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
179 ## User has supplied two arguments, these could be two file |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
180 ## names, or a combination of editor state name and new value |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
181 ## for that state, so first check for the various states |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
182 statevar = varargin{1}; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
183 stateval = varargin{2}; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
184 switch (toupper (statevar)) |
7325 | 185 case "EDITOR" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
186 FUNCTION.EDITOR = stateval; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
187 return |
7325 | 188 case "HOME" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
189 if (! isempty (stateval) && stateval(1) == "~") |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
190 stateval = [ default_home, stateval(2:end) ]; |
7325 | 191 endif |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
192 FUNCTION.HOME = stateval; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
193 return |
7325 | 194 case "AUTHOR" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
195 FUNCTION.AUTHOR = stateval; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
196 return |
7325 | 197 case "EMAIL" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
198 FUNCTION.EMAIL = stateval; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
199 return |
7325 | 200 case "LICENSE" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
201 FUNCTION.LICENSE = stateval; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
202 return |
7325 | 203 case "MODE" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
204 if (strcmp (stateval, "sync") || strcmp (stateval, "async")) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
205 FUNCTION.MODE = stateval; |
7325 | 206 else |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
207 error ('edit: expected "edit MODE sync|async"'); |
7325 | 208 endif |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
209 return |
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
|
210 case "EDITINPLACE" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
211 if (ischar (stateval)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
212 if (strcmpi (stateval, "true")) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
213 stateval = true; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
214 elseif (strcmpi (stateval, "false")) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
215 stateval = false; |
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
|
216 else |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
217 stateval = eval (stateval); |
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
|
218 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
|
219 endif |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
220 FUNCTION.EDITINPLACE = stateval; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
221 return |
7325 | 222 case "GET" |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
223 if (isfield (FUNCTION, toupper (stateval))) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
224 ret = FUNCTION.(toupper (stateval)); |
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
|
225 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
|
226 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
|
227 endif |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
228 return |
7325 | 229 otherwise |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
230 ## If none of the states match, assume both inputs are |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
231 ## actually both file names to be opened |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
232 editfilelist = varargin; |
7325 | 233 endswitch |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
234 elseif (nargin > 2) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
235 if (iscellstr(varargin)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
236 editfilelist = varargin; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
237 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
238 error('edit: if supplying more than one input all inputs must be strings containing fiel names to open.'); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
239 endif |
7325 | 240 endif |
241 | |
242 ## Start the editor without a file if no file is given. | |
243 if (nargin < 1) | |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
244 if (exist (FUNCTION.HOME, "dir") == 7) |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
245 curr_dir = pwd (); |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
246 unwind_protect |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
247 chdir (FUNCTION.HOME); |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
248 do_edit (FUNCTION.EDITOR, "", FUNCTION.MODE); |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
249 unwind_protect_cleanup |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
250 chdir (curr_dir); |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
251 end_unwind_protect |
7325 | 252 else |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
253 do_edit (FUNCTION.EDITOR, "", FUNCTION.MODE); |
7325 | 254 endif |
255 return; | |
256 endif | |
257 | |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
258 if (numel(editfilelist) > 1) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
259 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
260 ## Call edit on each of the files in the list if there are more than 1 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
261 for i = 1:numel(editfilelist) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
262 edit(editfilelist{i}); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
263 endfor |
7325 | 264 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
265 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
266 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
267 ## Only one file name was supplied, get it from the cell array |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
268 file = editfilelist{1}; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
269 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
270 ## Check whether the user is trying to edit a builtin or compiled function. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
271 switch (exist (file)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
272 case {3, 5} |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
273 error ("edit: unable to edit a built-in or compiled function"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
274 endswitch |
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
|
275 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
276 ## Checks for whether the file is |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
277 ## absolute or relative should be handled inside file_in_loadpath. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
278 ## That way, it will be possible to look up files correctly given |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
279 ## partial path information. For example, you should be able to |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
280 ## edit a particular overloaded function by doing any one of |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
281 ## |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
282 ## edit classname/foo |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
283 ## edit classname/foo.m |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
284 ## edit @classname/foo |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
285 ## edit @classname/foo.m |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
286 ## |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
287 ## This functionality is needed for other functions as well (at least |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
288 ## help and type; there may be more). So the place to fix that is in |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
289 ## file_in_loadpath, possibly with some help from the load_path class. |
7325 | 290 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
291 ## The code below includes a portion that serves as a place-holder for |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
292 ## the changes suggested above. |
7325 | 293 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
294 ## Create list of explicit and implicit file names. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
295 filelist = {file}; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
296 ## If file has no extension, add file.m and file.cc to the list. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
297 idx = rindex (file, "."); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
298 if (idx == 0) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
299 ## Create the list of files to look for |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
300 filelist = {file}; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
301 if (isempty (regexp (file, '\.m$'))) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
302 ## No ".m" at the end of the file, add to the list. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
303 filelist{end+1} = cat (2, file, ".m"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
304 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
305 if (isempty (regexp (file, '\.cc$'))) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
306 ## No ".cc" at the end of the file, add to the list. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
307 filelist{end+1} = cat (2, file, ".cc"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
308 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
|
309 endif |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
310 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
311 ## If the file includes a path, it may be an overloaded function. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
312 if (! strcmp (file, "@") && index (file, filesep)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
313 ## No "@" at the beginning of the file, add to the list. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
314 numfiles = numel (filelist); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
315 for n = 1:numfiles |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
316 filelist{n+numfiles} = cat (2, "@", filelist{n}); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
317 endfor |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
318 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
|
319 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
320 ## Search the entire path for the 1st instance of a file in the list. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
321 fileandpath = ""; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
322 for n = 1:numel (filelist) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
323 filetoedit = file_in_path (path, filelist{n}); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
324 if (! isempty (filetoedit)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
325 ## The path is explicitly included. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
326 fileandpath = filetoedit; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
327 break; |
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
|
328 endif |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
329 endfor |
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
|
330 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
331 if (! isempty (fileandpath)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
332 ## If the file exists, then edit it. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
333 if (FUNCTION.EDITINPLACE) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
334 ## Edit in place even if it is protected. |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
335 do_edit (FUNCTION.EDITOR, fileandpath, FUNCTION.MODE); |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
336 return; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
337 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
338 ## If the file is modifiable in place then edit it, otherwise make |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
339 ## a copy in HOME and then edit it. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
340 fid = fopen (fileandpath, "r+t"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
341 if (fid < 0) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
342 from = fileandpath; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
343 fileandpath = cstrcat (FUNCTION.HOME, from (rindex (from, filesep):end)); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
344 [status, msg] = copyfile (from, fileandpath, 1); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
345 if (status == 0) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
346 error (msg); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
347 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
348 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
349 fclose (fid); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
350 endif |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
351 do_edit (FUNCTION.EDITOR, fileandpath, FUNCTION.MODE); |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
352 return; |
7325 | 353 endif |
354 endif | |
355 | |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
356 ## If editing a new file that is neither a m-file or an oct-file, |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
357 ## just edit it. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
358 fileandpath = file; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
359 idx = rindex (file, "."); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
360 name = file(1:idx-1); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
361 ext = file(idx+1:end); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
362 switch (ext) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
363 case {"cc", "m"} |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
364 0; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
365 otherwise |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
366 do_edit (FUNCTION.EDITOR, fileandpath, FUNCTION.MODE); |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
367 return; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
368 endswitch |
7325 | 369 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
370 ## The file doesn't exist in path so create it, put in the function |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
371 ## template and edit it. |
7325 | 372 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
373 ## Guess the email name if it was not given. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
374 if (isempty (FUNCTION.EMAIL)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
375 host = getenv ("HOSTNAME"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
376 if (isempty (host) && ispc ()) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
377 host = getenv ("COMPUTERNAME"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
378 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
379 if (isempty (host)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
380 [status, host] = system ("uname -n"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
381 ## trim newline from end of hostname |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
382 if (! isempty (host)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
383 host = host(1:end-1); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
384 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
385 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
386 if (isempty (host)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
387 FUNCTION.EMAIL = " "; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
388 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
389 FUNCTION.EMAIL = cstrcat ("<", default_user(0), "@", host, ">"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
390 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
391 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
392 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
393 ## Fill in the revision string. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
394 now = localtime (time); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
395 revs = cstrcat ("Created: ", strftime ("%Y-%m-%d", now)); |
7325 | 396 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
397 ## Fill in the copyright string. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
398 copyright = cstrcat (strftime ("Copyright (C) %Y ", now), FUNCTION.AUTHOR); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
399 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
400 ## Fill in the author tag field. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
401 author = cstrcat ("Author: ", FUNCTION.AUTHOR, " ", FUNCTION.EMAIL); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
402 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
403 ## Fill in the header. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
404 uclicense = toupper (FUNCTION.LICENSE); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
405 switch (uclicense) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
406 case "GPL" |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
407 head = cstrcat (copyright, "\n\n", "\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
408 This program is free software; you can redistribute it and/or modify\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
409 it under the terms of the GNU General Public License as published by\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
410 the Free Software Foundation; either version 3 of the License, or\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
411 (at your option) any later version.\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
412 \n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
413 This program is distributed in the hope that it will be useful,\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
414 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
415 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
416 GNU General Public License for more details.\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
417 \n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
418 You should have received a copy of the GNU General Public License\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
419 along with Octave; see the file COPYING. If not, see\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
420 <http://www.gnu.org/licenses/>.\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
421 "); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
422 tail = cstrcat (author, "\n", revs); |
7325 | 423 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
424 case "BSD" |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
425 head = cstrcat (copyright, "\n\n", "\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
426 This program is free software; redistribution and use in source and\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
427 binary forms, with or without modification, are permitted provided that\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
428 the following conditions are met:\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
429 \n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
430 1.Redistributions of source code must retain the above copyright\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
431 notice, this list of conditions and the following disclaimer.\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
432 2.Redistributions in binary form must reproduce the above copyright\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
433 notice, this list of conditions and the following disclaimer in the\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
434 documentation and/or other materials provided with the distribution.\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
435 \n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
436 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
437 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
438 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
439 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
440 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
441 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
442 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
443 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
444 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
445 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
446 SUCH DAMAGE.\ |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
447 "); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
448 tail = cstrcat (author, "\n", revs); |
7325 | 449 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
450 case "PD" |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
451 head = ""; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
452 tail = cstrcat (author, "\n", revs, "\n\n", |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
453 "This program is granted to the public domain."); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
454 |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
455 otherwise |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
456 head = ""; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
457 tail = cstrcat (copyright, "\n\n", FUNCTION.LICENSE, "\n", |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
458 author, "\n", revs); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
459 endswitch |
7325 | 460 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
461 ## Generate the function template. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
462 exists = exist (name); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
463 switch (ext) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
464 case {"cc", "C", "cpp"} |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
465 if (isempty (head)) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
466 comment = cstrcat ("/*\n", tail, "\n\n*/\n\n"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
467 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
468 comment = cstrcat ("/*\n", head, "\n\n", tail, "\n\n*/\n\n"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
469 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
470 ## If we are shadowing an m-file, paste the code for the m-file. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
471 if (any (exists == [2, 103])) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
472 code = cstrcat ("\\ ", strrep (type (name){1}, "\n", "\n// ")); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
473 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
474 code = " "; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
475 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
476 body = cstrcat ("#include <octave/oct.h>\n\n", |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
477 "DEFUN_DLD(", name, ",args,nargout,\"\\\n", |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
478 name, "\\n\\\n\")\n{\n", |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
479 " octave_value_list retval;\n", |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
480 " int nargin = args.length ();\n\n", |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
481 code, "\n return retval;\n}\n"); |
7325 | 482 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
483 text = cstrcat (comment, body); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
484 case "m" |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
485 ## If we are editing a function defined on the fly, paste the |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
486 ## code. |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
487 if (any (exists == [2, 103])) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
488 body = type (name){1}; |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
489 else |
15612
8b04a7d67d8a
Use texinfo syntax in default m-file template.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15526
diff
changeset
|
490 body = cstrcat ("function [ret] = ", name, " ()\n\nendfunction\n"); |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
491 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
492 if (isempty (head)) |
15612
8b04a7d67d8a
Use texinfo syntax in default m-file template.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15526
diff
changeset
|
493 comment = cstrcat ("## -*- texinfo -*- \n## @deftypefn {Function File}", |
8b04a7d67d8a
Use texinfo syntax in default m-file template.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15526
diff
changeset
|
494 "{@var{ret} =}", name, "(@var{x}, @var{y})\n##\n", |
8b04a7d67d8a
Use texinfo syntax in default m-file template.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15526
diff
changeset
|
495 "## @seealso{}\n## @end deftypefn\n\n", |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
496 "## ", strrep (tail, "\n", "\n## "), "\n\n"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
497 else |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
498 comment = cstrcat ("## ", strrep (head,"\n","\n## "), "\n\n", ... |
15612
8b04a7d67d8a
Use texinfo syntax in default m-file template.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15526
diff
changeset
|
499 "## -*- texinfo -*- \n## @deftypefn {Function File}", |
8b04a7d67d8a
Use texinfo syntax in default m-file template.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15526
diff
changeset
|
500 "{@var{ret} =}", name, "(@var{x}, @var{y})\n##\n", |
8b04a7d67d8a
Use texinfo syntax in default m-file template.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15526
diff
changeset
|
501 "## @seealso{}\n## @end deftypefn\n\n", |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
502 "## ", strrep (tail, "\n", "\n## "), "\n\n"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
503 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
504 text = cstrcat (comment, body); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
505 endswitch |
7325 | 506 |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
507 ## Write the initial file (if there is anything to write) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
508 fid = fopen (fileandpath, "wt"); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
509 if (fid < 0) |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
510 error ("edit: could not create %s", fileandpath); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
511 endif |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
512 fputs (fid, text); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
513 fclose (fid); |
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
514 |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
515 do_edit (FUNCTION.EDITOR, fileandpath, FUNCTION.MODE); |
15526
1353ca03266f
add ability to edit multiple files (bug #37573)
Richard Crozier <richard.crozier@yahoo.co.uk>
parents:
14868
diff
changeset
|
516 |
7325 | 517 endif |
518 | |
519 endfunction | |
520 | |
521 function ret = default_home () | |
522 | |
523 ret = getenv ("HOME"); | |
524 if (isempty (ret)) | |
525 ret = glob ("~"); | |
526 if (! isempty (ret)) | |
527 ret = ret{1}; | |
528 else | |
529 ret = ""; | |
530 endif | |
531 endif | |
532 | |
533 endfunction | |
534 | |
7434 | 535 ## Return the name associated with the current user ID. |
7325 | 536 ## |
7434 | 537 ## If LONG_FORM is 1, return the full name. This will be the |
538 ## default author. Otherwise return the login name. | |
7325 | 539 ## login@host will be the default email address. |
540 | |
541 function ret = default_user (long_form) | |
542 | |
543 ent = getpwuid (getuid); | |
544 if (! isstruct (ent)) | |
545 ret = getenv ("USER"); | |
7330 | 546 if (isempty (ret)) |
7325 | 547 ret = getenv ("USERNAME"); |
548 endif | |
549 elseif (long_form) | |
550 ret = ent.gecos; | |
7434 | 551 pos = strfind (ret, ","); |
552 if (! isempty (pos)) | |
553 ret = ret(1:pos-1); | |
554 endif | |
7325 | 555 else |
556 ret = ent.name; | |
557 endif | |
558 | |
559 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
|
560 |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
561 function do_edit (editor, file, mode) |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
562 |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
563 ## Give the hook function a chance. If that fails, fall back |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
564 ## on running an editor with the system function. |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
565 |
16420
81ec95768520
use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents:
16399
diff
changeset
|
566 status = __octave_link_edit_file__ (file); |
16399
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
567 |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
568 if (! status) |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
569 system (sprintf (undo_string_escapes (editor), |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
570 cstrcat ("\"", file, "\"")), |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
571 [], mode); |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
572 endif |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
573 |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
574 endfunction |
f9a737fd8829
allow command-line edit function to use GUI editor
John W. Eaton <jwe@octave.org>
parents:
16045
diff
changeset
|
575 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
576 |
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
|
577 %!test |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
578 %! s.editor = edit ("get", "editor"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
579 %! s.home = edit ("get", "home"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
580 %! s.author = edit ("get", "author"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
581 %! s.email = edit ("get", "email"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
582 %! s.license = edit ("get", "license"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
583 %! s.editinplace = edit ("get", "editinplace"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8506
diff
changeset
|
584 %! 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
|
585 %! 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
|
586 %! 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
|
587 %! 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
|
588 %! 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
|
589 %! 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
|
590 %! 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
|
591 %! 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
|
592 %! 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
|
593 %! 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
|
594 %! 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
|
595 %! 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
|
596 %! 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
|
597 %! 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
|
598 %! 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
|
599 %! 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
|
600 %! 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
|
601 %! 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
|
602 %! 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
|
603 %! 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
|
604 %! 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
|
605 %! 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
|
606 %! 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
|
607 %! 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
|
608 %! 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
|
609 %! 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
|
610 |