zufuliu / notepad4

Notepad4 (Notepad2⨯2, Notepad2++) is a light-weight Scintilla based text editor for Windows with syntax highlighting, code folding, auto-completion and API list for many programming languages and documents, bundled with file browser plugin matepath.
Other
2.42k stars 174 forks source link

Set app environment variables for running 3rd party apps as extensions #758

Open lifenjoiner opened 5 months ago

lifenjoiner commented 5 months ago

Kind of solution for https://github.com/zufuliu/notepad2/issues/259.

For grepWin using a launcher:

  1. Prepare the grepWin. Locate it in D:\grepWin\grepWin_portable.exe for example.
  2. Create a script gw.bat:
    @start D:\grepWin\grepWin_portable.exe /content /searchpath:"%cd%"
  3. Config the command line of grepWin editor setting to notepad2 /g %line% %path%.
  4. Ctrl + R --> gw, search or replace.
  5. Double click the search result will locate the line in notepad2.

For ripgrep:

  1. Locate rg.exe in the same directory as notepad2.
  2. Ctrl + R --> cmd --> rg.

N2Root is in case of there is the same name files in the directory of the opened file and notepad2, it can be used as a short and unique prefix.

zufuliu commented 5 months ago

There is no use of N2Root and modify PATH isn't good. When integrating 3rd tools, we can find their executable from

  1. GetProgramRealPath(), same directory as Notepad2.exe.
  2. GetModuleFileName(), same directory as symbolic link to Notepad2.exe.
  3. SearchPath()
lifenjoiner commented 5 months ago

The key logic is launching other files in the order of: dir of the opened file (current dir) --> dir of notepad2 --> systerm path. I tried getting the dir of notepad2 dynamically, and then implement the logic. But, I did not manage it as simple as this, if dir of notepad2 is not added at the head of PATH.

Modified environment variables only have the lifetime in the current progress and its descendants. It won't be a problem.

Without N2Root, what if there is rg.bat/rg.exe/rg.js in dir of the opened file, and also in the dir of notepad2? Isn't %N2Root%\rg simpler?

lifenjoiner commented 5 months ago

Reasons to modify Path:

  1. The path searching order is: current dir --> Path. And we should insert dir of notepad2 between them.
  2. CLI tools. The designed "Ctrl + R --> cmd --> rg" won't be possible, if don't modify Path.
zufuliu commented 5 months ago

delayed this until there is real usage for the changes.