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

syntax highlighting question

Expand Messages
  • Kartik Agaram
    Lisp symbols can usually contain : , but I m using a dialect where : is special syntax. I d like to highlight it like parens. A) My first attempt was the
    Message 1 of 7 , May 23, 2012
      Lisp symbols can usually contain ':', but I'm using a dialect where
      ':' is special syntax. I'd like to highlight it like parens.


      A) My first attempt was the following:

      au BufReadPost *.lisp syntax match Delimiter /:/

      (The autocmd is to apply this after any other settings.)

      This works on the following file x.lisp:

      abc:def

      The ':' is highlighted as expected.


      B) However, it doesn't work inside lists:

      (abc:def)

      Now the ':' isn't highlighted.

      I used this awesome tip to see what was going on:
      http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor.
      Position cursor on the unhighlighted ':', hit <F10> and it shows me
      that it thinks the ':' belongs to lispSymbol.

      So I dug into the definition of lispSymbol and updated it to not include ':'

      au BufReadPost *.lisp syn clear lispSymbol
      au BufReadPost *.lisp syn match lispSymbol contained ![^()'`,"; \t:]\+!


      C) Still no dice. <F10> now shows ':' inside lists to be of type
      lispList. Turns out I need to tell vim that lispList can contain
      Delimiters:
      au BufReadPost *.lisp syn cluster lispListCluster add=Delimiter

      It works!


      D) Now I want to make sure a leading ':' at the start of a symbol *is*
      treated as part of the symbol. So we only highlight ':' in the middle
      or end of a word.

      au BufReadPost *.lisp syn match Delimiter /[^ ]\zs:/

      But this again doesn't work inside lists. <F10> shows the ':' is
      considered part of lispList just as before I made change (C).

      Anybody have any ideas on why? I've attached both the test vimrc and
      test x.lisp file. I'm using vim 7.3 and have tested it with the latest
      runtime files.

      --
      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
    • Ben Schmidt
      ... I tried this (I changed the way autocommands were handled so I could easily source the file multiple times while testing): augroup Test au! au BufReadPost
      Message 2 of 7 , Jun 18, 2012
        On 24/05/12 9:29 AM, Kartik Agaram wrote:
        > Lisp symbols can usually contain ':', but I'm using a dialect where
        > ':' is special syntax. I'd like to highlight it like parens.
        >
        >
        > A) My first attempt was the following:
        >
        > au BufReadPost *.lisp syntax match Delimiter /:/
        >
        > (The autocmd is to apply this after any other settings.)
        >
        > This works on the following file x.lisp:
        >
        > abc:def
        >
        > The ':' is highlighted as expected.
        >
        >
        > B) However, it doesn't work inside lists:
        >
        > (abc:def)
        >
        > Now the ':' isn't highlighted.
        >
        > I used this awesome tip to see what was going on:
        > http://vim.wikia.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor.
        > Position cursor on the unhighlighted ':', hit<F10> and it shows me
        > that it thinks the ':' belongs to lispSymbol.
        >
        > So I dug into the definition of lispSymbol and updated it to not include ':'
        >
        > au BufReadPost *.lisp syn clear lispSymbol
        > au BufReadPost *.lisp syn match lispSymbol contained ![^()'`,"; \t:]\+!
        >
        >
        > C) Still no dice.<F10> now shows ':' inside lists to be of type
        > lispList. Turns out I need to tell vim that lispList can contain
        > Delimiters:
        > au BufReadPost *.lisp syn cluster lispListCluster add=Delimiter
        >
        > It works!
        >
        >
        > D) Now I want to make sure a leading ':' at the start of a symbol *is*
        > treated as part of the symbol. So we only highlight ':' in the middle
        > or end of a word.
        >
        > au BufReadPost *.lisp syn match Delimiter /[^ ]\zs:/
        >
        > But this again doesn't work inside lists.<F10> shows the ':' is
        > considered part of lispList just as before I made change (C).
        >
        > Anybody have any ideas on why? I've attached both the test vimrc and
        > test x.lisp file. I'm using vim 7.3 and have tested it with the latest
        > runtime files.

        I tried this (I changed the way autocommands were handled so I could
        easily source the file multiple times while testing):

        augroup Test
        au!
        au BufReadPost *.lisp call MyLispModifications()
        augroup END
        func! MyLispModifications()
        syn clear lispSymbol
        syn match lispSymbol contained !:\?[^()'`,"; \t:]\+!
        syn match Delimiter /\(\<\)\@!:/
        syn cluster lispListCluster add=Delimiter
        endfunc

        Note that the ordering of the syn commands is important.

        The combination of optionally including : in a symbol, and not
        recognising it as a delimiter at the beginning of a word seems to do the
        trick for me.

        Ben.



        --
        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
      • Peter Miller
        hi all, i gather from the lack of response that my previous question has no feasible answer. anyway, i have updated the question a bit to give some other
        Message 3 of 7 , Jul 31, 2012
          hi all,

          i gather from the lack of response that my previous question has no feasible answer. anyway, i have updated the question a bit to give some other possible ways of solving the problem. any pointers in the right direction would be much appreciated. i am pretty competent with vim but i have little to no vim scripting. then again i am a quick learner and very eager haha...

          here is the updated question: http://stackoverflow.com/questions/11661614/vim-php-javascriptinstrings-option


          I noticed that the syntax/php.vim file on my ubuntu machine has a php_htmlInStrings option. I can turn this option on to display HTML syntax highlighting within strings in my php files, which is great. I would also like to do javascript syntax highlighting within strings in a php file. Does anybody know if this can be done and if so how can I do it?

          edited - added extra possibilities

          I should also mention that I would be happy with a solution where i have to parse all my javascript strings though a php function before outputting the result. This might get around the problem suggested by connor below where vim has trouble deciding if the string contains javascript. for example:

          $js = "some regular text which is not javascript##now vim has
          detected that this part is javscript##back to regular text"
          ;
          parse
          ($js);
          function parse($str)
          {
             
          return str_replace('##', '', $str);
          }

          The reason I would be happy to do this is because I will probably be incorporating a html/css/js variable minifier into my project which will be doing substitutions on strings anyway.

          Of course if there is a vim-specific equivalent character for ## which will not show up in the source code and would not need to be filtered out then this would be preferable...


          --
          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
        • Tony Mechelynck
          ... I don t see your previous question anywhere in this vim_use list (maybe I didn t scroll far enough up) but no answer to a question sent to this list
          Message 4 of 7 , Aug 1, 2012
            On 01/08/12 08:08, Peter Miller wrote:
            > hi all,
            >
            > i gather from the lack of response that my previous question has no
            > feasible answer. anyway, i have updated the question a bit to give some
            > other possible ways of solving the problem. any pointers in the right
            > direction would be much appreciated. i am pretty competent with vim but
            > i have little to no vim scripting. then again i am a quick learner and
            > very eager haha...

            I don't see your previous question anywhere in this "vim_use" list
            (maybe I didn't scroll far enough up) but no answer to a question sent
            to this list usually just means that no one knowing the answer saw your
            question. If someone sees your question and knows that there is no
            feasible answer (s)he will tell you so.

            >
            > here is the updated question:
            > http://stackoverflow.com/questions/11661614/vim-php-javascriptinstrings-option
            >
            >
            > I noticed that the syntax/php.vim file on my ubuntu machine has a
            > |php_htmlInStrings| option. I can turn this option on to display HTML
            > syntax highlighting within strings in my php files, which is great. I
            > would also like to do javascript syntax highlighting within strings in a
            > php file. Does anybody know if this can be done and if so how can I do it?
            >
            > *edited - added extra possibilities*
            >
            > I should also mention that I would be happy with a solution where i have
            > to parse all my javascript strings though a php function before
            > outputting the result. This might get around the problem suggested by
            > connor below where vim has trouble deciding if the string contains
            > javascript. for example:
            >
            > |$js= "some regular text which is not javascript##now vim has
            > detected that this part is javscript##back to regular text";
            >
            > parse($js);
            > function parse($str)
            >
            > {
            > return str_replace('##', '', $str);
            >
            > }
            > |
            >
            > The reason I would be happy to do this is because I will probably be
            > incorporating a html/css/js variable minifier into my project which will
            > be doing substitutions on strings anyway.
            >
            > Of course if there is a vim-specific equivalent character for |##| which
            > will not show up in the source code and would not need to be filtered
            > out then this would be preferable...



            I don't know… but maybe someone else will…


            Best regards,
            Tony.
            --
            There is no substitute for good manners, except, perhaps, fast
            reflexes.

            --
            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
          • Ben Schmidt
            ... You may yet get an answer. I don t think it s impossible to do javascript in strings, but it is a little tricky. It s the sort of area we delve into
            Message 5 of 7 , Aug 1, 2012
              On 1/08/12 4:08 PM, Peter Miller wrote:
              > i gather from the lack of response that my previous question has no
              > feasible answer.

              You may yet get an answer. I don't think it's impossible to do
              javascript in strings, but it is a little tricky. It's the sort of area
              we delve into relatively rarely, and indeed, relatively few of us go
              there at all. Formulating a truly useful response will take more time
              than other questions. Give it a little while to brew and someone still
              might answer (myself included).

              Ben.



              > I noticed that the syntax/php.vim file on my ubuntu machine has a
              > |php_htmlInStrings| option. I can turn this option on to display HTML syntax
              > highlighting within strings in my php files, which is great. I would also like to
              > do javascript syntax highlighting within strings in a php file. Does anybody know
              > if this can be done and if so how can I do it?

              --
              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
            • Ben Fritz
              ... I personally passed up the question because I don t know of a way that is already built into the php syntax script but maybe one exists. It s possible to
              Message 6 of 7 , Aug 1, 2012
                On Wednesday, August 1, 2012 1:08:35 AM UTC-5, mulllhausen wrote:
                > hi all,
                >
                > i gather from the lack of response that my previous question has no feasible answer. anyway, i have updated the question a bit to give some other possible ways of solving the problem. any pointers in the right direction would be much appreciated. i am pretty competent with vim but i have little to no vim scripting. then again i am a quick learner and very eager haha...
                >
                >
                > here is the updated question: http://stackoverflow.com/questions/11661614/vim-php-javascriptinstrings-option
                >
                >
                >
                >
                >
                >
                >
                > I noticed that the syntax/php.vim file on my ubuntu machine has a php_htmlInStrings
                > option. I can turn this option on to display HTML syntax highlighting
                > within strings in my php files, which is great. I would also like to do
                > javascript syntax highlighting within strings in a php file. Does
                > anybody know if this can be done and if so how can I do it?
                >
                >
                > edited - added extra possibilities
                >
                >
                > I should also mention that I would be happy with a solution where i
                > have to parse all my javascript strings though a php function before
                > outputting the result. This might get around the problem suggested by
                > connor below where vim has trouble deciding if the string contains
                > javascript. for example:
                >
                > $js = "some regular text which is not javascript##now vim has
                > detected that this part is javscript##back to regular text";
                >
                > parse($js);
                > function parse($str)
                >
                > {
                >     return str_replace('##', '', $str);
                >
                > }
                >
                >
                >
                > The reason I would be happy to do this is because I will probably be
                > incorporating a html/css/js variable minifier into my project which will
                > be doing substitutions on strings anyway.
                >
                >
                > Of course if there is a vim-specific equivalent character for ## which will not show up in the source code and would not need to be filtered out then this would be preferable...

                I personally passed up the question because I don't know of a way that is already built into the php syntax script but maybe one exists.

                It's possible to do, see http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file and the help links it gives but it will require a lot of work on your part to do it yourself.

                --
                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
              • Peter Miller
                ... thanks for the replies people! and no worries if it takes a while :) somebody on stackoverflow showed me that if i put at the start of the string,
                Message 7 of 7 , Aug 1, 2012
                  On Thu, Aug 2, 2012 at 1:20 AM, Ben Fritz <fritzophrenic@...> wrote:
                  On Wednesday, August 1, 2012 1:08:35 AM UTC-5, mulllhausen wrote:
                  > hi all,
                  >
                  > i gather from the lack of response that my previous question has no feasible answer. anyway, i have updated the question a bit to give some other possible ways of solving the problem. any pointers in the right direction would be much appreciated. i am pretty competent with vim but i have little to no vim scripting. then again i am a quick learner and very eager haha...
                  >
                  >
                  > here is the updated question: http://stackoverflow.com/questions/11661614/vim-php-javascriptinstrings-option
                  >
                  >
                  >
                  >
                  >
                  >
                  >
                  > I noticed that the syntax/php.vim file on my ubuntu machine has a php_htmlInStrings
                  >  option. I can turn this option on to display HTML syntax highlighting
                  > within strings in my php files, which is great. I would also like to do
                  > javascript syntax highlighting within strings in a php file. Does
                  > anybody know if this can be done and if so how can I do it?
                  >
                  >
                  > edited - added extra possibilities
                  >
                  >
                  > I should also mention that I would be happy with a solution where i
                  > have to parse all my javascript strings though a php function before
                  > outputting the result. This might get around the problem suggested by
                  > connor below where vim has trouble deciding if the string contains
                  > javascript. for example:
                  >
                  > $js = "some regular text which is not javascript##now vim has
                  > detected that this part is javscript##back to regular text";
                  >
                  > parse($js);
                  > function parse($str)
                  >
                  > {
                  >     return str_replace('##', '', $str);
                  >
                  > }
                  >
                  >
                  >
                  > The reason I would be happy to do this is because I will probably be
                  > incorporating a html/css/js variable minifier into my project which will
                  >  be doing substitutions on strings anyway.
                  >
                  >
                  > Of course if there is a vim-specific equivalent character for ## which will not show up in the source code and would not need to be filtered out then this would be preferable...

                  I personally passed up the question because I don't know of a way that is already built into the php syntax script but maybe one exists.

                  It's possible to do, see http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file and the help links it gives but it will require a lot of work on your part to do it yourself.

                  --
                  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


                  thanks for the replies people! and no worries if it takes a while :)

                  somebody on stackoverflow showed me that if i put <script> at the start of the string, then turn on the html syntax highlighting, vim will interpret the string as javascript and format accordingly.

                  my line 167 in syntax/html.vim previously looked like this:

                  syn region  javaScript start=+<script[^>]*>+ keepend end=+</script>+me=s-1 contains=@htmlJavaScript,htmlCssStyleComment,htmlScriptTag,@htmlPreproc

                  so i commented it out and changed "script" to "js". i have a work around now where i parse all javascript strings through a function to strip out the opening tag (i found that i dont actually need a closing tag for vim to give the proper syntax highlighting). however, while this is functional, it would be nice if i could use the following format to get the syntax highlighting:

                  /*<js>*/ "this string should have javascript syntax highlighting" /*</js>*/

                  i have had a go at this but i'm a bit new to the way that vim groups regions under headings so i didn't get it right. line 340 in syntax/php.vim currently reads:

                    syn region  phpComment  start="/\*" end="\*/" contained contains=phpTodo

                  so i tried changing it to:

                    syn region  phpComment  start="/\*" end="\*/" contained contains=@htmlJavascript,phpTodo

                  but that doesn't do it.

                  actually if somebody could give me some pointers as to a good place to learn about the vim syntax regions that would be a great help. or if anybody can tell me how i could alter my syntax/ files that would be even better!

                  thanks in advance!
                  peter

                  --
                  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.