• Login
Community
  • Login

Syntax Highlightning for folder path in custom language

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
2 Posts 2 Posters 262 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.
  • M
    Mad Rheeza
    last edited by Dec 8, 2023, 3:22 PM

    Hey, i am new in npp and need your help, how can i highlight full folder path in custom language?
    I added " C:\ C:/ E:\ E:/ D:\ D:/ " in keywords lists, and it works only if path without spaces like
    C:\Users\Mad\TextOne.txt
    if i am using path
    C:\Users\Mad\Text Two.txt
    its highlight only C:\Users\Mad\Text

    e32b2cd8-e957-4b8d-b469-873411127ad3-image.png

    P 1 Reply Last reply Dec 8, 2023, 3:47 PM Reply Quote 0
    • P
      PeterJones @Mad Rheeza
      last edited by Dec 8, 2023, 3:47 PM

      @Mad-Rheeza ,

      The User Defined Lanauge (UDL) system is not that powerful on its own.

      If you use the EnhanceAnyLexer plugin, you can use a regular expression to define it.

      But good luck in coming up with a regex that can distinguish between two similar (or identical) sets of text which mean two different things:

      I want to rename c:\path\filename as blah.txt
      I want to rename c:\path\filename as blah.txt
      

      In the first instance, it’s really implying “I want to rename c:\path\filename as blah.txt” to mean a single filename with spaces. The second is really implying “I want to rename c:\path\filename as blah.txt”

      And by “good luck”, I meant, “that’s an impossible task, without caveats”.

      If you have the caveat of “each line that starts with a drive letter then a colon then forward-or-backward-slash is a single filename, which may or may not include spaces, all the way to the end of the line”, then it’s easy. Something like ^[A-Z]:[\\/].*?$ will handle that.

      Or if you defined that all filenames with spaces must have double-quotes around (like the cmd.exe prompt and Windows > Run dialog require), then it’s also not too bad: Something like [A-Z]:[/\\]\S+|"[A-Z]:[/\\].+?" might work (the left half of the alternation before the | is for filenames without spaces, and the right half is for filenames in quotes, which might contain spaces.

      Or if you always have a three-letter extension, then [A-Z]:[/\\].*\.[A-Za-z]{3} would likely work.

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