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

Re: vim counterpart for persistent includes

Expand Messages
  • Tim Chase
    ... I don t know of anything pre-existing, but I whipped up this ... fname=matchstr(getline( . ),
    Message 1 of 6 , Apr 1, 2011
    • 0 Attachment
      On 04/01/2011 10:48 AM, Tim Gray wrote:
      > I'm a new user of vim and am currently evaluating it for my uses. I'm coming
      > from BBEdit. One of the features of BBEdit that I've found useful is the
      > 'persistent include.'* It's mostly used for HTML. The idea behind it is that
      > you can specify a file in an HTML comment, and when you 'update' the document,
      > the file's contents are included in your HTML document, between the persistent
      > include comments. It looks like this:
      >
      > <!-- #bbinclude "filename" -->
      > file contents that are inlined.
      > <!-- end bbinclude -->
      >
      > *Only* the lines in between the include comments are replaced with included
      > file. If the included file changes and you update the main file again, the
      > contents are updated. The real power of this comes from when the included
      > file is a shell script, which you can pass options too.
      >
      > Sorry for the long winded description. My question is this: Is there
      > functionality in vim for something like this? If not, is there a pre-existing
      > script that replicates this?

      I don't know of anything pre-existing, but I whipped up this
      which reads in the file:

      :g/<!-- #bbinclude "[^"]*" -->\_.\{-}<!-- end bbinclude -->/let
      fname=matchstr(getline('.'),'<!-- #bbinclude "\zs[^"]*\ze"
      -->')|exec '+,/<!-- end bbinclude -->/-!cat '.fnameescape(fname)

      or, if you want to exec it as a script

      :g/<!-- #bbinclude "[^"]*" -->\_.\{-}<!-- end bbinclude -->/let
      fname=matchstr(getline('.'),'<!-- #bbinclude "\zs[^"]*\ze"
      -->')|exec '+,/<!-- end bbinclude -->/-!'.fnameescape(fname)


      It's pretty rigid on the tag-formatting (exact-matches, spacing
      matters, etc), but the regexps can be tweaked to be more
      permissive. You can also tweak it if you want for alternate tags
      ("<!-- #viminclude ... -->").

      You don't mention how these replacements are triggered (it might
      have been in the bbedit website)...on-read? on a key-press?
      on-write? These can be set up with an autocmd or mapping
      depending on what you want.

      -tim




      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Tim Gray
      ... Wow, thanks! I ll see if it suits my needs. ... It s triggered from a menu/key-combination. Nothing automatic. One of the reasons I m thinking of moving
      Message 2 of 6 , Apr 1, 2011
      • 0 Attachment
        On Apr 01, 2011 at 06:27 PM -0500, Tim Chase wrote:
        >I don't know of anything pre-existing, but I whipped up this which
        >reads in the file:

        Wow, thanks! I'll see if it suits my needs.

        >You don't mention how these replacements are triggered (it might have
        >been in the bbedit website)...on-read? on a key-press? on-write?
        >These can be set up with an autocmd or mapping depending on what you
        >want.

        It's triggered from a menu/key-combination. Nothing automatic. One of the
        reasons I'm thinking of moving away from BBEdit is that vim is so much more
        configurable and scriptable.

        Thanks again!

        Tim

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Marc Weber
        ... This only seems to be useful to me until you learn a proper programming language / template engine. If you can t find a plugin for that yet you can script
        Message 3 of 6 , Apr 2, 2011
        • 0 Attachment
          Excerpts from Tim Gray's message of Fri Apr 01 17:48:11 +0200 2011:
          > <!-- #bbinclude "filename" -->
          > file contents that are inlined.
          > <!-- end bbinclude -->
          This only seems to be useful to me until you learn a proper programming
          language / template engine.

          If you can't find a plugin for that yet you can script it up easily eg
          using

          a) getlines (get all lines in a buffer)
          b) readfile, writefile
          c) matchstr (get part of a string using a regex)


          everything else is like iterating over a list of lines:

          let idx=0
          let new_lines = []
          while idx < len(lines)

          endwhile

          and appending lines to this list:

          call add(new_lines, single line)

          let new_lines += list_to_append

          So even if it does not exist yet it can be done using maybe 10 lines of
          VimL code easily.

          And if this doesn't work - you can still use any scripting language.

          Marc Weber

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Tim Gray
          ... For the most part I don t find it necessary, but every once in a while, it can save a lot of time. Particularly in helping to maintain older pages (who
          Message 4 of 6 , Apr 2, 2011
          • 0 Attachment
            On Apr 02, 2011 at 11:07 AM +0200, Marc Weber wrote:
            >This only seems to be useful to me until you learn a proper programming
            >language / template engine.

            For the most part I don't find it necessary, but every once in a while, it can
            save a lot of time. Particularly in helping to maintain older pages (who
            might be also maintained by others with wildly varying knowledge levels).
            It's a nice way to enable some automation on a page with out upping the
            requirements for anyone else.

            >If you can't find a plugin for that yet you can script it up easily eg
            >VimL code easily.

            Thanks for the example! VimL is pretty new to me so it's nice to see some
            examples spelled out for me. In this case though it will probably be easiest
            to just write a little python script to take care of things. I just figured
            I'd ask to see if there was anything preexisting.

            Tim

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Mikolaj Machowski
            ... http://www.vim.org/scripts/script.php?script_id=1078 Maybe this can be helpful. m. -- You received this message from the vim_use maillist. Do not
            Message 5 of 6 , Apr 4, 2011
            • 0 Attachment
              On Friday 01 of April 2011 17:48:11 Tim Gray wrote:
              > I'm a new user of vim and am currently evaluating it for my uses. I'm
              > coming from BBEdit. One of the features of BBEdit that I've found useful
              > is the 'persistent include.'* It's mostly used for HTML. The idea behind
              > it is that you can specify a file in an HTML comment, and when you
              > 'update' the document, the file's contents are included in your HTML
              > document, between the persistent include comments. It looks like this:
              >
              > <!-- #bbinclude "filename" -->
              > file contents that are inlined.
              > <!-- end bbinclude -->
              >
              http://www.vim.org/scripts/script.php?script_id=1078

              Maybe this can be helpful.

              m.

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            Your message has been successfully submitted and would be delivered to recipients shortly.