• Login
Community
  • Login

userDefineLangs for .txt

Scheduled Pinned Locked Moved General Discussion
5 Posts 3 Posters 582 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.
  • K
    kozakmak
    last edited by kozakmak Jun 8, 2022, 1:48 PM Jun 8, 2022, 1:47 PM

    Ho can (already?) made custom .txt like in Akelpad , where latin, cyrillic, numbers and characters are have their own highlight?
    alt text

    P 1 Reply Last reply Jun 8, 2022, 2:12 PM Reply Quote 0
    • P
      PeterJones @kozakmak
      last edited by Jun 8, 2022, 2:12 PM

      @kozakmak ,

      If you create your own User Defined language, and put txt in the User Exts box for that language, Notepad++ will apply the defined highlighting to all .txt files

      Here is an example where I put the word “latin” as red keyword1, the word “cyrillic” as green keyword2, and each individual cyrillic letter I copied from somewhere in magenta-on-yellow keyword3 with “prefix mode” enabled; the “Number” style on the “Comment & Number” tab is set to blue:

      3d9a4057-af61-489b-9d73-0cb1098f17f8-image.png

      Without “prefix mode” being checked, it won’t highlight the cyrillic characters when there are more than one adjacent:

      9b9c86cf-96df-448c-acbc-1a0183c2b9e1-image.png

      Note that, because of the limitations of the UDL parser, if I have a mixed-alphabet “word” like Дabcd, it will highlight the whole thing as keyword3, but if I use a non-keyword3 character as the first character, like abДcd, it will not highlight as keyword3:
      678c5370-3125-4579-9895-0808fe1dcb26-image.png

      If you want more fine-grained control, use @Ekopalypse’s EnhanceAnyLexer plugin (you can install it from Plugins Admin): you don’t even need a UDL for this version: in the EnhanceAnyLexerConfig.ini file (Plugins > Enhance Any Lexer > Open Configuration file), just add a section at the end and save it:

      [Normal text]
      0xFFFF00 = [АА́А̀БВГҐДЂЃЕЀЁЄЖЗЗ́ЅИІЇИ́ЍЙЈКЛЉМНЊОŌПРСС́ТЋЌУӮЎФХЦЧЏШЩЪЫЬЭЮЯ]
      0xFF0000 = [+-]?\d*\.?\d+
      

      This will highlight any of those cyrillic characters as cyan and a variety of numeric formats as blue:
      8ed01ce3-30b1-4586-817f-9c72e3386657-image.png

      You can add as many regex rules as you want for any lexer (normal text, builtin lexer, or UDL)

      Ekopalypse’s plugin is awesome!

      K 1 Reply Last reply Jun 8, 2022, 2:33 PM Reply Quote 2
      • K
        kozakmak @PeterJones
        last edited by Jun 8, 2022, 2:33 PM

        okey, I tried through EnhanceAnyLexerConfig and it works
        BUT! features of different themes are not taken into account, for example, dark and light
        green is always green

        E P 2 Replies Last reply Jun 8, 2022, 2:38 PM Reply Quote 0
        • E
          Ekopalypse @kozakmak
          last edited by Jun 8, 2022, 2:38 PM

          @kozakmak

          The answer is simple: currently there is no official way to determine the theme used and their colors, and therefore a plugin does not know which color to assign to which “theme color”.

          @PeterJones - thx for the kind words.

          1 Reply Last reply Reply Quote 2
          • P
            PeterJones @kozakmak
            last edited by Jun 8, 2022, 3:04 PM

            @kozakmak said in userDefineLangs for .txt:

            BUT! features of different themes are not taken into account, for example, dark and light

            Out of curiosity, do you really change themes or light/dark that often? Everyone I know just picks their favorite theme and just leaves it like that for normal usage. If you have a use case (other than the few minutes, hours, or days required to say, “no, I like theme/mode X better than theme/mode Y”) where you frequently change themes or light/dark, I’d love to hear it… because I’ve occasionally seen people complain about things not following theme/mode changes, but whenever I’ve asked for a use case where changing is necessary, I’ve never seen a reason that makes sense to me: maybe you will be the first. (And if I know of use cases where it’s important, either I can figure out workarounds in such situations, or if it makes sense, I could start lobbying the developers to expose new API that will give information about the theme – the Dark-vs-Light mode is now in the API, thankfully)

            If you aren’t changing themes or light/dark modes, then just put in the colors that work well with your theme. If you are changing themes often, then as Ekopalypse says, there isn’t a way for the plugin to know what theme you are using for now, so you’ll unfortunately have to live with that mild annoyance of editing and saving the EnhanceAnyLexer config whenever you do change theme. (If you are changing themes enough that it goes beyond mild annoyance, maybe you should consider which is a higher priority to you: changing themes, or the custom “normal text” highlighting.)

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