help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: edit on a read only file


From: Peter Cloetens
Subject: Re: edit on a read only file
Date: Tue, 24 Nov 2009 23:26:53 +0100
User-agent: Thunderbird 2.0.0.21 (X11/20090302)

Jaroslav Hajek wrote:


On Tue, Nov 24, 2009 at 9:45 PM, Peter Cloetens <address@hidden <mailto:address@hidden>> wrote:

    Hello,
    When you call 'edit' on a read only file, a copy of the file is
    made in
    your home directory and the copy is edited.
    People tend to edit scripts just to view the code and learn from
    it. The
    issue is that after they used 'edit' a single time on a standard
    script
    they will have a copy in their home directory that will become their
    default.
    This copy will not be maintained and necessarily give incompatibility
    issues with later versions of octave.
    Is there a way to change this behavior and just edit the read only
    file
    as it is (read only)?
    It could be solved by asking the user if a copy should be made or not,
    something along the lines:

     ## 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)
         copyreadonly = input("File is read-only, make a copy [y/n] ?
    ","s");
         if strcmp(copyreadonly, "y")
           from = path;
           path = strcat (FUNCTION.HOME, from (rindex (from,
    filesep):end))
           [status, msg] = copyfile (from, path, 1);
           if (status == 0)
             error (msg);
           endif
         endif
       else
         fclose(fid);
       endif
       system (sprintf (FUNCTION.EDITOR, strcat ("\"", path, "\"")),
           [], FUNCTION.MODE);
       return;
     endif

    Peter



    --
    Peter Cloetens
    X-Ray Imaging Group
    Tel: +33 4 76 88 26 50
    Mailto: address@hidden <mailto:address@hidden>

    European Synchrotron Radiation Facility (ESRF)
    6 rue Jules Horowitz
    F-38043 Grenoble
    http://www.esrf.eu



Add this to your ~/.octaverc:
edit editinplace true

hth
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz <http://www.highegg.matfyz.cz>
Thanks a lot. I did not notice this possibility because we are still using version 3.0.5.
Peter



reply via email to

[Prev in Thread] Current Thread [Next in Thread]