DRAFT Ved utility for editing files whose names have spaces 
Author Message
 DRAFT Ved utility for editing files whose names have spaces

[To reply replace "Aaron.Sloman.XX" with "A.Sloman"]

I found that the low level procedure vedreadfile (and also some others,
like vedfile_line_repeater) can accept a file name with spaces. So can
the unix utilities readable, sysopen, etc.

This made it fairly easy to define a procedure to read a file whose
name has spaces into a Ved buffer, without altering any VED system
files.

I.e. the file appended to this message should work in all CURRENT
versions of Poplog.

It could be installed in $poplocal/local/auto/ved_spaceved.p

I'll put it (and any future modifications) in
    http://www.*-*-*.com/

A shorter name may be more appropriate so that you don't
have to type

    ENTER spaceved .....

I worried that any shorter name I could dream up (e.g. ved_sv)
might clash with some user's ved utility. It's easy enough to
change the name or define your own synonym.

The procedure ved_spaceved enables you to read in a file with
commands like:

    ENTER spaceved my silly file from windows

It creates a ved buffer whose name is 'my silly file from windows'

Like wise it will work if a directory name includes a space:

    ENTER spaceved my dir/my file

The new file is writeable by default, though you could change the code
below to make a file non-writeable. Or immediately after reading it in
do
    ENTER pved

to make the file protected.

Minor problem: what you will see on the status line for a file
read in using ved_spaceved has "workbuff" in it. e.g. this sort of
thing:

    (examining: workbuff my dir/my file)

I can't change that without digging deep into the system. But it is
a very minor irritation.

I also tried doing all this a different way: making ved read in the file
but giving the buffer a different name, with hyphens replacing spaces in
the file name part (not the directory part, as Ved will not allow a file
path to refer to a nonexistent directory).

That was not difficult (using vedfile_line_repeater, or vedreadfile)
but it meant that you could not use ordinary commands for writing and
saving the file.

To overcome that I had to define a procedure ved_spacewrite to convert
the hyphens back, and then there's a problem if the original file name
had a mixture of hyphens and spaces!

Anyhow, in the end I decided that conversion to a new filename
was not worth the hassle. You can always change the name after
reading in the file, using the ENTER name command, if you wish.

In other respects a file read in with ved_spaceved will behave slightly
differently from other ved files. E.g. if you give the same command
twice you will get two copies of the file, so to re-edit the file while
it is already in a ved buffer you must use vedfileselect (ESC e)
or ved_rb (ENTER rb) or select with the mouse.

I have tested this only on solaris and linux poplog.

I have a bit of code for tests for a full path name by seeing whether
the file name starts with "/". That will not work on Windows, and
in some cases may not work on VMS.

Aaron
===
Aaron Sloman, ( http://www.*-*-*.com/ ~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK

PAPERS: http://www.*-*-*.com/
TOOLS: http://www.*-*-*.com/
Phone: +44-121-414-4775        Fax:   +44-121-414-4281/2799

DRAFT autoloadable library file follows
=======================================================================

/* --- Copyright University of Birmingham 2001. All rights reserved. ------
 > File:            $poplocal/local/auto/ved_spaceved.p
 > Purpose:                  Read in file whose name contains spaces
 > Author:          Aaron Sloman, May 13 2001
 > Documentation:    Below for now
 > Related Files:
 */

/*

HELP ved_spaceved

    Utility for reading in files whose names include spaces.
    This is needed because ved_ved assumes that if its argument
    includes spaces then it refers to several files, which should
    all be read into Ved.

ENTER spaceved my silly file.p

    This command will look for a file called 'my silly file.p'
    Warning: this will not use vedsearchlist, so explicit path
    names will be needed for files not in the current directory.

        It will also not find the file if it is already being edited,
        so use ESC e (vedfileselect) to return to a file previously
        edited with this command.

        The ENTER spaceved command will make ved read the file into
        a Ved buffer and in many ways it will be like an ordinary ved
    file. However, on the status line ved will show the type "workbuff"
        before the file name as a reminder that this is an unusual file.

*/

section;

define lconstant setupglobals(newfile, string);
        ;;; Set up some of the globals for the new file, to make it behave
        ;;; more or less like an ordinary file

        dlocal ved_current_file = newfile;

        sysfileok(string) -> string;

        ;;; modify this test for windows ???
        if string(1) = `/` then
                ;;; it's a full path name
                string ->> vedpathname -> vedcurrent;
                nullstring -> veddirectory;
        else
                ;;; it's a relative path
                current_directory dir_>< string -> vedpathname;
                current_directory -> veddirectory;
                string -> vedcurrent;
        endif;

        ;;; if not false, it will be "workbuff"!
        false -> vedfileprops;
        false -> vedchanged;
        ;;; Maybe the user should have a choice about this:
        true -> vedwriteable;

enddefine;

define ved_spaceved();
        ;;; Edit file whose name (or path) has spaces.

        ;;; Check that the file exists
        lvars filedev = readable(vedargument);
        unless filedev then
                vederror('FILE NOT FOUND: ' <> vedargument);
        endunless;

        ;;; Prepare new ved file structure containing the file
        ;;; ignore first result of vedreadfile
        lvars (_, newfile) = vedreadfile(filedev, vedveddefaults, false);

        setupglobals(newfile, vedargument);

        vededit(newfile);

enddefine;

endsection;



Fri, 31 Oct 2003 00:05:08 GMT  
 DRAFT Ved utility for editing files whose names have spaces

Hi Aaron,

I'm mailing you directly rather than posting because I want to be sure I
don't have the wrong end of the stick.

Quote:
> This made it fairly easy to define a procedure to read a file whose
> name has spaces into a Ved buffer, without altering any VED system
> files.

Your procedure is going to be immediately useful to people who are
suffering from the problem of spaces in names, but wouldn't it be good
to also fix the problem at source, i.e., in the system files?

Of course there are going to be people, e.g., students, who aren't in a
position to install a new system for themselves and will want to use
your procedure in the meantime, but in the long run, a separate
procedure for reading in files with spaces in their names would be an
extra piece of obscure lore for the new user to trip over.

From the (lack of) reaction to your original post, I would guess that
there are few if any people who make use of the multi file facility, so
it would probably be ok to make the possibility of spaces in names be
the default, and have a settable variable to give you the old behavior
(with a warning in the documentation that it is likely to be phased
out).

The only remark I have about your procedure is that it seems to prevent
the user from opening a new file with a space in the name.  (I haven't
actually tried your code, just read it.)      

        ;;; Check that the file exists
        lvars filedev = readable(vedargument);
        unless filedev then
                vederror('FILE NOT FOUND: ' <> vedargument);
        endunless;

With an ordinary space-free filename, if the file doesn't exist I get a
"new file" message on the command line, rather than an error message.
In the windows code that Robert Duncan wrote, it also seems to be
impossible to open a new file with spaces in the name from the command
line.  Is there some deeper problem that makes this necessary?

Regards,

Steve



Fri, 31 Oct 2003 20:43:44 GMT  
 DRAFT Ved utility for editing files whose names have spaces

Quote:


> Hi Aaron,

> I'm mailing you directly rather than posting because I want to be sure I
> don't have the wrong end of the stick.

Well, here is my message on the newsgroup, so I've screwed up.  Sorry.

Steve



Fri, 31 Oct 2003 20:46:20 GMT  
 DRAFT Ved utility for editing files whose names have spaces
[To reply replace "Aaron.Sloman.XX" with "A.Sloman"]

Quote:

> Hi Aaron,

> I'm mailing you directly rather than posting because I want to be sure I
> don't have the wrong end of the stick.

No wrong ends that I noticed, apart from accidental posting to the
group!

Quote:
> Your procedure is going to be immediately useful to people who are
> suffering from the problem of spaces in names, but wouldn't it be good
> to also fix the problem at source, i.e., in the system files?

Yes, though that's one of many things to be fixed in the system
files, and doing that and rebuilding all the saved images will take
some time (I can't recompile some myself as we don't have the
machines here, and I have not yet set up the convenient environment
used at sussex for managing one master directory with lots of
different cross links for different versions of poplog, from which
all the different versions can easily be created).

Or rather, I have the master directory tree, but have not yet copied
and checked out all the tools they used for manipulating it.

In any case I thought some people might like a simple fix that did
not require either fetching a new poplog image or rebuilding poplog
after recompiling a source file.

There are lots of things that don't work well if you have spaces in file
or directory names. e.g. ved_dired, the file browser, and
vedfilecomplete, to name but two.

So there will be lots of thought needed on how to fix all this. (I'd
hate to have to adopt the Emacs philosophy using editing "modes": one of
the things I prefer about Ved is that any mechanism can be used in any
context -- apart from one or two that I have forgotten.)

Quote:
> Of course there are going to be people, e.g., students, who aren't in a
> position to install a new system for themselves and will want to use
> your procedure in the meantime, but in the long run, a separate
> procedure for reading in files with spaces in their names would be an
> extra piece of obscure lore for the new user to trip over.

I agree. I keep saying that I want to apply to EPSRC for funds to
hire a couple of people, one at Birmingham and one somewhere else to
work on poplog for a couple of years to bring various things up to
date, clean up some of the messier features, and incorporate various
desirable extensions, including replacing the disastrous Ved "graphic"
characters (Very nice for Ved users and awful for everyone else.)

But I have been so busy with other things I have done nothing about
the grant proposal, apart from some discussions a few months ago
with Steve Leach about some of the things that need to be done...

(If someone in a UK university would like to be a co-proposer to EPSRC
that might trigger me into action! Perhaps Nottingham where Brian Logan
tells me interesting things are being done to link Poplog with a Virtual
Reality package developed there which runs on NT!)

Quote:
> The only remark I have about your procedure is that it seems to prevent
> the user from opening a new file with a space in the name.  (I haven't
> actually tried your code, just read it.)

That was because I assumed it was obvious that no sane poplog user would
ever wish to create new files with spaces in their names, only to
read/edit existing ones.

But on reflection I see I was completely wrong, for the very reason I
gave originally, i.e. there are now cross-mounted *windows* file systems
and there could be a directory with a space in its name, etc. etc.

And anyway, if an operating system allows something and users want to do
it, then no editor should be designed so as to make it impossible!

So I have modified ved_spaceved so that you can create a file with a
space in its name, including creating a new file in a directory with
a space in its name.

I have installed the new version in
    http://www.cs.bham.ac.uk/research/poplog/auto/ved_spaceved.p

and I append it below also. (Remove my signature before installing,
either in $usepop/pop/lib/auto/ or in $poplocal/local/auto/)

I added a fix in case anyone tries to use it in WinTel poplog but I
have no idea whether it will work in windows/NT. Probably not.
Nothing ever works there as I would expect...

Aaron
Revised version follows
===================================================================

/* --- Copyright University of Birmingham 2001. All rights reserved. ------
 > File:            $poplocal/local/auto/ved_spaceved.p
 > Purpose:                  Read in file whose name contains spaces
 > Author:          Aaron Sloman, May 13 2001 (see revisions)
 > Documentation:    Below for now
 > Related Files:
 */

/*

HELP ved_spaceved

    Utility to use Ved for reading in or creating files whose names
        include spaces.

    This is needed because ved_ved assumes that if its argument
    includes spaces then it refers to several files, which should
    all be read into Ved. (This will almost certainly be disabled in
        a later version of Poplog, or at least made optional.)

ENTER spaceved my silly file.p

    This command will look for a file called 'my silly file.p'
        and read it into ved for editing.

        If there is no such file, a new ved buffer will be created, which
        when written will have 'my silly file.p' as its name.

        It will also work for directories whose names contain spaces,
        e.g.
                ENTER spaceved ~/my dir/my silly file.p

WARNING: this will not use vedsearchlist, so explicit path
    names will be needed for files not in the current directory.

        It will also not find the file if it is already being edited,
        so use ESC e (vedfileselect) to return to a file previously
        edited with this command.

        The ENTER spaceved command will make ved read the file into
        a Ved buffer and in many ways it will be like an ordinary ved
    file. However, on the status line ved will show the type "workbuff"
        before the file name as a reminder that this is an unusual file.

*/

section;

define lconstant setupglobals(newfile, string);
        ;;; Set up some of the globals for the new file, to make it behave
        ;;; more or less like an ordinary file

        dlocal ved_current_file = newfile;

        sysfileok(string) -> string;

        ;;; modify this test for windows ???
#_IF hd(sys_os_type) == "unix"
        if string(1) = `/` then
#_ELSE
        ;;; see if second char in string is `:`, e.g. C:foo\baz
        if datalength(string) > 2 and string(2) == `:` then
#_ENDIF
                ;;; it's a full path name
                string ->> vedpathname -> vedcurrent;
                nullstring -> veddirectory;
        else
                ;;; it's a relative path
                current_directory dir_>< string -> vedpathname;
                current_directory -> veddirectory;
                string -> vedcurrent;
        endif;

        ;;; if not false, it will be "workbuff"!
        false -> vedfileprops;
        false -> vedchanged;
        ;;; Maybe the user should have a choice about this:
        true -> vedwriteable;

enddefine;

define ved_spaceved();
        ;;; Edit file whose name (or path) has spaces.

        ;;; Check that the file exists
        lvars filedev = readable(vedargument);
        if filedev then
                ;;; Prepare new ved file structure containing the file
                ;;; ignore first result of vedreadfile
                lvars (_, newfile) = vedreadfile(filedev, vedveddefaults, false);
        else
                ;;; need to create a new file. Check that directory exists
                lvars path = sys_fname_path(vedargument);
                unless path = nullstring or sys_file_exists(path) then
                        vederror('NO DIRECTORY: ' <> path)
                endunless;
                ;;; create new empty file
                lvars newfile = vedopen(vedargument, false);
        endif;

        setupglobals(newfile, vedargument);

        vededit(newfile);

enddefine;

endsection;

/* --- Revision History ---------------------------------------------------
--- Aaron Sloman, May 15 2001
        Altered so that it can also be used to create a new file with
        spaces in its name, or a new file in a directory whose name has spaces.

        Modified to test for `:` as second character as an indicator of
        full path name, for non-unix file systems. Needs a change for
        VMS
 */
====
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK

PAPERS: http://www.cs.bham.ac.uk/research/cogaff/
FREE TOOLS: http://www.cs.bham.ac.uk/research/poplog/freepoplog.html



Sat, 01 Nov 2003 22:15:07 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. urlretrieve a file whose name has spaces in it

2. Arrays whose index contains a space?

3. a file name with space for http

4. name-spaces and loading a file

5. Bwidget Trees : Spaces in File Names

6. file dialog doesn't work with spaces or non-list directory names

7. Printing a symbol whose name is a potential number

8. DOS File Lookup - just the file name, not the path AND file name

9. Name spaces - instantiation labels and entity names

10. Running Ved from Ved

11. Numeric-Edited in the Draft Standard (CD 1.7 w/CCP 00-100)

12. OS/2 Rexx Macro Space functions (use with RXU utility pkg)

 

 
Powered by phpBB® Forum Software