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

Re: syn question

Expand Messages
  • Johannes Zellner
    ... suppose I want to highlight a pattern (e.g. my e-mail address) in all files of all filetypes w/o changing the original syntax files and without adding a
    Message 1 of 8 , Apr 11 1:11 AM
    • 0 Attachment
      On Mon, 10 Apr 2000, Bram Moolenaar wrote:

      > Johannes Zellner wrote:
      >
      > > having
      > > :syntax region fred start=+.*fred+rs=s end=+fred+
      > > :hi fred cterm=blue
      > >
      > > why does this not match the following line ?
      > >
      > > blabla fred blabla
      > >
      > > :help syn-region says:
      > > The search for the end pattern starts at the start of the region.
      > > This implies that it can also match inside the start pattern!
      >
      > The documentation is wrong, the search for the end pattern starts only after
      > the match with the start pattern. Otherwise this wouldn't work:
      >
      > :syn region someString start=/"/ end=/"/
      >
      > Now the question is if it should somehow be possible to find a match for the
      > end pattern inside the match for the start pattern? It could perhaps be
      > useful in some situations. Although you can probably do what you want with a
      > "syn match" item then, since it's in a single line. Perhaps we need an
      > example of you were trying to do.

      suppose I want to highlight a pattern (e.g. my e-mail address) in all files
      of all filetypes w/o changing the original syntax files and without adding
      a line in `mysyntax.vim' for each filetype.

      I thought this could be possible by an autocommand which is triggered after
      the syntax has been loaded. Something like

      au BufReadPost * syntax region eMail start=+<johannes@...>+rs=s end=+<johannes@...>+
      hi eMail term=underline cterm=underline ctermfg=darkblue gui=underline guifg=blue

      The problem is that the pattern I want to add (here: my email) may occur
      within an other syntax region (e.g. a comment.).

      " e.g. in a .vim file
      " (C) 1999 - 2000 by Johannes Zellner, <johannes@...>
      " ^^^^^^^^^^^^^^^^^^^^^^
      " highlight this

      " does not work for the above case:
      au BufReadPost * syntax match eMail +<johannes@...>+

      " matches the above case but highlights all from the beginning of the line:
      au BufReadPost * syntax match eMail +.*<johannes@...>+


      maybe there's an easy solution, but I don't see it.


      --
      Johannes
    • Stephen P. Wall
      ... I use the following to highlight a variety of todo items: Todo/DEBUG items in comments: autocmd BufNewFile,BufRead * if exists( b:current_syntax )
      Message 2 of 8 , Apr 11 6:10 AM
      • 0 Attachment
        > From: Johannes Zellner <johannes@...>
        >
        > suppose I want to highlight a pattern (e.g. my e-mail address) in all files
        > of all filetypes w/o changing the original syntax files and without adding
        > a line in `mysyntax.vim' for each filetype.

        I use the following to highlight a variety of todo items:

        " Todo/DEBUG items in comments:
        autocmd BufNewFile,BufRead * if exists("b:current_syntax")
        autocmd BufNewFile,BufRead * exe 'syn keyword '.b:current_syntax.'Todo
        contained TODO FIXME XXX DEBUG Debug Todo todo ATTENTION kludge Kludge KLUDGE'
        autocmd BufNewFile,BufRead * exe 'syn match '.b:current_syntax.'Todo
        contained "!!!!*\|????*"'
        autocmd BufNewFile,BufRead * endif

        If your e-mail name will always appear in comments, you could use
        this to highlight it using the Todo highlight group. There are
        highlight groups used by some syntax files you could do the same
        with - xSpecial, xStringError - to get highlighting in strings,
        but it would be much less universal.

        A more complete, albiet slower and more complicated, solution would
        be to write a function that captures the output of the ":syntax"
        command, clears the syntax, and rebuilds it using the captured output,
        with the addition of a "contains=eMail" on every syntax item.

        Or you could turn hlsearch on and "/johannes@..."....


        --
        Free High Speed DSL Access:
        http://in.winfire.com/s/isapiEng.dll/wf.exe?cmd=rl&452,180045277&wf.exe
        ______________________________________________________________________
        ________ ______
        Stephen P. Wall Redcom Laboratories, Inc. / __ /\/ ___/\
        Steve_Wall@... One Redcom Center ___/ /\/ /_/ /\__\/
        (716) 924-7550 Victor, NY 14564 /_____/ /_______/ /
        x300 USA \_____\/\_______\/
      • Johannes Zellner
        ... not bad. I ll try this. thanks. -- Johannes
        Message 3 of 8 , Apr 11 6:17 AM
        • 0 Attachment
          On Tue, 11 Apr 2000, Stephen P. Wall wrote:

          > > From: Johannes Zellner <johannes@...>
          > >
          > > suppose I want to highlight a pattern (e.g. my e-mail address) in all files
          > > of all filetypes w/o changing the original syntax files and without adding
          > > a line in `mysyntax.vim' for each filetype.
          >
          > I use the following to highlight a variety of todo items:
          >
          > " Todo/DEBUG items in comments:
          > autocmd BufNewFile,BufRead * if exists("b:current_syntax")
          > autocmd BufNewFile,BufRead * exe 'syn keyword '.b:current_syntax.'Todo
          > contained TODO FIXME XXX DEBUG Debug Todo todo ATTENTION kludge Kludge KLUDGE'
          > autocmd BufNewFile,BufRead * exe 'syn match '.b:current_syntax.'Todo
          > contained "!!!!*\|????*"'
          > autocmd BufNewFile,BufRead * endif
          not bad. I'll try this. thanks.

          --
          Johannes
        • Johannes Zellner
          ... but it restricts me to groups which were defined to be contained in b:current_syntax. Comment -- Johannes
          Message 4 of 8 , Apr 11 6:28 AM
          • 0 Attachment
            On Tue, 11 Apr 2000, Johannes Zellner wrote:

            > On Tue, 11 Apr 2000, Stephen P. Wall wrote:
            >
            > > > From: Johannes Zellner <johannes@...>
            > > >
            > > > suppose I want to highlight a pattern (e.g. my e-mail address) in all files
            > > > of all filetypes w/o changing the original syntax files and without adding
            > > > a line in `mysyntax.vim' for each filetype.
            > >
            > > I use the following to highlight a variety of todo items:
            > >
            > > " Todo/DEBUG items in comments:
            > > autocmd BufNewFile,BufRead * if exists("b:current_syntax")
            > > autocmd BufNewFile,BufRead * exe 'syn keyword '.b:current_syntax.'Todo
            > > contained TODO FIXME XXX DEBUG Debug Todo todo ATTENTION kludge Kludge KLUDGE'
            > > autocmd BufNewFile,BufRead * exe 'syn match '.b:current_syntax.'Todo
            > > contained "!!!!*\|????*"'
            > > autocmd BufNewFile,BufRead * endif
            > not bad. I'll try this. thanks.

            but it restricts me to groups which were defined
            to be contained in b:current_syntax.'Comment'

            --
            Johannes
          • Stephen P. Wall
            ... Yes. Almost half of the syntax files include a Todo item. And as I said, it will only be in comments. Maybe you could implement a new syntax keyword,
            Message 5 of 8 , Apr 11 7:27 AM
            • 0 Attachment
              > From: Johannes Zellner <johannes@...>
              >
              > but it restricts me to groups which were defined
              > to be contained in b:current_syntax.'Comment'
              >

              Yes. Almost half of the syntax files include a Todo item.
              And as I said, it will only be in comments. Maybe you could implement
              a new syntax keyword, "containedall":

              syntax match eMail "johannes@..." containedall

              Would force eMail to be contained by all other syntax groups, whether
              they have a "contains=" option or not. Don't know if Bram would
              want to include such a thing - it's use it quite narrow. Would there
              be a more general way to implement something like this?

              syntax match eMail "johannes@..." supercedes=@ALL

              with "supercedes" being a list of syntax items which this item will
              supercede, even if the other syntax has already started. problems -
              should the superceded syntax resume after the superceding one ends,
              or should it just be ended, or should the code track both syntaxes
              simultaneously, and "do the right thing"? Could get quite complicated,
              multiple "supercedes" could result in tracking several syntaxes
              simultaneously. Could restrict to only one supercede active at a time,
              ie, you cannot supercede a syntax item that has the "supercede" option.
              Again, though, are there enough practical applications of such an item
              to make implementation worthwhile?

              --
              Free High Speed DSL Access:
              http://in.winfire.com/s/isapiEng.dll/wf.exe?cmd=rl&452,180045277&wf.exe
              ______________________________________________________________________
              ________ ______
              Stephen P. Wall Redcom Laboratories, Inc. / __ /\/ ___/\
              Steve_Wall@... One Redcom Center ___/ /\/ /_/ /\__\/
              (716) 924-7550 Victor, NY 14564 /_____/ /_______/ /
              x300 USA \_____\/\_______\/
            • Bram Moolenaar
              ... Hmm, would be possible. Since it would also match when it s not contained in anything, containedall isn t fully correct. We could call it anywhere
              Message 6 of 8 , Apr 12 8:16 AM
              • 0 Attachment
                Stephen P. Wall wrote:

                > Maybe you could implement a new syntax keyword, "containedall":
                >
                > syntax match eMail "johannes@..." containedall

                Hmm, would be possible. Since it would also match when it's not contained in
                anything, "containedall" isn't fully correct. We could call it "anywhere"
                perhaps.

                > Would force eMail to be contained by all other syntax groups, whether
                > they have a "contains=" option or not. Don't know if Bram would
                > want to include such a thing - it's use it quite narrow. Would there
                > be a more general way to implement something like this?
                >
                > syntax match eMail "johannes@..." supercedes=@ALL
                >
                > with "supercedes" being a list of syntax items which this item will
                > supercede, even if the other syntax has already started. problems -
                > should the superceded syntax resume after the superceding one ends,
                > or should it just be ended, or should the code track both syntaxes
                > simultaneously, and "do the right thing"? Could get quite complicated,
                > multiple "supercedes" could result in tracking several syntaxes
                > simultaneously. Could restrict to only one supercede active at a time,
                > ie, you cannot supercede a syntax item that has the "supercede" option.
                > Again, though, are there enough practical applications of such an item
                > to make implementation worthwhile?

                This sounds complicated. Do we really need this? Implementing the "anywhere"
                is much easier.

                Another item that would be nice, but might not be needed, is "containedin=",
                giving a list of items this item can be contained in, even though those items
                don't have this item in their "contains=" list.

                --
                hundred-and-one symptoms of being an internet addict:
                3. Your bookmark takes 15 minutes to scroll from top to bottom.

                /-/-- Bram Moolenaar --- Bram@... --- http://www.moolenaar.net --\-\
                \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/
              • Stephen P. Wall
                ... Or everywhere . Hey, a religious war! 8-] ... Not quite that bad... 8-] They re mostly useless, anyways. Some are so old, I don t even know if they
                Message 7 of 8 , Apr 12 11:19 AM
                • 0 Attachment
                  > From: Bram Moolenaar <Bram@...>
                  >
                  > Hmm, would be possible. Since it would also match when it's not contained in
                  > anything, "containedall" isn't fully correct. We could call it "anywhere"
                  > perhaps.
                  >

                  Or "everywhere". Hey, a religious war! 8-]


                  > 3. Your bookmark takes 15 minutes to scroll from top to bottom.

                  Not quite that bad... 8-] They're mostly useless, anyways. Some
                  are so old, I don't even know if they still work. A bunch were put
                  there by the browser and I don't even know what they are. Somebody
                  should invent a better way to organize and track them. How about
                  a vim script? =-) Hey, if vim could display images and access
                  HTTP servers, it could even fetch the links and display them for
                  you... Netscape's new Gecko engine is supposed to be embeddable...

                  --
                  Free High Speed DSL Access:
                  http://in.winfire.com/s/isapiEng.dll/wf.exe?cmd=rl&452,180045277&wf.exe
                  ______________________________________________________________________
                  ________ ______
                  Stephen P. Wall Redcom Laboratories, Inc. / __ /\/ ___/\
                  Steve_Wall@... One Redcom Center ___/ /\/ /_/ /\__\/
                  (716) 924-7550 Victor, NY 14564 /_____/ /_______/ /
                  x300 USA \_____\/\_______\/
                • Thomas Köhler
                  On Wed, Apr 12, 2000 at 08:24:50PM +0200, ... [...] ... Well, as I m currently struggling to get my bookmarks database (it s really a database, mySQL-based)
                  Message 8 of 8 , Apr 12 11:40 AM
                  • 0 Attachment
                    On Wed, Apr 12, 2000 at 08:24:50PM +0200,
                    Stephen P. Wall <swall@...> wrote:
                    >
                    [...]
                    > > 3. Your bookmark takes 15 minutes to scroll from top to bottom.
                    >
                    > Not quite that bad... 8-] They're mostly useless, anyways. Some
                    > are so old, I don't even know if they still work. A bunch were put
                    > there by the browser and I don't even know what they are. Somebody
                    > should invent a better way to organize and track them. How about
                    > a vim script? =-) Hey, if vim could display images and access
                    > HTTP servers, it could even fetch the links and display them for
                    > you... Netscape's new Gecko engine is supposed to be embeddable...

                    Well, as I'm currently struggling to get my bookmarks database (it's
                    really a database, mySQL-based) work better, I might as well come up
                    with a few cool vim macros to add or delete URLs - Is there a way to let
                    vim connect to mysql? :-}

                    (OK, the idea would be to do some "mysqldump" of all the URLs, put those
                    in a file, edit that file, and on :w, just put the data back in tha
                    database)

                    OK, now this one gets too silly I think...

                    CU,
                    Thomas

                    --
                    Thomas Köhler Email: jean-luc@... | LCARS - Linux
                    <>< WWW: http://jeanluc-picard.de | for Computers
                    IRC: jeanluc | on All Real
                    PGP public key available from Homepage! | Starships
                  Your message has been successfully submitted and would be delivered to recipients shortly.