d0vgan / nppexec

NppExec (plugin for Notepad++)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NppExecScript echo newline, npe_cmdalias, con_colour, and con_filter

David-Maisonave opened this issue · comments

1. In my NppExec script, I'm trying to do a single echo with new line, but I can't seem to get it to work.

The reason I need to use a single echo, is because I'm setting a npe_cmdalias key, in which I want it to list the available commands for the script.
Here's an example:
npe_cmdalias ? =echo Console-shortcuts\nR=Run Script\ns=shows all local variables\nh=show NppExec console commands\n!=Show all console commands in detail
In a normal DOS console the following two methods works for producing new lines in a single echo:

echo Method 1
echo R=Run cmd /c ("E:\_Dev\Scripts\NppTest\_WorkingScripts_\ValidScripts\HelloWorld.cmd")&echo\ run=Run cmd /c ("E:\_Dev\Scripts\NppTest\_WorkingScripts_\ValidScripts\HelloWorld.cmd")&echo\ h=show NppExec console commands&echo\ !=Show all console commands in detail

echo Method 2
setlocal EnableDelayedExpansion
(
set \n=^
%=Don't remove this line=%
)
echo R=Run cmd /c ("E:\_Dev\Scripts\NppTest\_WorkingScripts_\ValidScripts\HelloWorld.cmd");!\n! run=Run cmd /c ("E:\_Dev\Scripts\NppTest\_WorkingScripts_\ValidScripts\HelloWorld.cmd");!\n! h=show NppExec console commands;!\n! !=Show all console commands in detail

I can't get any of these methods to work in the script.

  • Is there a way to include new line character in an echo for the NppExec console?

2. I created an alias for help and help all

  npe_cmdalias h =help
  npe_cmdalias ! =help all

The h command works with no problem, but when I try using !, I get the following error:
This command is not supported by the help utility. Try "all /?".

  • Is there a way to get [help all] to work with alias key?

3. Setting color to blue, before issuing the Execute command.

I put this at the top of the script:con_colour fg = 0000FF
Right before I issue the Execute command, i reset the color con_colour fg = 0
I expected that all the output before the execute command would be in blue text, but instead it's being display in green.

  • Does this setting only effect the output from the execute command?
  • If so, is there a way to change the green color from the script?

4. con_filter not working.

I prefixed the output shortcut key with "Console-shortcuts", and created a highlight for it, but it's not working.

set Highlight10 = Console-shortcuts*
set Include5 = *
con_filter +i5 +h10

But the line never gets highlighted. I even tried sending a line in a batch file with the keyword, but it still failed to highlight.

  • Am I doing something wrong?
  • How do I set the color to a specific highlight number?

Another question.
For NppExec scripts, is there a way to use "or" in an if statement? if $(ext) == .bat or $(ext) == .cmd

  1. You may use set local s ~ strunescape Line1\nLine2\nLine3 to produce a string that contains new lines.
    Then just pass $(s) to a desired command.

  2. The commands "help", "help all", "help <command>" work only when they are directly typed in NppExec's Console. I.e. the internal NppExec Script Engine does not recognize these commands.

  3. Here is how con_colour works:

con_colour fg = 0000FF // blue
cmd /c echo Test // this is in blue
  1. con_filter
    Could it be that you forgot to specify $(Highlight10) as the 10th Highlight filter in the Console Filters dialog?

  2. or in IF statement
    No, or is not supported.

  1. That solution works great. Thank you. I thought I tried something like that.
  2. Got it.
  3. But any output from the script is still displayed in green.
  4. You're right, I didn't set the color in the Filters dialog. However, after setting the color, it still didn't work in the script. The scrip was not able to change the value for the highlight string. set Highlight10 = Console-shortcuts*
  5. Can or/and support get added to the script?

I would like to add the functionality myself, along with other settings not yet available through the script.
Can I add the following to NppExecEngine?
con_highlight (id) (value) (rgb) (IBU) //Allow scripts to use 11-20 so it doesn't interfere with user GUI settings.
con_custom_msg_ready (value to set or empty string to disable) // Should only effect running script
con_colour_msg (rgb) // Should only effect running script
con_colour_err (rgb) // Should only effect running script
con_colour_bkgrnd (rgb) // Should only effect running script
con_exclude_empty (0/1) // Should only effect running script
con_exclude_dup (0/1) // Should only effect running script

FYI:
Americans spell it color, and most other English speaking countries spell it colour. Even my spell checker flags colour as misspelled.
I'm just curious if you picked the name "con_colour".

While adding new commands, be sure to follow the steps described under // For each of the Do-methods inside the "NppExec\src\NppExecEngine.h".
Also, con_colour_... commands may be tricky in implementation since they invoke methods of CNppExecConsole which supports postponed output (the postponed changes are not applied right now, but are postponed to be applied later). As an example, you may look at CNppExecConsole::SetCurrentColorTextNorm.
The CScriptEngine supports both spellings: CON_COLOUR and CON_COLOR. See the DoConColourCommand for details.

By the way, I believe the existing command con_colour can be enhanced to set the message and error colour, e.g.
con_colour msg = ...
con_colour err = ...
as well as
con_colour local err = ... msg = ...
so separate commands con_colour_msg and con_colour_err will not be needed for this.
Also, con_colour already supports con_colour local bg = ... that seems to do what con_colour_bkgrnd is intended to do.

I've also played a bit with the regex-driven WarningAnalyzer - pretty good job!
For example, it detects both output from cmd /c echo error in file c:\aaa.txt line 123 and from cmd /c echo error in file c:\aaa.txt : 123.
When talking about a relative file path, such as cmd /c echo error in file aaa.txt : 123, it is not detected. Is it intended? I believe some compilers/interpreters use relative file paths.
Also I tried cmd /c echo error in file c:\aaa.txt line: 123 and the "line:" part does not seem to be recognized.
By the way, do you know that npe_debug 1 typed in NppExec's Console also reacts on double-click within the Console, thus allowing to "debug" the work of the WarningAnalyzer?

The only two compilers (C# & Go) I found that used the file name only, had the file name at the start of the line.
Try it like this: cmd /c echo HelloWorld.cpp : 123

It does pickup relative path. The LUA compiler used relative path. It produced errors like the following:
C:\Program Files\Lua\lua54.exe: ...NppTest\_WorkingScripts_\BadHelloWorld\BadHelloWorld.lua:5: unexpected symbol near ')'
Try the following:

cmd /c echo C:\Program Files\Lua\lua54.exe: ...MyProject\aaa.txt : 123
cmd /c echo C:\Program Files\Lua\lua54.exe: ...\MyDocuments\MyProject\aaa.txt : 123
cmd /c echo C:\Program Files\Lua\lua54.exe: MyProject\aaa.txt : 123
cmd /c echo C:\Program Files\Lua\lua54.exe: aaa.txt : 123

If you have the file open, double clicking the error will take you to the line number error.
With relative paths, you have to have the file open in order for it to go to file and line number.

On another update, I plan to add logic that will help it get the full path from the relative path if the currently opened file is in the same file path.

Compilers having line before the number, did not have a colon, or anything between the word "line" and the number.
Here's how Python reports the error:

  File "E:\_Dev\Scripts\NppTest\_WorkingScripts_\BadHelloWorld\BadHelloWorld.py", line 8, in <module>
  File "E:\_Dev\Scripts\NppTest\_WorkingScripts_\BadHelloWorld\BadHelloWorld.py", line 5, in main

You can test that via following:

cmd /c echo File "E:\myproject\aaa.txt", line 5
cmd /c echo File E:\myproject\aaa.txt line 5

FYI:
I tested 26 programming languages, and a few didn't display the error file name and line number.
The regex code works on all 21 which produced file names and line numbers.

My goal is to have the NppExec script work on at least 50 programming languages, and for the regex code to support any of the 50 which produce errors with file names.

I just realized there's a bug in the code! It's supposed to pickup the line position.

cmd /c echo File E:\myproject\aaa.txt:5:9:
cmd /c echo File E:\myproject\aaa.txt:5 char:41

That was working before. I'm checking now to see what happen to break it.

Fixed it!
Some how extra spaces got added when I moved the regex statement to a member variable.
With the updated code you can double click on lines having position indicators and it should move the cursor to the line and line position. You can test it with the following:

cmd /c echo aaa.txt:5:10
cmd /c echo E:\_Dev\DummyProject\aaa.txt:3:15:
cmd /c echo File E:\_Dev\DummyProject\aaa.txt:2 char:8
cmd /c echo File .\DummyProject\aaa.txt:8:15: error:
cmd /c echo File ...\_Dev\DummyProject\aaa.txt line 10 char:25
cmd /c echo gawk: ...\_Dev\DummyProject\aaa.txt:5:    print(foofoo)&echo gawk: ...\_Dev\DummyProject\aaa.txt:5:         ^^
cmd /c echo  E:\_Dev\DummyProject\aaa.txt:2: syntax error&echo ...       ^^
cmd /c echo  E:\_Dev\DummyProject\aaa.txt:8: syntax error&echo               ~

You'll notice the last 3 test have no line position numbers. Some compilers report the error position by using "^" or "~" to place the line position indicator under the position of the previous output that displays a line of code. It usually doesn't line up in the console display, because of the font. But that doesn't stop the code form using this information to get the line position indicator.

I notice while testing this, that if I paste several "cmd /c" to the NppExec console and press enter, only the last command gets executed and/or displayed on the screen.
Is that expected behavior?

Regarding multiple lines pasted to NppExec's Console, it is a known limitation that only the last line is processed.
I was thinking about supporting of multi-line pasting and even created a roadmap for that. Currently this roadmap is not available because my PC can't start (so I'm using a laptop), but, in short, there are two directions to be implemented:

  • multi-line pasting when a console process is running: these lines go to the process'es input;
  • multi-line pasting while no console process is running: these lines go to a new NppExec script. This latter case requires more deep changes, but for the moment I can't recall what are the exact challenges there.

Thanks for your help.
I'm closing this, and I'll follow-up when needed on a new item.