comparison scripts/miscellaneous/edit.m @ 17592:28eb00d3edf4

edit.m: Work correctly for file names with '~'. * scripts/miscellaneous/edit.m: Use tilde_expand() on base filename immediately before proceeding to make a search list based off that filename.
author Rik <rik@octave.org>
date Mon, 07 Oct 2013 17:06:56 -0700
parents 6437a6815bc6
children 539aea0e59f4
comparison
equal deleted inserted replaced
17591:7c479b7d3aab 17592:28eb00d3edf4
227 else 227 else
228 ret = FUNCTION; 228 ret = FUNCTION;
229 endif 229 endif
230 return; 230 return;
231 otherwise 231 otherwise
232 ## If none of the states match, assume both inputs are 232 ## If none of the states match, assume both inputs are actually
233 ## actually both file names to be opened 233 ## file names to be opened.
234 editfilelist = varargin; 234 editfilelist = varargin;
235 endswitch 235 endswitch
236 elseif (nargin > 2) 236 elseif (nargin > 2)
237 if (iscellstr (varargin)) 237 if (iscellstr (varargin))
238 editfilelist = varargin; 238 editfilelist = varargin;
265 endfor 265 endfor
266 266
267 else 267 else
268 268
269 ## Only one file name was supplied, get it from the cell array 269 ## Only one file name was supplied, get it from the cell array
270 file = editfilelist{1}; 270 file = tilde_expand (editfilelist{1});
271 271
272 ## Check whether the user is trying to edit a builtin or compiled function. 272 ## Check whether the user is trying to edit a builtin or compiled function.
273 switch (exist (file)) 273 switch (exist (file))
274 case {3, 5} 274 case {3, 5}
275 error ("edit: unable to edit a built-in or compiled function"); 275 error ("edit: unable to edit a built-in or compiled function");
298 ## If file has no extension, add file.m and file.cc to the list. 298 ## If file has no extension, add file.m and file.cc to the list.
299 idx = rindex (file, "."); 299 idx = rindex (file, ".");
300 if (idx == 0) 300 if (idx == 0)
301 if (isempty (regexp (file, '\.m$'))) 301 if (isempty (regexp (file, '\.m$')))
302 ## No ".m" at the end of the file, add to the list. 302 ## No ".m" at the end of the file, add to the list.
303 filelist{end+1} = [file ".m"]; 303 filelist(end+1) = [file ".m"];
304 endif 304 endif
305 if (isempty (regexp (file, '\.cc$'))) 305 if (isempty (regexp (file, '\.cc$')))
306 ## No ".cc" at the end of the file, add to the list. 306 ## No ".cc" at the end of the file, add to the list.
307 filelist{end+1} = [file ".cc"]; 307 filelist(end+1) = [file ".cc"];
308 endif 308 endif
309 endif 309 endif
310 310
311 keyboard;
311 ## If the file includes a path, it may be an overloaded function. 312 ## If the file includes a path, it may be an overloaded function.
312 if (! strcmp (file, "@") && index (file, filesep)) 313 if (! index (file, "@") && index (file, filesep))
313 ## No "@" at the beginning of the file, add to the list. 314 ## No "@" at the beginning of the file, add to the list.
314 numfiles = numel (filelist); 315 numfiles = numel (filelist);
315 for n = 1:numfiles 316 for n = 1:numfiles
316 filelist{n+numfiles} = ["@" filelist{n}]; 317 filelist(n+numfiles) = ["@" filelist{n}];
317 endfor 318 endfor
318 endif 319 endif
319 320
320 ## Search the entire path for the 1st instance of a file in the list. 321 ## Search the entire path for the 1st instance of a file in the list.
321 fileandpath = ""; 322 fileandpath = "";
351 do_edit (FUNCTION.EDITOR, fileandpath, FUNCTION.MODE); 352 do_edit (FUNCTION.EDITOR, fileandpath, FUNCTION.MODE);
352 return; 353 return;
353 endif 354 endif
354 endif 355 endif
355 356
356 ## If editing a new file that is neither a m-file or an oct-file, 357 ## If editing a new file that is neither an m-file or an oct-file,
357 ## just edit it. 358 ## just edit it.
358 fileandpath = file; 359 fileandpath = file;
359 idx = rindex (file, "."); 360 idx = rindex (file, ".");
360 name = file(1:idx-1); 361 name = file(1:idx-1);
361 ext = file(idx+1:end); 362 ext = file(idx+1:end);