|
From: | Ben Abbott |
Subject: | Re: bug in edit.m |
Date: | Wed, 16 Jan 2008 22:03:16 -0500 |
On Jan 15, 2008, at 8:56 PM, John W. Eaton wrote: On 15-Jan-2008, Ben Abbott wrote: Please review and comment. 2008-01-16 Ben Abbott <address@hidden> * miscellaneous/edit.m: Changed behavior to be consistent with Matlab. Open all existing files in place. New files are opened in the pwd. Index: edit.m =================================================================== RCS file: /cvs/octave/scripts/miscellaneous/edit.m,v retrieving revision 1.3 diff -u -r1.3 edit.m --- edit.m 29 Dec 2007 00:30:20 -0000 1.3 +++ edit.m 17 Jan 2008 02:56:11 -0000 @@ -27,28 +27,25 @@ ## ## @itemize @bullet ## @item -## If the function @var{name} is available in a file on your path and -## that file is modifiable, then it will be edited in place. If it -## is a system function, then it will first be copied to the directory -## @code{HOME} (see further down) and then edited. +## If the function @var{name} is available in a file on your path it +## will be edited in place. ## ## @item -## If @var{name} is the name of a function defined in the interpreter but -## not in an m-file, then an m-file will be created in @code{HOME} +## If @var{name} is the name of a function defined in the interpreter +## but not in an m-file, then an m-file will be created in @code{PWD} ## to contain that function along with its current definition. ## ## @item ## If @code{name.cc} is specified, then it will search for @code{name.cc} ## in the path and try to modify it, otherwise it will create a new -## @file{.cc} file in @code{HOME}. If @var{name} happens to be an +## @file{.cc} file in @code{PWD}. If @var{name} happens to be an ## m-file or interpreter defined function, then the text of that ## function will be inserted into the .cc file as a comment. ## ## @item -## If @var{name.ext} is on your path then it will be editted, otherwise -## the editor will be started with @file{HOME/name.ext} as the -## filename. If @file{name.ext} is not modifiable, it will be copied to -## @code{HOME} before editing. +## If @var{name.ext} is on your path then it will be edited, otherwise +## the editor will be started with @file{./name.ext} as the +## filename. ## ## @strong{WARNING!} You may need to clear name before the new definition ## is available. If you are editing a .cc file, you will need @@ -185,47 +182,31 @@ error ("unable to edit a built-in or compiled function"); endswitch - ## Find file in path. - idx = rindex (file, "."); - if (idx != 0) - ## If file has an extension, use it. - path = file_in_loadpath (file); - else - ## Otherwise try file.cc, and if that fails, default to file.m. - path = file_in_loadpath (strcat (file, ".cc")); - if (isempty (path)) - file = strcat (file, ".m"); - path = file_in_loadpath (file); + ## If no path info, and no ".m" look for both the file and file+".m" + if !(any (strfind (file, filesep)) || \ + (any (strfind (file, ".")) && isempty (regexp (file, "\\.m$")))) + files = {file}; + if (isempty (regexp (file, "\\.m$"))) + ## If the name is not explicity an m-file, create a list with each. + files{2} = strcat (file, ".m"); + endif + ## File without the ".m" exists, it has precidence over the ".m" version. + file_to_edit = file_in_loadpath (files); + if (numel (file_to_edit)) + file = file_to_edit; endif endif - ## If the file exists and is modifiable in place then edit it, - ## otherwise copy it and then edit it. - if (! isempty (path)) - fid = fopen (path, "r+t"); - if (fid < 0) - from = path; - path = strcat (FUNCTION.HOME, from (rindex (from, filesep):end)) - [status, msg] = copyfile (from, path, 1); - if (status == 0) - error (msg); - endif - else - fclose(fid); - endif - system (sprintf (FUNCTION.EDITOR, strcat ("\"", path, "\"")), - [], FUNCTION.MODE); + ## If the file exists, edit it. + if exist (file) + system (sprintf (FUNCTION.EDITOR, strcat ("\"", file, "\"")), + [], FUNCTION.MODE); return; endif ## If editing something other than a m-file or an oct-file, just ## edit it. - idx = rindex (file, filesep); - if (idx != 0) - path = file; - else - path = fullfile (FUNCTION.HOME, file); - endif + path = file; idx = rindex (file, "."); name = file(1:idx-1); ext = file(idx+1:end); @@ -373,6 +354,8 @@ text = strcat (comment, body); endswitch +path +file ## Write the initial file (if there is anything to write) fid = fopen (path, "wt"); if (fid < 0) |
edit.patch
Description: Binary data
edit.ChangeLog
Description: Binary data
[Prev in Thread] | Current Thread | [Next in Thread] |