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

make vim quiet as filter

Expand Messages
  • marc chantreux
    Hi all, I want to use vim to colorize sample codes on my site, so i wrote those lines : % cat go.vim set nocompatible syntax on silent edit a.sed let
    Message 1 of 3 , Mar 31, 2005
    • 0 Attachment
      Hi all,

      I want to use vim to colorize sample codes on my site, so i wrote those
      lines :

      % cat go.vim
      set nocompatible
      syntax on
      silent edit a.sed
      let html_use_css='yes'
      silent source $VIMRUNTIME/syntax/2html.vim
      norm gg
      " redir! > AA
      /^<pre>/+1,/<\/pre>/-1p
      " redir END
      qa!

      so, in my m4 file :

      m4_esyscmd( vim -u go.vim )

      it works fine but i have an error message :

      Vim: Warning: Output is not to a terminal

      is there a way to tell to vim that's all right ?

      regards

      mc
    • François Pinard
      [marc chantreux] ... Thanks for providing these, they hint me at studying some details a bi more deeply. :-) ... I do not know if the following fragment of
      Message 2 of 3 , Mar 31, 2005
      • 0 Attachment
        [marc chantreux]

        > I want to use vim to colorize sample codes on my site, so i wrote
        > those lines [...]

        Thanks for providing these, they hint me at studying some
        details a bi more deeply. :-)

        > it works fine but i have an error message : [...]
        > is there a way to tell to vim that's all right ?

        I do not know if the following fragment of code is any useful to you,
        I blindly extract it from a bigger script. It produces the body of an
        HTML page batch-produced by Vim, in the context of highlighting source
        code on my Web site.

        def html_body_data_through_vim(self):
        fragments = []
        write = fragments.append
        import tempfile
        work = tempfile.mktemp()
        # `-u NONE' ne fonctionne pas.
        command = ('vim -fNn -u /dev/null >/dev/null 2>/dev/null'
        ' -c \'set background=light\' -c \'syntax on\''
        ' -c TOhtml -c \'wq! %s\' -c q %s'
        % (work, os.path.join(self.top, self.name)))
        os.system(command)
        before = True
        for line in file(work):
        if before:
        if line != '<pre>\n':
        continue
        before = False
        write(line)
        if line == '</pre>\n':
        break
        os.remove(work)
        return ''.join(fragments)

        This is Python however, not m4. Just my preference of the day, I've
        nothing against m4 :-). (I maintained René Seindal's GNU m4 for many
        years, this was one of the nicest source code I had to play with.)

        --
        François Pinard http://pinard.progiciels-bpi.ca
      • Marc Chantreux
        ... So let see all the lines : 1. Makefile: # sources is a repository for my sources SRCS=$(wildcard sources/*) # i store temporary html chunks into
        Message 3 of 3 , Mar 31, 2005
        • 0 Attachment
          >
          >Thanks for providing these, they hint me at studying some
          >details a bi more deeply. :-)
          >
          >

          So let see all the lines :
          1. Makefile:
          # sources is a repository for my sources
          SRCS=$(wildcard sources/*)


          # i store temporary html chunks into htmlchunks/
          # every source has its chunk

          CHUNKDIR=htmlchunks
          HTMLCHUNKS=$(addprefix $(CHUNKDIR)/,$(notdir $(SRCS)))

          all: $(HTMLCHUNKS)

          $(HTMLCHUNKS) : source2chunks.vim

          # do not remove partfiles
          # its timestamp is important for make

          source2chunks.vim: $(SRCS)
          @echo generating blocs $?
          @./vimsyn2html.sh $(CHUNKDIR) $? > $@
          @echo still alive
          vi --noplugin -fNnu $@ 2>/dev/null

          clean:
          rm *part source2chunks.vim

          2. vimsyn2html.sh# generate a vim script to create html chunks that that
          are syn highlight
          # for sourcecode

          dest=$1
          shift


          # initialize vim
          # set background=light can be usefull to see default syn
          # set nocompatible if not -N

          cat << START
          syntax on
          let html_use_css='yes'
          START

          # for every source code ....

          for src in $@; do

          # open and htmlize it !
          echo edit $src
          echo source $VIMRUNTIME/syntax/2html.vim

          # at the end of 2html, the current buffer is the html page
          # the code itself is between a ^<pre> and a ^</pre>
          # we just write it in another file :-)

          echo '/^<pre>/+1,/<\/pre>/-1w '$dest/${src##*/}

          # then we delete the code and html buffers ( without quit vim)
          echo 'bd!'
          echo 'bd!'
          done

          # it will be back ....
          echo 'wqa!'

          That's all ... note that vim is called only one time for all the files,
          i think this
          can speed up file generation.

          >
          >I do not know if the following fragment of code is any useful to you,
          >I blindly extract it from a bigger script. It produces the body of an
          >HTML page batch-produced by Vim, in the context of highlighting source
          >code on my Web site.
          >
          >
          no help here ... just tips to speed more with -fn

          >This is Python however, not m4. Just my preference of the day, I've
          >nothing against m4 :-). (I maintained René Seindal's GNU m4 for many
          >years, this was one of the nicest source code I had to play with.)
          >
          >
          >
          I've produced m4 example because it's a well known tool but in fact, i'm
          using template-toolkit.
          http://template-toolkit.org It's an amazing tool i use every day !

          regards
          mc
        Your message has been successfully submitted and would be delivered to recipients shortly.