Open files with NPP_EXEC then switch to the tab of the first opened file?
-
I have an NPP_EXEC script tied to a Customize Toolbar button that opens a set of files using NPP_OPEN. The files are opened in a specific order. But after they’re all open, I want focus to switch to the first tab (the first file opened), not left on the last tab (the last file opened). Nothing the internet has suggested will switch the tab for me. Is there a command I’ve missed to do that?
-
@VTGroupGitHub
If I understand you correctly, you neednpp_switch
:set local firstFileToOpen = path_to_the_first_file_to_open // now opening the files via npp_open npp_switch $(firstFileToOpen)
If, however, you don’t know the firstFileToOpen in advance - for example, if npp_open uses a file mask, you can remember the number of opened files before npp_open and then switch to the number+1 document after npp_open:
// 1. remembering num_opened_files npp_sendmsg NPPM_GETCURRENTSCINTILLA 0 @0 set local view ~ $(MSG_LPARAM) + 1 npp_sendmsg NPPM_GETNBOPENFILES 0 $(view) set local num_opened_files = $(MSG_RESULT) // 2. calling npp_open // ... // 3. switching to a (num_opened_files + 1)th document set local file_idx ~ $(num_opened_files) + 1 npp_switch $(#$(file_idx))
-
@Vitalii-Dovgan said in Open files with NPP_EXEC then switch to the tab of the first opened file?:
npp_switch $(firstFileToOpen)
Thank you! That’s exactly what I was looking for.
And I really thought after reading your reply that I’d tried that one already, but since it’s now working, I must have missed it.
Thank you again.
-
Just for information,
npp_switch $(#$(file_idx))
becomes e.g.npp_switch $(#5)
when$(file_idx) = 5
.
This trick is called “indirect variable reference, e.g. $($(name))” and was added in NppExec v0.6.2. -
I’ve added this case to the Manual!
https://d0vgan.github.io/nppexec/?q=4.6.20