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

Improve context syntax file

Expand Messages
  • Marco
    Hi, the context syntax file is rather outdated. I have never tinkered with syntax files and I don t really have a clue how they work. However, I managed to
    Message 1 of 13 , Sep 25, 2013
    • 0 Attachment
      Hi,

      the context syntax file is rather outdated. I have never tinkered
      with syntax files and I don't really have a clue how they work.
      However, I managed to improve the existing one. I contacted the
      maintainer Nikolai Weibull, but I didn't get a response. So I post
      my improvements to this list.

      The changes I made:

      1) additional syntax languages in g:context_include.
      2) support for all MetaPost environments, e.g. \startMPcode
      3) support for Lua highlighting for MkIV
      4) support for the gnuplot module
      5) add C++ syntax highlighting (since C is there as well)
      6) support for the MkIV start-stop structuring commands, e.g. \startsection
      7) add more font switches
      8) a fix, so that \startCSV is not recognised as C code

      Unsolved problems which I couldn't fix myself:

      - having the underscore correctly recognised, e.g. the following
      results in wrong syntax highlighting

      \unprotect
      \def\foo_bar{whatever}
      \def\foo@bar{whatever}
      \protect

      \starttexcode
      \def\foo_bar{whatever}
      \def\foo@bar{whatever}
      \stoptexcode

      - correct commentstring in Lua code (e.g. in combination with Tim
      Pope's vim-commentary)

      \starttext
      \startluacode
      foo="bar"
      \stopluacode
      \stoptext

      Pressing gcc (with vim-commentary) while being on the line
      “foo="bar"” leads to

      %% foo="bar"

      instead of

      -- foo="bar"

      - I have set commentstring to %%\ %s for ConTeXt in my .vimrc.
      Can this be set automatically?

      Does someone have a solution for the three unsolved problems?

      Marco
    • Marco
      ... I found it. The commentstring is set it ftplugin/context.vim ... Does someone have a solution for the remaining two problems? Marco
      Message 2 of 13 , Sep 25, 2013
      • 0 Attachment
        On 2013–09–25 Marco wrote:

        > Unsolved problems which I couldn't fix myself:
        >
        > - I have set commentstring to %%\ %s for ConTeXt in my .vimrc.
        > Can this be set automatically?

        I found it. The commentstring is set it ftplugin/context.vim

        > Does someone have a solution for the three unsolved problems?

        Does someone have a solution for the remaining two problems?

        Marco
      • Nikolay Pavlov
        ... I guess you need to alter iskeyword for the problem with underscore. But different comments could be only a result of patching commetary and other plugins.
        Message 3 of 13 , Sep 25, 2013
        • 0 Attachment


          On Sep 26, 2013 10:46 AM, "Marco" <lists@...> wrote:
          >
          > On 2013–09–25 Marco wrote:
          >
          > > Unsolved problems which I couldn't fix myself:
          > >
          > > - I have set commentstring to %%\ %s for ConTeXt in my .vimrc.
          > >   Can this be set automatically?
          >
          > I found it. The commentstring is set it ftplugin/context.vim
          >
          > > Does someone have a solution for the three unsolved problems?
          >
          > Does someone have a solution for the remaining two problems?

          I guess you need to alter iskeyword for the problem with underscore. But different comments could be only a result of patching commetary and other plugins. You can try hacking with CursorMoved/CursorMovedI events but likely you will introduce more problems then solve.

          > Marco

          --
          --
          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
           
          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Marco
          ... But I can t add it permanently. The underscore is only part of a word in between the following blocks. unprotect … protect %% or starttexcode …
          Message 4 of 13 , Sep 26, 2013
          • 0 Attachment
            On 2013–09–26 Nikolay Pavlov wrote:

            > > Does someone have a solution for the remaining two problems?
            >
            > I guess you need to alter iskeyword for the problem with underscore.

            But I can't add it permanently. The underscore is only part of a
            word in between the following blocks.

            \unprotect … \protect %% or
            \starttexcode … \stoptexcode

            > But different comments could be only a result of patching
            > commetary and other plugins. You can try hacking with
            > CursorMoved/CursorMovedI events but likely you will introduce more
            > problems then solve.

            I don't think patching commetary is the right solution. It's a very
            small plugin only relying on commentstring. Furthermore, vim knows
            already that it's inside a Lua snippet (it switched to Lua syntax
            highlighting) and it knows that it's inside a Lua comment (it's
            highlighted as a comment). So all required information is available
            at this point. If I only could make vim change the commentstring in
            this case, that would be perfect.

            Marco
          • Nikolay Pavlov
            ... If you want to respect this I see no way other then duplicating syntax definitions for inner region. :execute is your friend here. ... Vim knows nothing.
            Message 5 of 13 , Sep 26, 2013
            • 0 Attachment


              On Sep 26, 2013 11:53 AM, "Marco" <lists@...> wrote:
              >
              > On 2013–09–26 Nikolay Pavlov wrote:
              >
              > > > Does someone have a solution for the remaining two problems?
              > >
              > > I guess you need to alter iskeyword for the problem with underscore.
              >
              > But I can't add it permanently. The underscore is only part of a
              > word in between the following blocks.
              >
              >   \unprotect    … \protect %% or
              >   \starttexcode … \stoptexcode

              If you want to respect this I see no way other then duplicating syntax definitions for inner region. :execute is your friend here.

              > > But different comments could be only a result of patching
              > > commetary and other plugins. You can try hacking with
              > > CursorMoved/CursorMovedI events but likely you will introduce more
              > > problems then solve.
              >
              > I don't think patching commetary is the right solution. It's a very
              > small plugin only relying on commentstring. Furthermore, vim knows
              > already that it's inside a Lua snippet (it switched to Lua syntax
              > highlighting) and it knows that it's inside a Lua comment (it's
              > highlighted as a comment). So all required information is available
              > at this point. If I only could make vim change the commentstring in
              > this case, that would be perfect.

              Vim knows nothing. Lua syntax highlighting groups are not a tiny bit different from any other syntax highlighting group included in any other cluster (implementation of :syn include). There is no source of information about &commentstring in lua hl group that defines highlighting for comments. Also what vim is supposed to use if you included multiple languages in the selection and want to comment it? And note that there is no line-local options.

              You must patch commentary to make it obtain information from the syntax group name or use some plugin that is already capable of doing this: information that really is there requires human for teaching computer to interpret it. Vim cannot do this itself.

              Note that it is likely that no plugins capable of doing this use &commentstring for nested region due to problems which will appear if one sources ftplugin for different filetype.

              > Marco

              --
              --
              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
               
              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Paul Isambert
              ... Since there is little chance that an underscore will immediately follow a control sequence anyway, I don t think defining it for the entire syntax file
              Message 6 of 13 , Sep 26, 2013
              • 0 Attachment
                Marco wrote:
                > On 2013–09–26 Nikolay Pavlov wrote:
                >
                > > > Does someone have a solution for the remaining two problems?
                > >
                > > I guess you need to alter iskeyword for the problem with
                > > underscore.
                >
                > But I can't add it permanently. The underscore is only part of a
                > word in between the following blocks.
                >
                > \unprotect … \protect %% or
                > \starttexcode … \stoptexcode

                Since there is little chance that an underscore will immediately follow a
                control sequence anyway, I don't think defining it for the entire syntax file
                will cause any problem.

                However, you can do something along the following lines:

                sy match ControlSequence '\\[a-zA-Z]\+'
                sy match SpecialControlSequence '\\[a-zA-Z_]\+' contained
                sy region SpecialCode matchgroup=ControlSequence start='\\unprotect' end='\\protect' contains=SpecialControlSequence

                Best,
                Paul

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

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Nikolay Pavlov
                ... file ... It is very common in LaTeX math: int_a^b . Can t say anything about context though. In LaTeX/TeX syntax file AFAIR _ is marked as an error
                Message 7 of 13 , Sep 26, 2013
                • 0 Attachment


                  On Sep 26, 2013 1:33 PM, "Paul Isambert" <zappathustra@...> wrote:
                  >
                  > Marco wrote:
                  > > On 2013–09–26 Nikolay Pavlov wrote:
                  > >
                  > > > > Does someone have a solution for the remaining two problems?
                  > > >
                  > > > I guess you need to alter iskeyword for the problem with
                  > > > underscore.
                  > >
                  > > But I can't add it permanently. The underscore is only part of a
                  > > word in between the following blocks.
                  > >
                  > >   \unprotect    … \protect %% or
                  > >   \starttexcode … \stoptexcode
                  >
                  > Since there is little chance that an underscore will immediately follow a
                  > control sequence anyway, I don't think defining it for the entire syntax file
                  > will cause any problem.

                  It is very common in LaTeX math:

                      \int_a^b

                  . Can't say anything about context though.

                  In LaTeX/TeX syntax file AFAIR _ is marked as an error outside of math regions though.

                  > However, you can do something along the following lines:
                  >
                  >   sy match ControlSequence '\\[a-zA-Z]\+'
                  >   sy match SpecialControlSequence '\\[a-zA-Z_]\+' contained
                  >   sy region SpecialCode matchgroup=ControlSequence start='\\unprotect' end='\\protect' contains=SpecialControlSequence

                  --
                  --
                  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
                   
                  ---
                  You received this message because you are subscribed to the Google Groups "vim_use" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Marco
                  ... I tried this. But iskeyword does not change the syntax highlighting. It only seems to have an effect on the “*” and similar commands. So changing
                  Message 8 of 13 , Sep 26, 2013
                  • 0 Attachment
                    On 2013–09–26 Paul Isambert wrote:

                    > > But I can't add it permanently. The underscore is only part of a
                    > > word in between the following blocks.
                    > >
                    > > \unprotect … \protect %% or
                    > > \starttexcode … \stoptexcode
                    >
                    > Since there is little chance that an underscore will immediately follow a
                    > control sequence anyway, I don't think defining it for the entire syntax file
                    > will cause any problem.

                    I tried this. But iskeyword does not change the syntax highlighting.
                    It only seems to have an effect on the “*” and similar commands. So
                    changing iskeyword is probably not what I'm after.

                    > However, you can do something along the following lines:
                    >
                    > sy match ControlSequence '\\[a-zA-Z]\+'
                    > sy match SpecialControlSequence '\\[a-zA-Z_]\+' contained
                    > sy region SpecialCode matchgroup=ControlSequence start='\\unprotect' end='\\protect' contains=SpecialControlSequence

                    I tried this, but it removes all syntax highlighting. Frankly, I
                    have no idea of how the syntax highlighting works. I have to read up
                    the basics to understand how this exactly works. The issue seems
                    more complicated than anticipated. But thanks for the snippet, it's
                    something to start with.

                    Marco
                  • Marco
                    ... “a” is not a control sequence. ... The maths looks almost the same, it s mostly TeX anyway. ... Not so in ConTeXt. Underscores and circumflex accents
                    Message 9 of 13 , Sep 26, 2013
                    • 0 Attachment
                      On 2013–09–26 Nikolay Pavlov wrote:

                      > > Since there is little chance that an underscore will immediately follow a
                      > > control sequence anyway, I don't think defining it for the entire syntax
                      > file
                      > > will cause any problem.
                      >
                      > It is very common in LaTeX math:
                      >
                      > \int_a^b

                      “a” is not a control sequence.

                      > . Can't say anything about context though.

                      The maths looks almost the same, it's mostly TeX anyway.

                      > In LaTeX/TeX syntax file AFAIR _ is marked as an error outside of
                      > math regions though.

                      Not so in ConTeXt. Underscores and circumflex accents are valid
                      input:

                      \starttext
                      This_is_valid %% the _ is not marked as error, correct
                      So ^ is ^ this %% the ^ is marked as error, although it's valid input
                      \stoptext

                      Marco
                    • Nikolay Pavlov
                      ... follow a ... syntax ... Assuming _ is defined to be a part of a command this will incorrectly highlight _a with the same color as int. Thus you cannot
                      Message 10 of 13 , Sep 26, 2013
                      • 0 Attachment


                        On Sep 26, 2013 2:18 PM, "Marco" <lists@...> wrote:
                        >
                        > On 2013–09–26 Nikolay Pavlov wrote:
                        >
                        > > > Since there is little chance that an underscore will immediately follow a
                        > > > control sequence anyway, I don't think defining it for the entire syntax
                        > > file
                        > > > will cause any problem.
                        > >
                        > > It is very common in LaTeX math:
                        > >
                        > >     \int_a^b
                        >
                        > “a” is not a control sequence.

                        Assuming _ is defined to be a part of a command this will incorrectly highlight _a with the same color as \int. Thus you cannot just follow that advice.

                        > > . Can't say anything about context though.
                        >
                        > The maths looks almost the same, it's mostly TeX anyway.
                        >
                        > > In LaTeX/TeX syntax file AFAIR _ is marked as an error outside of
                        > > math regions though.
                        >
                        > Not so in ConTeXt. Underscores and circumflex accents are valid
                        > input:
                        >
                        >   \starttext
                        >     This_is_valid  %% the _ is not marked as error, correct
                        >     So ^ is ^ this %% the ^ is marked as error, although it's valid input
                        >   \stoptext
                        >
                        > Marco

                        --
                        --
                        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
                         
                        ---
                        You received this message because you are subscribed to the Google Groups "vim_use" group.
                        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                        For more options, visit https://groups.google.com/groups/opt_out.
                      • Nikolay Pavlov
                        ... a ... syntax file ... It also affects k atom. If changing &iskeyword does not affect syntax highlighting then it means this atom is not used. ...
                        Message 11 of 13 , Sep 26, 2013
                        • 0 Attachment


                          On Sep 26, 2013 2:12 PM, "Marco" <lists@...> wrote:
                          >
                          > On 2013–09–26 Paul Isambert wrote:
                          >
                          > > > But I can't add it permanently. The underscore is only part of a
                          > > > word in between the following blocks.
                          > > >
                          > > >   \unprotect    … \protect %% or
                          > > >   \starttexcode … \stoptexcode
                          > >
                          > > Since there is little chance that an underscore will immediately follow a
                          > > control sequence anyway, I don't think defining it for the entire syntax file
                          > > will cause any problem.
                          >
                          > I tried this. But iskeyword does not change the syntax highlighting.
                          > It only seems to have an effect on the “*” and similar commands. So
                          > changing iskeyword is probably not what I'm after.

                          It also affects \k atom. If changing &iskeyword does not affect syntax highlighting then it means this atom is not used.

                          > > However, you can do something along the following lines:
                          > >
                          > >   sy match ControlSequence '\\[a-zA-Z]\+'
                          > >   sy match SpecialControlSequence '\\[a-zA-Z_]\+' contained
                          > >   sy region SpecialCode matchgroup=ControlSequence start='\\unprotect' end='\\protect' contains=SpecialControlSequence
                          >
                          > I tried this, but it removes all syntax highlighting. Frankly, I
                          > have no idea of how the syntax highlighting works. I have to read up
                          > the basics to understand how this exactly works. The issue seems
                          > more complicated than anticipated. But thanks for the snippet, it's
                          > something to start with.

                          You also need to make all other syntax groups be containedin=SpecialCode. Or add contains=... to SpecialCode definition for all groups you need to be highlighted.

                          Note that there is no need in defining two separate syntax groups. You can make two rules for ControlSequence where one will be contained and other will not.

                          > Marco

                          --
                          --
                          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
                           
                          ---
                          You received this message because you are subscribed to the Google Groups "vim_use" group.
                          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                          For more options, visit https://groups.google.com/groups/opt_out.
                        • Paul Isambert
                          ... Anyway itÆs not a good idea since I had forgotten about math mode indeed. ... You also need, above all, to define highlight groups (that was implicit in
                          Message 12 of 13 , Sep 26, 2013
                          • 0 Attachment
                            Nikolay Pavlov <zyx.vim@...> a écrit:
                            > On Sep 26, 2013 2:12 PM, "Marco" <lists@...> wrote:
                            > >
                            > > On 2013–09–26 Paul Isambert wrote:
                            > >
                            > > > > But I can't add it permanently. The underscore is only part of a
                            > > > > word in between the following blocks.
                            > > > >
                            > > > > \unprotect … \protect %% or
                            > > > > \starttexcode … \stoptexcode
                            > > >
                            > > > Since there is little chance that an underscore will immediately follow
                            > a
                            > > > control sequence anyway, I don't think defining it for the entire
                            > syntax file
                            > > > will cause any problem.
                            > >
                            > > I tried this. But iskeyword does not change the syntax highlighting.
                            > > It only seems to have an effect on the “*” and similar commands. So
                            > > changing iskeyword is probably not what I'm after.
                            >
                            > It also affects \k atom. If changing &iskeyword does not affect syntax
                            > highlighting then it means this atom is not used.

                            Anyway it’s not a good idea since I had forgotten about math mode indeed.

                            > > > However, you can do something along the following lines:
                            > > >
                            > > > sy match ControlSequence '\\[a-zA-Z]\+'
                            > > > sy match SpecialControlSequence '\\[a-zA-Z_]\+' contained
                            > > > sy region SpecialCode matchgroup=ControlSequence start='\\unprotect'
                            > end='\\protect' contains=SpecialControlSequence
                            > >
                            > > I tried this, but it removes all syntax highlighting. Frankly, I
                            > > have no idea of how the syntax highlighting works. I have to read up
                            > > the basics to understand how this exactly works. The issue seems
                            > > more complicated than anticipated. But thanks for the snippet, it's
                            > > something to start with.
                            >
                            > You also need to make all other syntax groups be containedin=SpecialCode.
                            > Or add contains=... to SpecialCode definition for all groups you need to be
                            > highlighted.
                            >
                            > Note that there is no need in defining two separate syntax groups. You can
                            > make two rules for ControlSequence where one will be contained and other
                            > will not.

                            You also need, above all, to define highlight groups (that was
                            implicit in my code, I thought you knew about that), e.g.:

                            hi link ControlSequence Statement

                            But indeed you should learn a little bit more about highlighting (I’ve
                            always found modifying existing syntax files quite painful and easier
                            to start from scratch). Otherwise you may perhaps ask someone like
                            Aditya Mahajan, who is both an advanced ConTeXt user (he writes in
                            TUGboat) and, as far as I know, a Vim user.

                            Best,
                            Paul

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

                            ---
                            You received this message because you are subscribed to the Google Groups "vim_use" group.
                            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                            For more options, visit https://groups.google.com/groups/opt_out.
                          • Nikolay Pavlov
                            ... follow ... start= unprotect ... containedin=SpecialCode. ... to be ... can ... That s the reason why I suggest using two syntax rules for one
                            Message 13 of 13 , Sep 26, 2013
                            • 0 Attachment


                              On Sep 26, 2013 6:20 PM, "Paul Isambert" <zappathustra@...> wrote:
                              >
                              > Nikolay Pavlov <zyx.vim@...> a écrit:
                              > > On Sep 26, 2013 2:12 PM, "Marco" <lists@...> wrote:
                              > > >
                              > > > On 2013–09–26 Paul Isambert wrote:
                              > > >
                              > > > > > But I can't add it permanently. The underscore is only part of a
                              > > > > > word in between the following blocks.
                              > > > > >
                              > > > > >   \unprotect    … \protect %% or
                              > > > > >   \starttexcode … \stoptexcode
                              > > > >
                              > > > > Since there is little chance that an underscore will immediately follow
                              > > a
                              > > > > control sequence anyway, I don't think defining it for the entire
                              > > syntax file
                              > > > > will cause any problem.
                              > > >
                              > > > I tried this. But iskeyword does not change the syntax highlighting.
                              > > > It only seems to have an effect on the “*” and similar commands. So
                              > > > changing iskeyword is probably not what I'm after.
                              > >
                              > > It also affects \k atom. If changing &iskeyword does not affect syntax
                              > > highlighting then it means this atom is not used.
                              >
                              > Anyway it’s not a good idea since I had forgotten about math mode indeed.
                              >
                              > > > > However, you can do something along the following lines:
                              > > > >
                              > > > >   sy match ControlSequence '\\[a-zA-Z]\+'
                              > > > >   sy match SpecialControlSequence '\\[a-zA-Z_]\+' contained
                              > > > >   sy region SpecialCode matchgroup=ControlSequence start='\\unprotect'
                              > > end='\\protect' contains=SpecialControlSequence
                              > > >
                              > > > I tried this, but it removes all syntax highlighting. Frankly, I
                              > > > have no idea of how the syntax highlighting works. I have to read up
                              > > > the basics to understand how this exactly works. The issue seems
                              > > > more complicated than anticipated. But thanks for the snippet, it's
                              > > > something to start with.
                              > >
                              > > You also need to make all other syntax groups be containedin=SpecialCode.
                              > > Or add contains=... to SpecialCode definition for all groups you need to be
                              > > highlighted.
                              > >
                              > > Note that there is no need in defining two separate syntax groups. You can
                              > > make two rules for ControlSequence where one will be contained and other
                              > > will not.
                              >
                              > You also need, above all, to define highlight groups (that was
                              > implicit in my code, I thought you knew about that), e.g.:
                              >
                              >   hi link ControlSequence Statement

                              That's the reason why I suggest using two syntax rules for one highlighting group: I assume that separate highlighting for the same elements just in different context is not needed.

                              > But indeed you should learn a little bit more about highlighting (I’ve
                              > always found modifying existing syntax files quite painful and easier
                              > to start from scratch). Otherwise you may perhaps ask someone like
                              > Aditya Mahajan, who is both an advanced ConTeXt user (he writes in
                              > TUGboat) and, as far as I know, a Vim user.
                              >
                              > Best,
                              > Paul
                              >
                              > --
                              > --
                              > 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
                              >
                              > ---
                              > You received this message because you are subscribed to the Google Groups "vim_use" group.
                              > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                              > For more options, visit https://groups.google.com/groups/opt_out.

                              --
                              --
                              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
                               
                              ---
                              You received this message because you are subscribed to the Google Groups "vim_use" group.
                              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                              For more options, visit https://groups.google.com/groups/opt_out.
                            Your message has been successfully submitted and would be delivered to recipients shortly.