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

Re: Hey everyone! Two pathces to syntax files.

Expand Messages
  • Mark Manning
    ... No - I want HTM files treated as HTML files like they are supposed to be treated. But PHP code can reside within HTML files. My change allows HTML files
    Message 1 of 10 , Sep 28, 2009
      Peter Hodge wrote:
      --- On Fri, 25/9/09, Mark Manning <markem@...> wrote:
      From: Mark Manning <markem@...>
      Subject: Re: Hey everyone! Two pathces to syntax files.
      To: vim_dev@...
      Received: Friday, 25 September, 2009, 11:02 PM
      So to put this in to perspective - the PHP code does
      generate HTML code
      (or just data) and that is inserted into the HTML
      code.  I'm just using
      the ".htm" extension so Dreamweaver will display
      it properly as well
      and allow me to change things in it.  This is why I
      made the change. 
      Now the PHP.vim file correctly does the coloration even if
      the source
      code is in an HTML file.  Which it wasn't doing
      before for me.
      If you just wanted to have .htm files treated as PHP files, all you need to do is add filetype detection in your .vimrc:
          autocmd! filetypedetect *.htm setfiletype php
      No - I want HTM files treated as HTML files like they are supposed to be treated.  But PHP code can reside within HTML files.  My change allows HTML files to act like HTML files but it also makes the PHP within it act like PHP code.  There is a difference.  :-)

      PHP code, whether it is contained within HTML, VBScript, C/C++, COBOL, FORTRAN, or any other language should still look like PHP code when viewed within VIM.  Mine was all green, red, and other colors  associated with some other language's color scheme.  My simple change makes that go away and instead I now see the PHP code like it should be seen (as well the HTML, VBScript, et al).  The HTML.vim file did not add in the PHP code because the PHP code adds in the HTML.vim syntax file.  Thus causing a circular reference.  By adding in the little bit of code I have to the PHP.vim and HTML.vim files the circular reference is short circuited and the PHP.vim file can now be safely added to the HTML.vim file.  So now, if you happen to have an HTML file that contains PHP code - you see it properly syntax highlighted.  More importantly - you also still see the HTML file properly highlighted even if you do not have PHP included in your HTML file.

      Something else to consider is that your proposed change would require VIM to carry around the overhead of PHP.vim no matter what.  So even if all I have is a simple web page I would still be carrying around all of the PHP.vim commands.  My changes though, only come into effect if/when there is PHP contained within the HTML file.  If VIM detects the "<?php", "<script language='php'>", or the new "<%=" tag - it adds in the PHP.vim file so it can be used.  Otherwise (at least I believe that is what is happening) it does not add it in.  I could be wrong on that though.  I'm not a perfect programmer.  :-P  Still, I don't think we should commit all of HTML to be moved under the banner of PHP anymore than it should be moved under the Javascript, VBScript, or any other script that is out there other than HTML.vim.  Which, HTML.vim already loads in for Javascript and VBscript.  So why not PHP?  (Or Perl - or whatever other language someone wants to use.  VIM is smart enough to know when to load in the other syntax files.  It just wasn't smart enough to know that it had already done so once and should not do so again.  Which is what I found out and wrote some simple code to deal with that problem.)

      I believe it is a good set of patches (at least, I like to see my PHP code correctly highlighted).  Do you have a problem with what I submitted?  If so, could you post why?  If you have a valid reason for not wanting the change - then I see no reason for you to change the code.  But if you do not have a valid reason then I think you should add in the change so others might enjoy the benefit of being able to see their PHP code highlighted properly.  :-)


      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php

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