• Login
Community
  • Login

Same opening character but different closing character in a UDL?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 142 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F
    Francesco Notarianni
    last edited by Jan 8, 2025, 12:09 PM

    I want to style the lines that begin with “-” and end with “;” as yellow, and the lines that begin with “-” but end with “:” as bold and italics.

    Somehow that doesn’t seem to work, not even tinkering with the nesting option for both styles:

    bd1f3357-8078-48ab-b84c-4cce4abb8311-image.png

    What do I have to do?

    P 1 Reply Last reply Jan 8, 2025, 2:22 PM Reply Quote 1
    • P
      PeterJones @Francesco Notarianni
      last edited by PeterJones Jan 8, 2025, 2:26 PM Jan 8, 2025, 2:22 PM

      Somehow that doesn’t seem to work, not even tinkering with the nesting option for both styles:

      I believe the underlying logic in the UDL parser for Delimiters goes through the OPEN for each DELIMITER# until it finds a matching one, at which point it switches to that style, whether or not it finds the matching CLOSE (because EndOfFile is always a valid CLOSE for delimiters, in the UDL logic) – it’s not looking for the OPEN/CLOSE pair, but just for the OPEN.

      Thus, if Delimiter1 and Delimiter2 both use the same OPEN, it will always choose Delimiter1.

      If you could use something like -; as your opening for the yellow, and -: as your opening for bold+italics, or -: for bold+italics and plain - for yellow, then it would be workable (as long as the longer -: was in the lower Delimiter# if you choose the latter pair)…

      Here’s an example with Delimiter1 = -: to : , with Bold+Italic, and Delimiter2 = - to ; with Yellow background (which in my light-mode is more visible; you can of course set colors as you want)

      10a06853-13e4-4020-9a83-00e358f79f98-image.png

      But UDL is not able to do exactly what you described. UDL has a fairly simplistic algorithm for deciding what to color as what; that’s one of the benefits of a full lexer or a Lexer Plugin , because you can do the more complex logic that is beyond the scope of UDL.

      But as a compromise between the ease of UDL and the power of a Lexer Plugin, there’s the middle ground of UDL + EnhanceAnyLexer plugin – that plugin allows you to add foreground color (but not bold/italic/underline, yet) to any lexer using regular expressions.

      It still won’t be exactly what you claimed, but if you’re willing to have yellow+bold+italic instead of just yellow, then I would suggest Delimiter1 = - to ((EOL)) with bold+italics, and then use EnhanceAnyLexer to add the definition 0x00CCCC = -.*?;\h*$ , which will end up looking like:
      16ac7be3-82cc-478f-a7b2-e97d61f86da8-image.png
      … which might be close enough for your needs.

      If your UDL is called FrancescoUdl, then the header that EnhanceAnyLexer will create in EnhanceAnyLexerConfig.ini will be [FrancescoUdl] instead of [udf] in my example – doing Plugin > EnhanceAnyLexer > Enhance current language will always create or jump to the appropriate [languageHeader] section in the config file; mine was called [udf] because that’s the underlying name if you choose Language == User-Defined at the end of the Language Menu

      And until you are trying to add extra logic about where EnhanceAnyLexer will or will not apply a given color=regex definition, I recommend always commenting out the excluded_styles row using the ; prefix, as shown (it defaults to excluding most styles, which is may be confusing to a new user)

      F 1 Reply Last reply Jan 8, 2025, 2:52 PM Reply Quote 4
      • F
        Francesco Notarianni @PeterJones
        last edited by Jan 8, 2025, 2:52 PM

        @PeterJones
        Thanks, I have changed the beginning of line character for now, since it seemed the easiest thing to do. I will definitely look into the Lexer plugins, they seem interesting.
        I was doing all this to basically create an UDL that automatically styles lists, with some basic options for done/to do/doing options.
        Do you think it would be something useful to share with the rest of the community?

        P 1 Reply Last reply Jan 8, 2025, 3:00 PM Reply Quote 2
        • P
          PeterJones @Francesco Notarianni
          last edited by Jan 8, 2025, 3:00 PM

          Do you think it would be something useful to share with the rest of the community?

          There is a TODO.txt UDL in the User Defined Languages Collection already; and if you have a different angle-of-attack for lists/todo/done choices, it would be reasonable to share it as another UDL in that Collection, to give people more options.

          1 Reply Last reply Reply Quote 3
          2 out of 4
          • First post
            2/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors