Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Command Line Usage #11

Closed
pidgeon777 opened this issue Sep 28, 2021 · 14 comments
Closed

[Feature] Command Line Usage #11

pidgeon777 opened this issue Sep 28, 2021 · 14 comments
Labels
enhancement New feature or request

Comments

@pidgeon777
Copy link

Is there any way to implement some kind of command line?

The idea would be to be able to open a file in Notepad++ by specifying the wanted line and column (byte) position.

@shriprem
Copy link
Owner

@pidgeon777, you may already be aware that Notepad++ has command prompt options that achieve this without using the Goto-Line-Col-NPP plugin.

Just to recap, opening a file with, for example:
<Your_NPP_Folder_path>\notepad++.exe <Your_Text_File> -n148 -c861
will open your text file at line 148 and column 861.

You can find all command line options for NPP at: https://npp-user-manual.org/docs/command-prompt/

Of course, the NPP command line option for column navigation does not handle TAB and Unicode characters in the more sophisticated manner that Goto-Line-Col-NPP plugin does. Even then, it will still navigate to the correct line and the vicinity of the intended column position. So this should suffice for most text files.

@pidgeon777
Copy link
Author

pidgeon777 commented Sep 28, 2021

Thanks for the prompt reply.

You're right, but I was trying to look for a way to position Notepad++ in a more precise way. Unfortunately, my command-line tool returns column position in bytes, but Notepad++ accepts column numbers taking the width of any eventual Tab character into account.

@shriprem shriprem added the enhancement New feature or request label Oct 1, 2021
@shriprem
Copy link
Owner

shriprem commented Oct 2, 2021

I have implemented the command line options processing in GotoLineCol. In addition to -n and -c NPP native options, it supports 8 other options specific to the plugin. For more info, see: Command Line Options.

Please try the v2.1.0.0 Release and let me know if you find any regressions or new issues. Thanks.

DLL-only manual upgrade of a previously installed version of the plugin

Download the zip file version to match your Notepad++ bitness. Then, either:

  1. In Notepad++, navigate to menu: Settings » Import » Import Plugins... and import the dll file extracted from the zip file.
  2. OR, Extract the GotoLineCol.dll file into the <NPP_Plugins_folder>/GotoLineCol folder to overwrite the existing DLL therein.

@shriprem
Copy link
Owner

shriprem commented Oct 2, 2021

Post Script:
Also, see this Discussions topic: Why the kludgy syntax for the -GLCx options?

@shriprem
Copy link
Owner

shriprem commented Oct 3, 2021

Latest Update: Consolidated GLC Command Line Options has been introduced in the v2.1.1.0 Release.

Please ignore my two previous posts on this issue and try the v2.1.1.0 Release and let me know if you find any regressions or new issues. Thanks!

@pidgeon777
Copy link
Author

pidgeon777 commented Oct 4, 2021

Latest Update: Consolidated GLC Command Line Options has been introduced in the v2.1.1.0 Release.

Please ignore my two previous posts on this issue and try the v2.1.1.0 Release and let me know if you find any regressions or new issues. Thanks!

Tried it with this command:

notepad++ "C:\Work\Test\main.c" -n331 -c7 -z -GLCb1

Unfortunately, the caret still doesn't get positioned at the proper byte (column) position. In short, it has the same effect as this command, with no GotoLineCol custom switch:

notepad++ "C:\Work\Test\main.c" -n331 -c7

Tested with Notepad++ v8.1.5 32bit on Windows 10 x64 Pro.

@shriprem
Copy link
Owner

shriprem commented Oct 4, 2021

@pidgeon777, the -GLC option should work. I have tested it with x64 & x86 versions, and portable & installed versions of NPP.

Sample command used for byte column positioning (b is 1):
"E:\Portable\Notepad++ - x86\notepad++.exe" Test_0928.txt -n90 -c632 -z -GLCb1;c1;d1;e18;f1;h1;p1;q1
Output:
image

Sample command used for char column column positioning (b is now 0):
"E:\Portable\Notepad++ - x86\notepad++.exe" Test_0928.txt -n90 -c632 -z -GLCb0;c1;d1;e18;f1;h1;p1;q1
Output:
image

[In my NPP, the TAB is set at 3 spaces. Hence a shift of two chars between byte and char column positions.]

If the GLC option is not working for you, check for these:

  1. Is the version 2.1.1.0 of the GotoLineCol plugin installed? Check this with the menu option Plugins » Goto Line, Column » About.

  2. You have not used the q sub-option in your command. Either include q1 sub-option under GLC. Or ensure that the GotoLineCol side panel is visible and at the forefront. Even if is is open, but any other NPP panel like Character Panel or Clipboard History or another plugin panel is at the forefront, the GLC panel will count as being invisible and the GLC sub-options may not work. Therefore, use the q1 option as a fail-safe.

I also recommend that you include the d1;f1;h1 sub-options. You should then see the call tip, the caret flashing in block mode for a second, and the destination character getting highlighted. These visual confirmations will attest that the GLC option is working fine.

@pidgeon777
Copy link
Author

pidgeon777 commented Oct 5, 2021

I just did a test with this command:

notepad++ "C:\Work\test.c" -n87 -c24 -z -GLCb1;c1;d1;e18;f1;h1;p1;q1

The curious thing is that no call tip appeared, also the plugin itself after the jump reported a position that was coherent with the resulting Notepad++ position, but differed from the wanted byte position:

image

I specified byte 24 in my command line, but the plugin reported that it jumped to byte 18, instead (see the circle mark).

Also, the cursor has been wrongly positioned to the 24th horizontal char, as if the -b1 option didn't make any effect.

This is confirmed also by the fact that none of the GLC options had any effect (no call tip was shown and so on), even if I added them to my command line.

So, the problem unfortunately seems to be still there.

I configured my tab size to 4 spaces, and GLC version is 2.1.1.0.

@shriprem
Copy link
Owner

shriprem commented Oct 5, 2021

You haven't confirmed if you have updated the GotoLineColumn DLL. I had this query in my previous post:

  1. Is the version 2.1.1.0 of the GotoLineCol plugin installed? Check this with the menu option Plugins » Goto Line, Column » About.

I reiterate that I have tested it with single & multiple files; x64 & x86 versions; and portable & installed versions of NPP. So, I strongly suspect that you still have the version of GLC DLL that gets installed with the NPP's Plugins Admin. That would be GLC v2.0.0.0 which doesn't process any command line options.

If you have updated the GLC DLL, you should see this GLC » About message box:
image

If you are not seeing a matching version number and build timestamp, then use the instructions below to update the DLL.

DLL-only manual upgrade of a previously installed version of the plugin

Go to the v2.1.1.0 Release page. Download the zip file version to match your Notepad++ bitness. Then, either:

  1. In Notepad++, navigate to menu: Settings » Import » Import Plugins... and import the dll file extracted from the zip file.
  2. OR, Extract the GotoLineCol.dll file into the <NPP_Plugins_folder>/GotoLineCol folder to overwrite the existing DLL therein.

@pidgeon777
Copy link
Author

pidgeon777 commented Oct 5, 2021

My fault, for some reasons the info you asked for was missing from my post. Here is my GLC version:

image

Am I wrong or we're using two different Windows OS?

@shriprem
Copy link
Owner

shriprem commented Oct 5, 2021

The plugin is not able to see your command line options. That is why it is not processing the byte positioning switch or any of the other visual action switches.

This could happen if an NPP process was already running before you issued the command line options. So, check for these possibilities:

  1. If NPP is already running, close it before launching via the command line options.
  2. Your NPP may have been configured to minimize to system tray. If so, you should disable this setting. Go to NPP menu: Settings » Preferences » MISC. Here, ensure that the Minimize to system tray box is unchecked.

You can also try including the -multiInst option in your command line so that NPP always launches in a new process.

The fresh NPP process requirement is not a deficiency of the GLC plugin. Even Microsoft SysInternal's venerable Process Explorer utility is unable to see the command line parameters if you were to issue a fresh set of command line options when an NPP instance is already running or hidden in the system tray.

If you have complied with the two checks listed above and the GLC is still not processing your command line options, please run this extra Process Explorer check before replying back to my post:

  1. If you don't already have Process Explorer, download it from the Microsoft SysInternals page. Note that this tiny utility requires no installation. Just download the zip file, extract the executable to your Desktop, and you can launch it from there.
  2. Now, issue the command line options for NPP/GLC after ensuring no prior instance of NPP was running or hidden in systray.
  3. Now, in Process Explorer, hover over the NPP entry. Confirm that you are be able to see the options you issued from the command line. Somewhat like this:
    image

The GLC plugin uses the GetCommandLine WINAPI. The command line reported by this API is the command line used to invoke the original NPP process; and will not include a fresh set of command line options used to reinvoke the same NPP process.

@pidgeon777
Copy link
Author

Thanks for the explanation.

At this point, I suppose my issue is due to the fact that I'm trying to browse my source code by keeping my instance of Notepad++ always active. I didn't know Notepad++ had to be closed every time, before issuing the GLC command.

It is a pity because loading a new Notepad++ instance every time have two big disadvantages:

  • It could lead to big resources usage and slowness overall (especially with many plugins loaded).
  • It would make quick code navigation impossible.

I suppose the only way to fix this, would be to ask Notepad++ developers to hardcode your plugin or part of it in the next Notepad++ release, then.

@shriprem
Copy link
Owner

shriprem commented Oct 6, 2021

@pidgeon777, Alternatively, we need NPP to add a new NPM_xxx message to its API that will provide plugin writers with the new command line text used to re-invoke an existing NPP process.

Firstly, as sort of an addendum to my previous post, I will list two other ways to view the Initial NPP Command Line:

  1. Use the PythonScript plugin console and execute: notepad.getCommandLine(). This will only report the original command line used to invoke the initial NPP process. This is since PythonScript also uses GetCommandLine Windows API.
    image

  2. In Notepad++, use menu: ? » Debug Info... This too will only report the original command line to invoke the initial NPP process.

So, how does NPP manage to open new files when re-invoked, and process fresh command line options? Here is how:

Actually, when NPP is re-invoked, a new NPP process is started. This new process captures the new command line via its wWinMain function (file: notepad-plus-plue/PowerEditor/src/winmain.cpp). Note that NPP is not using the GetCommandLine Windows API at all.

Within winmain.cpp, there is a check for multi-instance and initial process: if ((!isMultiInst) && (!TheFirstOne)).

From within this if block, two WM_COPYDATA messages are sent out from this new NPP process to the existing, initial NPP process. One message contains a list of the new command line options, and the other one a list of the file names specified for this fresh NPP invocation. After this, the new, not-yet-visible NPP process will terminate.

The initial NPP process will use these two messages to open new files and process any fresh command line options that came along with it.

For our purposes here, we will need NPP to store the information from these two messages and make them available to the plugins via a new NPPM_xxx message call.

@shriprem
Copy link
Owner

This feature request has been implemented with this commit: Implemented -pluginMessage="GLCb1..." command line option for NPP 8.4.2.

This feature is available with the GotoLineCol 2.4.0.0 Release. If you are testing this, please make sure you are using it with the Notepad++ 8.4.2 version. See: Notepad++ v8.4.2 Release Candidate 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants