I was wondering whether NppExec already allow, for example, to open a file "C:\Program Files (x86)\Notepad++\change.log" when a text "Notepad++\change.log" is selected in the editor.
NppExec does allow this!
Here is NppExec's script required for this (please see the embedded comments for clarifications):
NPP_CONSOLE?// process the selected text...SCI_SENDMSGSCI_GETSELTEXT0@""setlocalF=$(MSG_LPARAM)if"$(F)"==""gotoDone// no selected text// check current file name...setlocaln~strfind"$(FILE_NAME)""$(F)"if$(n)!=-1gotoDone// current file name contains the selected text// check opened files...setlocalprev_fpath=$(FULL_CURRENT_PATH)NPP_SWITCH$(F)if"$(FULL_CURRENT_PATH)"!="$(prev_fpath)"gotoDone// switched to another opened file// check predefined directories...NPE_CONSOLEv+--C:\tools\findfile.bat"$(F)"if"$(OUTPUTL)"==""gotoOpensetlocalF=$(OUTPUTL)// found in a predefined dirgotoOpen:OpenNPE_CONSOLEv---NPP_OPEN$(F):Done
This NppExec's script uses external file "C:\tools\findfile.bat" which describes the set of predefined directories to be checked.
Here is the content of this "findfile.bat":
@echo off
for /D %%d in (
"C:",
"C:\Program Files",
"C:\Program Files (x86)"
) do (
if exist "%%~d\%~1" (
call :EchoUnquotedString "%%~d\%~1"
)
)
goto End
:EchoUnquotedString
echo %~1
goto End
:End
The predefined directories in this example are ( "C:", C:\Program Files", "C:\Program Files (x86)" ).
Define your own set of directories here.
Here is how it works:
1) The NppExec's statement
C:\tools\findfile.bat "$(F)"
invokes the external batch file, passing the selected text as an argument to it;
2) (Inside of "C:\tools\findfile.bat") When "%%~d\%~1" exists, its full path is printed to the console output;
3) Then NppExec's statement
if "$(OUTPUTL)" == "" goto Open
verifies whether the output from "C:\tools\findfile.bat" is empty or not;
4) If it is not empty, we take $(OUTPUTL) as the file name to be opened:
set local F = $(OUTPUTL) // found in a predefined dir
5) Finally, the file is opened by
NPP_OPEN $(F)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
High DV,
thank you very much for this script. I've done some modification to use git list file command inside a repository (git ls-files -- file_name ). It works perfectly fine.
I used "if <condition> goto <label>" command but I'd like to have a new command :
"if <condition> then <action_if_true> else <action_if_false>"
With this command, script would be easily written.
Thanks for your script
Christophe
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
From NppExec v0.6 alpha 1, the same script can look like the following:
NPP_CONSOLE?// process the selected text...SCI_SENDMSGSCI_GETSELTEXT0@""setlocalF=$(MSG_LPARAM)// the selected textif"$(F)"!=""then// something selected// check current file name...setlocaln~strfind"$(FILE_NAME)""$(F)"if$(n)==-1then// current file name does not contain the selected text// check already opened files...setlocalprev_fpath=$(FULL_CURRENT_PATH)NPP_CONSOLE-NPP_SWITCH$(F)// try to switch to another fileNPP_CONSOLE+if"$(FULL_CURRENT_PATH)"=="$(prev_fpath)"then// did not switch to another file// check predefined directories...NPE_CONSOLEv+--C:\tools\findfile.bat"$(F)"if"$(OUTPUTL)"!=""then// found in a predefined dirsetlocalF=$(OUTPUTL)endifNPE_CONSOLEv---NPP_OPEN$(F)endifendifendif
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was wondering whether NppExec already allow, for example, to open a file "C:\Program Files (x86)\Notepad++\change.log" when a text "Notepad++\change.log" is selected in the editor.
NppExec does allow this!
Here is NppExec's script required for this (please see the embedded comments for clarifications):
This NppExec's script uses external file "C:\tools\findfile.bat" which describes the set of predefined directories to be checked.
Here is the content of this "findfile.bat":
The predefined directories in this example are ( "C:", C:\Program Files", "C:\Program Files (x86)" ).
Define your own set of directories here.
Here is how it works:
1) The NppExec's statement
C:\tools\findfile.bat "$(F)"
invokes the external batch file, passing the selected text as an argument to it;
2) (Inside of "C:\tools\findfile.bat") When "%%~d\%~1" exists, its full path is printed to the console output;
3) Then NppExec's statement
if "$(OUTPUTL)" == "" goto Open
verifies whether the output from "C:\tools\findfile.bat" is empty or not;
4) If it is not empty, we take $(OUTPUTL) as the file name to be opened:
set local F = $(OUTPUTL) // found in a predefined dir
5) Finally, the file is opened by
NPP_OPEN $(F)
High DV,
thank you very much for this script. I've done some modification to use git list file command inside a repository (git ls-files -- file_name ). It works perfectly fine.
I used "if <condition> goto <label>" command but I'd like to have a new command :
"if <condition> then <action_if_true> else <action_if_false>"
With this command, script would be easily written.
Thanks for your script
Christophe
From NppExec v0.6 alpha 1, the same script can look like the following: