Community
    • Login

    text-highlight file extensions

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 516 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.
    • criga76C
      criga76
      last edited by

      I’m trying to highlight file extensions, e.g.
      ./data/layers_elevations/L5.asc

      I tried a keyword list, but adding asc doesn’t do it, likely because it’s not a separate word, but part of a string.

      I tried a delimiter as well:
      open . | close ((EOL))
      which

      • didn’t just highlight the extension but the entire line (since it starts with a ‘current folder’ period) - I could live with that.
      • highlighted the period and decimals in numbers which overwrote the number highlighting that I had already set

      is there a way to achieve that?

      thanks, Chris

      PeterJonesP rdipardoR 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @criga76
        last edited by

        @criga76 said in text-highlight file extensions:

        is there a way to achieve that?

        There’s not a built-in way using User Defined Language (UDL) alone, because it doesn’t accept regular expressions. However, you can add extra highlighting to a UDL using regexes via the PythonScript plugin in conjunction with the script EnhanceAnyLexer.py that @Ekopalypse shares in his github repo – doing an expression like r'\.[a-zA-Z]\w*' should look for a dot, followed by a letter, followed by one or more word characters (by doing the letter first, that guarantees it won’t find the decimal parts of numbers when looking for extensions, though it is technically possible for extensions to be .123)

        criga76C 1 Reply Last reply Reply Quote 2
        • criga76C
          criga76 @PeterJones
          last edited by

          Thanks @peterjones
          RegExes would be handy addition, but I’ll try your suggested for now.
          Chris

          1 Reply Last reply Reply Quote 0
          • rdipardoR
            rdipardo @criga76
            last edited by

            @criga76,

            I tried a keyword list, but adding asc doesn’t do it, likely because it’s not a separate word, but part of a string.

            An undocumented fact about the “Operators 1” group is that word characters work just fine, and you can cluster them as if they were keywords [^1], so maybe something like this would suit your use case:

            <Keywords name="Operators1">. asc bin txt <!-- more extensions --> </Keywords>
            

            file_ext_hl.png

            [^1]: I’m purposely contradicting Ivan Radić in his own UDL docs regarding operators:

            In short: [“Operators 1” elements] should be special non-alphanumeric characters

            Whereas,

            Operators2 group is just another keyword group, Keyword group 9 if you will.

            The distinction is not actually enforced by LexUser, a useful bug that allowed me, for example, to design a Vim script UDL that highlights variable scope prefixes: g:, s:, etc., by (ab)using Operators1 elements:

            abbot.vim.png

            criga76C 1 Reply Last reply Reply Quote 2
            • criga76C
              criga76 @rdipardo
              last edited by

              @rdipardo
              from everything I’ve tried, it messes with number highlighting as they share the period with file extension :-(

              rdipardoR 1 Reply Last reply Reply Quote 0
              • rdipardoR
                rdipardo @criga76
                last edited by

                It might work better if you prefix every extension with a dot (and get rid of the free-standing dot):

                <Keywords name="Operators1">.txt .asc .bin</Keywords>
                

                That seems to force an exact match:

                file_ext_hl_edit.png

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