Loading ...
Sorry, an error occurred while loading the content.

Network-oriented file reading and writing

Expand Messages
  • Dr. Charles E. Campbell
    ... Hello! Ever want to vim rcp://some.host.here/some_path_to_a_file - -or- vim ftp://some.host.here/some_path_to_a_file (uses ) ??? I have got a
    Message 1 of 4 , Feb 2, 2000
    • 0 Attachment
      -----BEGIN PGP SIGNED MESSAGE-----

      Hello!

      Ever want to

      vim rcp://some.host.here/some_path_to_a_file
      - -or-
      vim ftp://some.host.here/some_path_to_a_file (uses <.netrc>)

      ???

      I have got a solution for you! Now, I haven't extensively tested it, and
      there may be gotchas with the autocmd patches that I haven't run into. It
      needs testing.

      Anyway, here's the idea: I've introduced two new autocmd events, BufReadCmd
      and BufWriteCmd. When they're triggered they *don't* actually read or write,
      but they execute associated command(s) (like any good autocmd does). It just
      so happens that with the <.vimrc> inclusion given below, that the appropriate
      Nr or Nw command gets executed, which in turn does the rcp or ftp operation
      for you.

      Enjoy!
      Dr C

      -- <.vimrc> inclusion -----------------------------------------------
      augroup Network
      au!
      au BufReadCmd rcp://* exe "Nr " . substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","0r \\1:\\2","")
      au BufReadCmd rcp://* exe "set ft=" . expand("<afile>:e")
      au BufReadCmd ftp://* exe "Nr " . substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","0r \\1 \\2","")
      au BufReadCmd ftp://* exe "set ft=" . expand("<afile>:e")
      au BufWriteCmd rcp://* exe "Nw " . substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","\\1:\\2","")
      au BufWriteCmd ftp://* exe "Nw " . substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","\\1 \\2","")
      augroup END
      ---------------------------------------------------------------------

      Get <netrw.vim> from: http://www.erols.com/astronaut/vim/vimscript/netrw.vim

      Patch: from version 5.6 tar file versions up to patch-level 11 plus my
      modifications:
      ---------------------------------------------------------------------
      *** vim.h Tue Jan 11 10:20:58 2000
      - --- nvim.h Wed Feb 2 15:45:35 2000
      ***************
      *** 598,605 ****
      - --- 598,607 ----
      EVENT_BUFNEWFILE, /* when creating a buffer for a new file */
      EVENT_BUFREADPOST, /* after reading a buffer */
      EVENT_BUFREADPRE, /* before reading a buffer */
      + EVENT_BUFREADCMD, /* read buffer using command */
      EVENT_BUFUNLOAD, /* just before unloading a buffer */
      EVENT_BUFHIDDEN, /* just after buffer becomes hidden */
      + EVENT_BUFWRITECMD, /* write buffer using command */
      EVENT_BUFWRITEPOST, /* after writing a buffer */
      EVENT_BUFWRITEPRE, /* before writing a buffer */
      EVENT_FILEAPPENDPOST, /* after appending to a file */
      *** fileio.c Wed Dec 15 07:28:21 1999
      - --- nfileio.c Wed Feb 2 15:45:46 2000
      ***************
      *** 174,180 ****
      int try_dos = (vim_strchr(p_ffs, 'd') != NULL);
      int try_unix = (vim_strchr(p_ffs, 'x') != NULL);

      - -
      #ifdef AUTOCMD
      write_no_eol_lnum = 0; /* in case it was set by the previous read */
      #endif
      - --- 174,179 ----
      ***************
      *** 192,197 ****
      - --- 191,205 ----
      curbuf->b_flags |= BF_NOTEDITED;
      }

      + #ifdef AUTOCMD
      + /*
      + * BUFREADCMDs intercept the reading process by executing the associated
      + * commands instead
      + */
      + if(!filtering && !read_stdin && apply_autocmds(EVENT_BUFREADCMD, NULL, sfname, FALSE, curbuf))
      + return OK;
      + #endif
      +
      if (shortmess(SHM_OVER) || curbuf->b_help)
      msg_scroll = FALSE; /* overwrite previous file message */
      else
      ***************
      *** 452,457 ****
      - --- 460,466 ----
      return FAIL;
      }
      }
      +
      #endif /* AUTOCMD */

      /* Autocommands may add lines to the file, need to check if it is empty */
      ***************
      *** 1181,1186 ****
      - --- 1190,1201 ----
      #ifdef UNIX
      fname = sfname;
      #endif
      + #ifdef AUTOCMD
      + if(apply_autocmds(EVENT_BUFWRITECMD, fname, fname, FALSE, curbuf))
      + {
      + return OK;
      + }
      + #endif

      /* make sure we have a valid backup extension to use */
      if (*p_bex == NUL)
      ***************
      *** 3185,3194 ****
      - --- 3200,3211 ----
      {"BufHidden", EVENT_BUFHIDDEN},
      {"BufLeave", EVENT_BUFLEAVE},
      {"BufNewFile", EVENT_BUFNEWFILE},
      + {"BufReadCmd", EVENT_BUFREADCMD},
      {"BufReadPost", EVENT_BUFREADPOST},
      {"BufReadPre", EVENT_BUFREADPRE},
      {"BufRead", EVENT_BUFREADPOST},
      {"BufUnload", EVENT_BUFUNLOAD},
      + {"BufWriteCmd", EVENT_BUFWRITECMD},
      {"BufWritePost", EVENT_BUFWRITEPOST},
      {"BufWritePre", EVENT_BUFWRITEPRE},
      {"BufWrite", EVENT_BUFWRITEPRE},
      ***************
      *** 3231,3237 ****
      NULL, NULL, NULL, NULL, NULL,
      NULL, NULL, NULL, NULL, NULL,
      NULL, NULL, NULL, NULL, NULL,
      ! NULL, NULL, NULL, NULL
      };

      /*
      - --- 3248,3255 ----
      NULL, NULL, NULL, NULL, NULL,
      NULL, NULL, NULL, NULL, NULL,
      NULL, NULL, NULL, NULL, NULL,
      ! NULL, NULL, NULL, NULL, NULL, /* cec: added 2 more NULLs */
      ! NULL
      };

      /*
      ---------------------------------------------------------------------
      - --
      Charles E Campbell, Jr, PhD _ __ __
      Goddard Space Flight Center / /_/\_\_/ /
      cec@... /_/ \/_//_/
      PGP public key: http://www.erols.com/astronaut/pgp.html/

      -----BEGIN PGP SIGNATURE-----
      Version: 2.6.2

      iQCVAwUBOJibJNgdtXCdbCHhAQFcmwP+KGGsBbC8K49YcINpZ4Alaytwtn8JMvGa
      ItLJGO7NbiOiJ1L10uzp4PS8cCg/5RUmOL5wP2iiybb1aSpoMsOiISMiOC4SN4YV
      aDPDa7/rVwFCch6V0gbvBDP0TqGM2HTL4v2yByDQW2OK/SmX6twDij++EwPfLaoz
      HLFwnXOYSmI=
      =eCkI
      -----END PGP SIGNATURE-----
    • Michael Geddes
      Hmm.. I definitely agree with the need for the BufReadCmd - just remember there is already a solution without it though. It s a bit interesting , but it
      Message 2 of 4 , Feb 2, 2000
      • 0 Attachment
        Hmm.. I definitely agree with the need for the BufReadCmd - just remember
        there is already a solution without it though.

        It's a bit "interesting", but it works quite well.

        <<ftpurm.vim>>

        This only works with ftp, but it also does some cool stuff with parsing the
        file name that you could extend to rcp.

        It will also accept ftp://username:password@host/directory/file

        as well as leaving out username and/or password.

        <<ftpurm.html>>
        I'm assuming your version of the ftp will work in NT as well??

        Why don't you try assimilating some of the ideas with your RCP script.

        //.ichael G.


        > -----Original Message-----
        > From: cec@... [SMTP:cec@...]
        > Sent: None
        > To: vim-dev@...
        > Subject: Network-oriented file reading and writing
        >
        > -----BEGIN PGP SIGNED MESSAGE-----
        >
        > Hello!
        >
        > Ever want to
        >
        > vim rcp://some.host.here/some_path_to_a_file
        > - -or-
        > vim ftp://some.host.here/some_path_to_a_file (uses <.netrc>)
        >
        > ???
        >
        > I have got a solution for you! Now, I haven't extensively tested it, and
        > there may be gotchas with the autocmd patches that I haven't run into. It
        > needs testing.
        >
        > Anyway, here's the idea: I've introduced two new autocmd events,
        > BufReadCmd
        > and BufWriteCmd. When they're triggered they *don't* actually read or
        > write,
        > but they execute associated command(s) (like any good autocmd does). It
        > just
        > so happens that with the <.vimrc> inclusion given below, that the
        > appropriate
        > Nr or Nw command gets executed, which in turn does the rcp or ftp
        > operation
        > for you.
        >
        > Enjoy!
        > Dr C
        >
        > -- <.vimrc> inclusion -----------------------------------------------
        > augroup Network
        > au!
        > au BufReadCmd rcp://* exe "Nr " .
        > substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","0
        > r \\1:\\2","")
        > au BufReadCmd rcp://* exe "set ft=" . expand("<afile>:e")
        > au BufReadCmd ftp://* exe "Nr " .
        > substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","0
        > r \\1 \\2","")
        > au BufReadCmd ftp://* exe "set ft=" . expand("<afile>:e")
        > au BufWriteCmd rcp://* exe "Nw " .
        > substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","\
        > \1:\\2","")
        > au BufWriteCmd ftp://* exe "Nw " .
        > substitute(expand("<afile>"),"rcp://\\([a-zA-Z_0-9.]\\+\\)/\\(.\\+\\)$","\
        > \1 \\2","")
        > augroup END
        > ---------------------------------------------------------------------
        >
        > Get <netrw.vim> from:
        > http://www.erols.com/astronaut/vim/vimscript/netrw.vim
        >
        > Patch: from version 5.6 tar file versions up to patch-level 11 plus my
        > modifications:
        > ---------------------------------------------------------------------
        > *** vim.h Tue Jan 11 10:20:58 2000
        > - --- nvim.h Wed Feb 2 15:45:35 2000
        > ***************
        > *** 598,605 ****
        > - --- 598,607 ----
        > EVENT_BUFNEWFILE, /* when creating a buffer for a new
        > file */
        > EVENT_BUFREADPOST, /* after reading a buffer */
        > EVENT_BUFREADPRE, /* before reading a buffer */
        > + EVENT_BUFREADCMD, /* read buffer using command */
        > EVENT_BUFUNLOAD, /* just before unloading a buffer */
        > EVENT_BUFHIDDEN, /* just after buffer becomes hidden
        > */
        > + EVENT_BUFWRITECMD, /* write buffer using command */
        > EVENT_BUFWRITEPOST, /* after writing a buffer */
        > EVENT_BUFWRITEPRE, /* before writing a buffer */
        > EVENT_FILEAPPENDPOST, /* after appending to a file */
        > *** fileio.c Wed Dec 15 07:28:21 1999
        > - --- nfileio.c Wed Feb 2 15:45:46 2000
        > ***************
        > *** 174,180 ****
        > int try_dos = (vim_strchr(p_ffs, 'd') != NULL);
        > int try_unix = (vim_strchr(p_ffs, 'x') != NULL);
        >
        > - -
        > #ifdef AUTOCMD
        > write_no_eol_lnum = 0; /* in case it was set by the previous read
        > */
        > #endif
        > - --- 174,179 ----
        > ***************
        > *** 192,197 ****
        > - --- 191,205 ----
        > curbuf->b_flags |= BF_NOTEDITED;
        > }
        >
        > + #ifdef AUTOCMD
        > + /*
        > + * BUFREADCMDs intercept the reading process by executing the
        > associated
        > + * commands instead
        > + */
        > + if(!filtering && !read_stdin && apply_autocmds(EVENT_BUFREADCMD,
        > NULL, sfname, FALSE, curbuf))
        > + return OK;
        > + #endif
        > +
        > if (shortmess(SHM_OVER) || curbuf->b_help)
        > msg_scroll = FALSE; /* overwrite previous file message */
        > else
        > ***************
        > *** 452,457 ****
        > - --- 460,466 ----
        > return FAIL;
        > }
        > }
        > +
        > #endif /* AUTOCMD */
        >
        > /* Autocommands may add lines to the file, need to check if it is
        > empty */
        > ***************
        > *** 1181,1186 ****
        > - --- 1190,1201 ----
        > #ifdef UNIX
        > fname = sfname;
        > #endif
        > + #ifdef AUTOCMD
        > + if(apply_autocmds(EVENT_BUFWRITECMD, fname, fname, FALSE, curbuf))
        > + {
        > + return OK;
        > + }
        > + #endif
        >
        > /* make sure we have a valid backup extension to use */
        > if (*p_bex == NUL)
        > ***************
        > *** 3185,3194 ****
        > - --- 3200,3211 ----
        > {"BufHidden", EVENT_BUFHIDDEN},
        > {"BufLeave", EVENT_BUFLEAVE},
        > {"BufNewFile", EVENT_BUFNEWFILE},
        > + {"BufReadCmd", EVENT_BUFREADCMD},
        > {"BufReadPost", EVENT_BUFREADPOST},
        > {"BufReadPre", EVENT_BUFREADPRE},
        > {"BufRead", EVENT_BUFREADPOST},
        > {"BufUnload", EVENT_BUFUNLOAD},
        > + {"BufWriteCmd", EVENT_BUFWRITECMD},
        > {"BufWritePost", EVENT_BUFWRITEPOST},
        > {"BufWritePre", EVENT_BUFWRITEPRE},
        > {"BufWrite", EVENT_BUFWRITEPRE},
        > ***************
        > *** 3231,3237 ****
        > NULL, NULL, NULL, NULL, NULL,
        > NULL, NULL, NULL, NULL, NULL,
        > NULL, NULL, NULL, NULL, NULL,
        > ! NULL, NULL, NULL, NULL
        > };
        >
        > /*
        > - --- 3248,3255 ----
        > NULL, NULL, NULL, NULL, NULL,
        > NULL, NULL, NULL, NULL, NULL,
        > NULL, NULL, NULL, NULL, NULL,
        > ! NULL, NULL, NULL, NULL, NULL, /* cec: added 2 more NULLs */
        > ! NULL
        > };
        >
        > /*
        > ---------------------------------------------------------------------
        > - --
        > Charles E Campbell, Jr, PhD _ __ __
        > Goddard Space Flight Center / /_/\_\_/ /
        > cec@... /_/ \/_//_/
        > PGP public key: http://www.erols.com/astronaut/pgp.html/
        >
        > -----BEGIN PGP SIGNATURE-----
        > Version: 2.6.2
        >
        > iQCVAwUBOJibJNgdtXCdbCHhAQFcmwP+KGGsBbC8K49YcINpZ4Alaytwtn8JMvGa
        > ItLJGO7NbiOiJ1L10uzp4PS8cCg/5RUmOL5wP2iiybb1aSpoMsOiISMiOC4SN4YV
        > aDPDa7/rVwFCch6V0gbvBDP0TqGM2HTL4v2yByDQW2OK/SmX6twDij++EwPfLaoz
        > HLFwnXOYSmI=
        > =eCkI
        > -----END PGP SIGNATURE-----
      • raf
        ... excellent. these autocmds will make net-vimming much cleaner. what about scp, sftp, socksified-ftp, ... ? how extensible is netrw.vim? raf
        Message 3 of 4 , Feb 2, 2000
        • 0 Attachment
          Dr. Charles E. Campbell wrote:

          > Ever want to
          >
          > vim rcp://some.host.here/some_path_to_a_file
          > - -or-
          > vim ftp://some.host.here/some_path_to_a_file (uses <.netrc>)
          >
          > ???
          >
          > I have got a solution for you! Now, I haven't extensively tested it, and
          > there may be gotchas with the autocmd patches that I haven't run into. It
          > needs testing.
          >
          > Anyway, here's the idea: I've introduced two new autocmd events, BufReadCmd
          > and BufWriteCmd. When they're triggered they *don't* actually read or write,
          > but they execute associated command(s) (like any good autocmd does). It just
          > so happens that with the <.vimrc> inclusion given below, that the appropriate
          > Nr or Nw command gets executed, which in turn does the rcp or ftp operation
          > for you.

          excellent. these autocmds will make net-vimming much cleaner.

          what about scp, sftp, socksified-ftp, ... ?
          how extensible is netrw.vim?

          raf
        • Bram Moolenaar
          ... Nice idea. I wonder if a more generic solution would be possible. Suppose the pattern for the autocommand is not enough to decide if the text should be
          Message 4 of 4 , Feb 6, 2000
          • 0 Attachment
            Charles Campbell wrote:

            > Anyway, here's the idea: I've introduced two new autocmd events, BufReadCmd
            > and BufWriteCmd. When they're triggered they *don't* actually read or write,
            > but they execute associated command(s) (like any good autocmd does). It just
            > so happens that with the <.vimrc> inclusion given below, that the appropriate
            > Nr or Nw command gets executed, which in turn does the rcp or ftp operation
            > for you.

            Nice idea. I wonder if a more generic solution would be possible. Suppose
            the pattern for the autocommand is not enough to decide if the text should be
            read from a file or obtained with a command. Perhaps a global variable need
            to be checked. Some script would be needed to decide what to do:

            au BufReadPre <pattern> call GetText()

            fun GetText()
            if <some_condition>
            <get text with command>
            <prevent reading text from file>
            endif
            endfun

            In the situation that the text is read with a command, there needs to be some
            way to prevent the file-read action to take place. Since autocommands may
            nest, this is a bit tricky.

            --
            BEDEVERE: Oooooh!
            LAUNCELOT: No "Aaaaarrrrrrggghhh ... " at the back of the throat.
            BEDEVERE: No! "Oooooh!" in surprise and alarm!
            "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

            /-/-- Bram Moolenaar --- Bram@... --- http://www.moolenaar.net --\-\
            \ \ Vim: http://www.vim.org ICCF Holland: http://www.vim.org/iccf / /
          Your message has been successfully submitted and would be delivered to recipients shortly.