Community
    • Login

    Open files with NPP_EXEC then switch to the tab of the first opened file?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 2 Posters 90 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.
    • VTGroupGitHubV
      VTGroupGitHub
      last edited by

      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?

      Vitalii DovganV 1 Reply Last reply Reply Quote 0
      • Vitalii DovganV
        Vitalii Dovgan @VTGroupGitHub
        last edited by

        @VTGroupGitHub
        If I understand you correctly, you need npp_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))
        
        VTGroupGitHubV 1 Reply Last reply Reply Quote 1
        • VTGroupGitHubV
          VTGroupGitHub @Vitalii Dovgan
          last edited by

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

          Vitalii DovganV 1 Reply Last reply Reply Quote 1
          • Vitalii DovganV
            Vitalii Dovgan @VTGroupGitHub
            last edited by

            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.

            Vitalii DovganV 1 Reply Last reply Reply Quote 1
            • Vitalii DovganV
              Vitalii Dovgan @Vitalii Dovgan
              last edited by

              I’ve added this case to the Manual!
              https://d0vgan.github.io/nppexec/?q=4.6.20

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