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

52321Loading Multiple syntax files (suggestion) & alternate colorisation

Expand Messages
  • Michael Geddes
    Aug 9, 2004
      Hi all

      This is a bit long- but it should be worth the read <<syntax.zip>>

      I have recently been tidying up two files which are effectively 'syntax
      extensions' - ie they go on top of a main syntax file.

      For those who know, this is my doxygen.vim and ifdef.vim scripts
      (avilable on vim.sf.net).

      Currently vim doesn't really have this concept. Sure, you can add it
      to your after/syntax scripts, but that's only half the story.

      I have come up with a simple scheme (imlemented in synload.vim) that
      adds the ability to have multi-part syntaxes ie a syntax of the form:
      'c.doxygen' or 'java.doxygen' or 'cpp.doxygen.ifdef' where
      each of the sections would be loaded using runtime syntax/{bit}.vim -

      ie
      set syntax=cpp.extras.doxygen
      would cause
      runtime! syntax/cpp.vim
      runtime! syntax/extras.vim
      runtime! syntax/doxygen.vim
      to be executed. This is useful for modelines. Ie you could have /*
      vim:syntax=cpp.doxygen */ in your modeline.

      As an alternative, you could specify global extensions for specified
      syntaxes with variables of the form
      syntax_extra_{filetype}={extrasyntax}.
      To take the example used above, a similar effect could be caused by the
      following line in your .vimrc:
      let g:syntax_extra_cpp='extras.doxygen'
      So that when you load a 'cpp' file, you also get extras and doxygen
      hilighting as well.

      Part 2 of this is support for alternate colorisation - for syntax
      scripts that do better with non-standard colors (doxygen.vim)

      I have additions to syncolor.vim and synload.vim that will allow the
      alternate scripts to detect changes between light and dark background.
      This uses special Syntax autocomands (which are ignored by s:SynSet() in
      synload.vim ) :
      au Syntax UserColor_on
      au Syntax UserColor_enable
      au Syntax UserColor_reset

      I have attached a zip file including the modified synload.vim,
      syncolor.vim - as well as the new and improved doxygen.vim and
      ifdef.vim.

      Unzip these into your .vim/ or vimfiles/ directory, open up vim with a
      cpp/c file - or use the following file:
      (you may wish to aslo 'let doxygen_enhanced_colour=1' if you have a gui
      vim)

      ---------8<---------------------------test.hpp ---------------------

      // vim: syntax=cpp.doxygen.ifdef
      // vim_ifdef:undefine=LATER
      // vim_ifdef:define=WIN32

      /** Class to do stuff.
      * Requires things.
      */
      clas Stuff
      {
      /// Constructor
      Stuff();

      /** Do stuff.
      * \param option An option.
      */
      doStuff()
      {
      #ifdef LATER
      unimplemented_function();
      // Doesn't do anything
      #endif

      #ifdef WIN32
      // Do windows stuff
      WinAPICall();
      #else
      // Otherwise
      UseSomeotherCall();
      #endif // WIN32
      }
      };

      ------8<----------------
      Now try
      :colorscheme elflord
      and
      :colorscheme default


      I'll leave the other stuff up to the user.

      //.ichael G.
    • Show all 5 messages in this topic