• Login
Community
  • Login

text-highlight file extensions

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 3 Posters 571 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.
  • C
    criga76
    last edited by Feb 7, 2022, 5:50 AM

    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

    P R 2 Replies Last reply Feb 7, 2022, 1:56 PM Reply Quote 0
    • P
      PeterJones @criga76
      last edited by Feb 7, 2022, 1:56 PM

      @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)

      C 1 Reply Last reply Feb 7, 2022, 2:06 PM Reply Quote 2
      • C
        criga76 @PeterJones
        last edited by Feb 7, 2022, 2:06 PM

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

        1 Reply Last reply Reply Quote 0
        • R
          rdipardo @criga76
          last edited by Feb 7, 2022, 10:41 PM

          @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

          C 1 Reply Last reply Feb 8, 2022, 4:25 AM Reply Quote 2
          • C
            criga76 @rdipardo
            last edited by Feb 8, 2022, 4:25 AM

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

            R 1 Reply Last reply Feb 8, 2022, 5:00 AM Reply Quote 0
            • R
              rdipardo @criga76
              last edited by Feb 8, 2022, 5:00 AM

              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
              2 out of 6
              • First post
                2/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors