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

Conditionally sourcing a file based on sub-filetype

Expand Messages
  • Daniel Einspanjer
    I ve started using closetag.vim, and I like it a lot. I m looking for an easy way to automatically source it when editing a compatible file. This would
    Message 1 of 3 , Aug 1, 2001
    • 0 Attachment
      I've started using closetag.vim, and I like it a lot. I'm looking for an easy
      way to automatically source it when editing a compatible file. This would
      include html, xml, asp, jsp, php, etc.

      My problem is this:
      If I edit a jsp file, the jsp syntax file automatically sources the html
      syntax. main_syntax is defined as jsp, but no variable is stored stating that
      this file is also html (kind of like a sub-filetype). I could modify html.vim
      to automatically source closetag.vim, but it doesn't seem like a good practice
      because when I upgrade to the next version, html.vim would be gone unless I
      specifically remember to copy it over (and possibly merge any conflicts). I
      believe this is what the $VIM/vimfiles/ directory was made for. To give you a
      common place to put *your* files that are version independent. I could add
      code to my vimrc file to source closetag.vim, but then I'd have to keep a long
      list of all the different syntaxes that it works with, instead of relying on
      the inclusion code already contained in the html.vim sourcing code path.

      Am I missing an easy way to do this?

      -- Daniel Einspanjer, daniel@... on 08/01/2001
    • Daniel Einspanjer
      Did anyone ever have any input on this? -- Daniel Einspanjer, daniel-ml@yipyip.com on 08/13/2001
      Message 2 of 3 , Aug 13, 2001
      • 0 Attachment
        Did anyone ever have any input on this?
        -- Daniel Einspanjer, daniel-ml@... on 08/13/2001


        On Wed, 1 Aug 2001 16:27:02 -0400, Daniel Einspanjer wrote:
        >I've started using closetag.vim, and I like it a lot. I'm looking for an easy
        >way to automatically source it when editing a compatible file. This would
        >include html, xml, asp, jsp, php, etc.
        >
        >My problem is this:
        >If I edit a jsp file, the jsp syntax file automatically sources the html
        >syntax. main_syntax is defined as jsp, but no variable is stored stating that
        >this file is also html (kind of like a sub-filetype). I could modify html.vim
        >to automatically source closetag.vim, but it doesn't seem like a good practice
        >because when I upgrade to the next version, html.vim would be gone unless I
        >specifically remember to copy it over (and possibly merge any conflicts). I
        >believe this is what the $VIM/vimfiles/ directory was made for. To give you a
        >common place to put *your* files that are version independent. I could add
        >code to my vimrc file to source closetag.vim, but then I'd have to keep a long
        >list of all the different syntaxes that it works with, instead of relying on
        >the inclusion code already contained in the html.vim sourcing code path.
        >
        >Am I missing an easy way to do this?
        >
        >-- Daniel Einspanjer, daniel@... on 08/01/2001
        >
        >
        >
      • Dan Sharp
        ... Unfortunately, I don t think there is a quick and easy way to do this with the existing files. The correct way would be to create ftplugins. You could
        Message 3 of 3 , Aug 13, 2001
        • 0 Attachment
          At 03:23 PM 8/13/2001 -0400, Daniel Einspanjer wrote:
          >Did anyone ever have any input on this?
          >
          >On Wed, 1 Aug 2001 16:27:02 -0400, Daniel Einspanjer wrote:
          > >I've started using closetag.vim, and I like it a lot. I'm looking for
          > an easy
          > >way to automatically source it when editing a compatible file. This would
          > >include html, xml, asp, jsp, php, etc.
          > >
          > >My problem is this:
          > >If I edit a jsp file, the jsp syntax file automatically sources the html
          > >syntax. main_syntax is defined as jsp, but no variable is stored
          > stating that
          > >this file is also html (kind of like a sub-filetype). I could modify
          > html.vim
          > >to automatically source closetag.vim, but it doesn't seem like a good
          > practice
          > >because when I upgrade to the next version, html.vim would be gone unless I
          > >specifically remember to copy it over (and possibly merge any conflicts). I
          > >believe this is what the $VIM/vimfiles/ directory was made for. To give
          > you a
          > >common place to put *your* files that are version independent. I could add
          > >code to my vimrc file to source closetag.vim, but then I'd have to keep
          > a long
          > >list of all the different syntaxes that it works with, instead of relying on
          > >the inclusion code already contained in the html.vim sourcing code path.
          > >
          > >Am I missing an easy way to do this?

          Unfortunately, I don't think there is a quick and easy way to do this with
          the existing files. The correct way would be to create ftplugins. You
          could create an ftplugin/html.vim that sources closetag.vim and it would
          get loaded automatically for HTML files. Then you would create an
          ftplugin/jsp.vim that includes

          runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim

          so that all the HTML plugins get loaded as well, similarly to doing
          runtime! syntax/html.vim in the jsp syntax file. You would put the same
          sort of line in each ftplugin that also should have access to the HTML
          plugins. You *could* create a $VIM/vimfiles/syntax/after/html.vim that
          would get loaded after the distribution's syntax/html.vim, and put your
          "source closetags.vim" in there, but I wouldn't recommend it. I think
          functions like sourcing closetags.vim belong in the ftplugin group and
          should be independent of syntax highlighting. Since $VIM/vimfiles is your
          personal directory, though, you can do whatever you want :)

          Another option, though probably not what you want, it to modify
          filetype.vim so that when it detects the filetype of the file, it creates a
          variable listing the "associated" filetypes (like for jsp, the associated
          filetypes would be java and html). That would serve as sort of a master
          list of what should be included for that filetype. Then, both the syntax
          files and the ftplugin files could have access to the associated filetypes
          variable and could parse it to load the related syntax files and
          ftplugins. This is probbaly a little too complex, though, and would
          require redoing quite a bit of the existing files.

          Dan Sharp
        Your message has been successfully submitted and would be delivered to recipients shortly.