Index: edit.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/miscellaneous/edit.m,v retrieving revision 1.18 diff -u -r1.18 edit.m --- edit.m 22 Mar 2006 17:50:47 -0000 1.18 +++ edit.m 31 Mar 2006 01:24:53 -0000 @@ -1,85 +1,115 @@ -## edit name -## Edit the named function. -## -## If the function is available in a file on your path and that file -## is modifiable, then it will be editted in place. If it is a system -## function, then it will first be copied to the directory HOME -## and then editted. -## -## If 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 HOME -## to contain that function along with its current definition. -## -## If name.cc is specified, then it will search for name.cc in the -## path and try to modify it, otherwise it will create a new .cc file -## in HOME. If 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. -## -## If name.ext is on your path then it will be editted, otherwise -## the editor will be started with HOME/name.ext as the -## filename. If name.ext is not modifiable, it will be copied to -## HOME before editting. -## -## WARNING!! You may need to clear name before the new definition -## is available. If you are editting a .cc file, you will need -## to mkoctfile name.cc before the definition will be available. -## -## edit field value -## Set the value for an edit control field. -## -## edit get field -## Return the value for an edit control field. +## -*- texinfo -*- +## @deftypefn {Function File} {} edit @var{name} +## Edit the named function. +## +## If the function is available in a file on your path and that file +## is modifiable, then it will be editted in place. If it is a system +## function, then it will first be copied to the directory @var{home} +## and then editted. +## +## 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 @var{home} +## to contain that function along with its current definition. +## +## If @var{name}.cc is specified, then it will search for @var{name}.cc in the +## path and try to modify it, otherwise it will create a new .cc file +## in @var{home}. 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. +## +## If @var{name}.ext is on your path then it will be editted, otherwise +## the editor will be started with @var{home}/@var{name}.ext as the +## filename. If @var{name}.ext is not modifiable, it will be copied to +## @var{home} before editting. +## +## WARNING!! You may need to clear @var{name} before the new definition +## is available. If you are editting a .cc file, you will need +## to mkoctfile @var{name}.cc before the definition will be available. +## +## @table @samp +## @item edit(@var{field}, @var{value}) +## Set the value for an edit control field. +## +## @item edit(@var{get}, @var{field}) +## Return the value for an edit control field. +## @end table ## ## The following control fields are used: ## -## editor -## This is the editor to use to modify the functions. By default it uses -## Octave's EDITOR state variable, which comes from getenv("EDITOR") and -## defaults to vi. Use %s in place of the function name. E.g., -## [EDITOR, " %s"] -## use the editor which Octave uses for bug_report -## "xedit %s &" -## pop up simple X11 editor in a separate window -## "gnudoit -q \"(find-file \\\"%s\\\")\"" -## send it to current emacs; must have (gnuserv-start) in .emacs -## -## home -## This is the location of user local m-files. Be be sure it is on LOADPATH. -## The default is ~/octave. -## -## author -## This is the name to put after the "## Author:" field of new functions. -## By default it guesses from the `gecos' field of password database. -## -## email -## This is the e-mail address to list after the name in the author field. -## By default it guesses , and if $HOSTNAME is not -## defined it uses "uname -n". You probably want to override this. Be -## sure to use "" as your format. -## -## license -## gpl GNU General Public License (default) -## bsd BSD-style license without advertising clause -## pd public domain -## "text" your own default copyright and license -## -## Unless you specify PD, edit will prepend the copyright statement -## with "Copyright (C) yyyy Function Author" +## @table @samp +## @item editor +## This is the editor to use to modify the functions. By default it uses +## Octave's EDITOR state variable, which comes from getenv("EDITOR") and +## defaults to vi. Use %s in place of the function name. E.g., +## +## @example +## [EDITOR, " %s"] +## @end example +## use the editor which Octave uses for bug_report +## +## @example +## "xedit %s &" +## @end example +## pop up simple X11 editor in a separate window +## +## @example +## "gnudoit -q \"(find-file \\\"%s\\\")\"" +## @end example +## send it to current emacs; must have (gnuserv-start) in .emacs +## +## @example +## '"C:/Program Files/Good Editor/Editor.exe" "`cygpath -wa %s`"' +## @end example +## in cygwin, to use your favorite native windows based (non-cygwin) +## editor. Pay special attention to the "" and the ``; they are +## significant. +## +## @item home +## This is the location of user local m-files. Be be sure it is on LOADPATH. +## The default is ~/octave. +## +## @item author +## This is the name to put after the "## Author:" field of new functions. +## By default it guesses from the `gecos' field of password database. +## +## @item email +## This is the e-mail address to list after the name in the author field. +## By default it guesses <$LOGNAME@@$HOSTNAME>, and if $HOSTNAME is not +## defined it uses "uname -n". You probably want to override this. Be +## sure to use "" as your format. +## +## @item license +## +## @table @samp +## @item gpl +## GNU General Public License (default) +## +## @item bsd +## BSD-style license without advertising clause +## +## @item pd +## public domain +## +## @item "text" +## your own default copyright and license +## +## @end table +## +## Unless you specify PD, edit will prepend the copyright statement +## with "Copyright (C) yyyy Function Author" +## @end table +## @end deftypefn ## Author: Paul Kienzle ## This program is granted to the public domain. -## 2001-04-10 Paul Kienzle -## * Initial revision - ## PKG_ADD: mark_as_command edit function ret = edit(file,state) ## pick up globals or default them persistent FUNCTION = struct ("EDITOR", [ EDITOR, " %s" ], - "HOME", [ getenv("HOME"), "/octave" ], + "HOME", [ getenv("HOME"), filesep, "octave" ], "AUTHOR", getpwuid(getuid).gecos, "EMAIL", [], "LICENSE", "GPL"); @@ -136,7 +166,7 @@ fclose(fid); else from = path; - path = [ FUNCTION.HOME, from(rindex(from,"/"):length(from)) ] ; + path = [ FUNCTION.HOME, from(rindex(from, filesep):length(from)) ] ; system (sprintf("cp '%s' '%s'", from, path)); endif system(sprintf(FUNCTION.EDITOR, ["'", path, "'"])); @@ -145,7 +175,7 @@ ## if editing something other than a m-file or an oct-file, just ## edit it. - path = [ FUNCTION.HOME, "/", file ]; + path = [ FUNCTION.HOME, filesep, file ]; idx = rindex(file,'.'); name = file(1:idx-1); ext = file(idx+1:length(file)); @@ -155,14 +185,14 @@ system(sprintf(FUNCTION.EDITOR, ["'", path, "'"])); return; endswitch - + ## the file doesn't exist in path so create it, put in the function ## template and edit it. ## guess the email name if it was not given. if (isempty(FUNCTION.EMAIL)) host=getenv("HOSTNAME"); - if isempty(host), + if isempty(host), [status, host] = system("uname -n"); # trim newline from end of hostname if !isempty(host) host = host(1:length(host)-1); endif @@ -173,7 +203,7 @@ FUNCTION.EMAIL = [ "<", getpwuid(getuid).name, "@", host, ">" ]; endif endif - + ## fill in the revision string now = localtime(time); revs = [ strftime("%Y-%m-%d",now), " ", FUNCTION.AUTHOR, " ", ... @@ -184,7 +214,7 @@ ## fill in the author tag field author = [ "Author: ", FUNCTION.AUTHOR, " ", FUNCTION.EMAIL ]; - + ## fill in the header uclicense=toupper(FUNCTION.LICENSE); switch uclicense @@ -241,7 +271,7 @@ tail = [ copyright, "\n\n", FUNCTION.LICENSE, "\n", ... author, "\n\n", revs ]; endswitch - + ## generate the function template exists = exist(name); switch (ext)