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

Re: syntax: reusing nested expressions

Expand Messages
  • George V. Reilly
    let + execute. That makes a lot of sense. Thanks /G ... -- /George V. Reilly http://www.georgevreilly.com/blog
    Message 1 of 4 , Feb 3, 2008
    • 0 Attachment
      let + execute. That makes a lot of sense. Thanks
       
      /G

       
      On 03/02/2008, Szabolcs <szhorvat@...> wrote:



      On Feb 3, 7:04 am, "George V. Reilly" <geo...@...> wrote:
      > I'm trying to write some syntax highlighting for PBwiki, and I'd like to
      > reuse some complex regexps.

      Hi,

      I asked the same question recently and got this answer:
      http://groups.google.com/group/vim_use/browse_thread/thread/84f1fa50633c6c50

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

    • George V. Reilly
      ... Szabolcs kindly pointed me towards http://groups.google.com/group/vim_use/browse_thread/thread/84f1fa50633c6c50 where Dr. Chip suggested using a
      Message 2 of 4 , Feb 3, 2008
      • 0 Attachment
        On 02/02/2008, George V. Reilly <george@...> wrote:
        I'm trying to write some syntax highlighting for PBwiki, and I'd like to reuse some complex regexps. Here are some concrete examples:
          http://pbwiki.com  -and-  [http://pbwiki.com/|PBwiki]
          support@...  -and-  [support@...|help me harder!!]

        I have the following redundant expressions:
        syntax match pbwikiLink           `\(https\?\|ftp\|mailto\|file\):\(\(\(//\)\|\(\\\\\)\)*[A-Za-z0-9:#@%/;$~_?+-=.&\-\\\\]*\)`
        syntax match pbwikiLink           `\[\(https\?\|ftp\|mailto\|file\):\(\(\(//\)\|\(\\\\\)\)*[A-Za-z0-9:#@%/;$~_?+-=.&\-\\\\]*\)|[^]].\{-}\]`
        syntax match pbwikiLink           `[A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\{-}\.[A-Za-z]\{2,4}`
        syntax match pbwikiLink           `\[[A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\{-}\.[A-Za-z]\{2,4}|[^]].\{-}\]`

        How do I reuse the URL regexp and the email regexp inside the [<url>|<friendly text>]?

        Szabolcs kindly pointed me towards
        http://groups.google.com/group/vim_use/browse_thread/thread/84f1fa50633c6c50
        where Dr. Chip suggested using a combination of :let and :exe.

        In my case that yields the more legible

        let s:re_url='\(https\?\|ftp\|mailto\|file\):\(\(\(//\)\|\(\\\\\)\)*[A-Za-z0-9:#@%/;$~_?+-=.&\-\\\\]*\)'
        let s:re_email='[A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\+\.[A-Za-z]\{2,5}'
        let s:re_linkname='[^]].\{-}'

        exe 'syntax match pbwikiLink `' . s:re_url . '`'
        exe 'syntax match pbwikiLink `\[' . s:re_url . '|' . s:re_linkname . '\]`'
        exe 'syntax match pbwikiLink `' . s:re_email . '`'
        exe 'syntax match pbwikiLink `\[' . s:re_email . '|' . s:re_linkname . '\]`'
        --
        /George V. Reilly
        http://www.georgevreilly.com/blog
        --~--~---------~--~----~------------~-------~--~----~
        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.