I found the place in the code where space is inserted in the comments
-
Re: How to remove the space when commenting lines?
@Willy take a look at this:
https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/Notepad_plus.cpp#L5097I also created an issue, but its been a year and literally everybody ignored it, although, it would be like a few minutes for people that know how to add stuff to Npp preferences to make this feature.
https://github.com/notepad-plus-plus/notepad-plus-plus/issues/11831
At this rate, I’m forced to try and create plug-in that will implement commenting from scratch, and this is a huge time waste. Thank you Npp, community for great help to me and @Willy!
-
@ScienceD said in I found the place in the code where space is inserted in the comments:
I’m forced to try and create plug-in that will implement commenting from scratch, and this is a huge time waste
Better use of your time would be to build the Notepad++ code from source, and change the line of code you’ve identified.
Or, you could script some behavior (which is less effort than a plugin).
-
@Alan-Kilborn I was considering rebuilding Npp, but there is one problem… I will be stuck with this version forever, and I want to update it from time to time. So, this would require to actually make commit request, and it might not get accepted etc., huge pain.
At least plugin should work in every version =
IDK about script… Might bee too complex task for simple scripting =\ -
Actually, why not just use replacements, via macros?
Example for C++ single-line commenting:
Find:
^\h*+(?!$)
Replace:${0}//
Search mode: Regular expression
In selection: checked
IDK about script… Might bee too complex task for simple scripting =\
No, not too difficult.
-
@Alan-Kilborn Actually, I would prefer slightly different RegEx:
Find:
^(\h*+)(?!$)
Rep.://\1
This way it produces this style of comments:
//void printChar(char c, ui64 mod) //{ // static HANDLE oh = GetStdHandle(STD_OUTPUT_HANDLE); // WORD drb = BACKGROUND_RED | FOREGROUND_INTENSITY; // WORD std = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; // if((mod == MOD_L) && diff_mode_l || (mod == MOD_R) && diff_mode_r) // { // switch(c) // { // case 0: // SetConsoleTextAttribute(oh, BACKGROUND_RED); // p|'0'|D; // break; // case '\n':
Which is much better readable when you just want to disable some piece of your code (which is 99% of usecases for the comment/uncomment feature). Like, when you just want to write comment you just type it manually anyway!
What sux, is that I loose one button space because now instead of just “toggle single line comment” I need 2 buttons:
Here is buttons defined in
CustomizeToolbar.btn
file:Macro,COMMENT_LINES,,,,,butts\lcomm.ico Macro,UNCOMMENT_LINES,,,,,butts\undolcomm.ico
-
@ScienceD said in I found the place in the code where space is inserted in the comments:
What sux, is that I loose one button space because now instead of just “toggle single line comment” I need 2 buttons
A small price to pay for all of your cool new functionality!
-
@ScienceD I figured out some major improvements to regex:
COMMENT:
F:^(\h*)(?!$)
R://\1
UNCOMMENT:
F:^\/{2}(\/*)
R:\1
This will allow you to have this kind of nested comments:
// while(1) // { // PeekConsoleInput(ih, ir, 128, &nread); // for(DWORD i = 0; i < nread; ++i) // { // if(ir[i].EventType == MOUSE_EVENT) // { // const MOUSE_EVENT_RECORD* m = &ir[i].Event.MouseEvent; // if(m->dwButtonState == 0x1) // { // COORD pos = m->dwMousePosition; // SetConsoleCursorPosition(oh, pos); // p|'O'|DC; // } //// else if(m->dwButtonState == 0x2) //// { //// hideCursor(); //// ShowWindow(wnd, SW_MINIMIZE); //// hideCursor(); //// } // } // else if(ir[i].EventType == KEY_EVENT) // { // //SetEvent(pause_event); // } // } // }
So that when you uncomment this block, you will save the inner comments:
while(1) { PeekConsoleInput(ih, ir, 128, &nread); for(DWORD i = 0; i < nread; ++i) { if(ir[i].EventType == MOUSE_EVENT) { const MOUSE_EVENT_RECORD* m = &ir[i].Event.MouseEvent; if(m->dwButtonState == 0x1) { COORD pos = m->dwMousePosition; SetConsoleCursorPosition(oh, pos); p|'O'|DC; } // else if(m->dwButtonState == 0x2) // { // hideCursor(); // ShowWindow(wnd, SW_MINIMIZE); // hideCursor(); // } } else if(ir[i].EventType == KEY_EVENT) { //SetEvent(pause_event); } } }
Here is full macro, if you don’t want to record it yourself:
<Macro name="COMMENT_LINES" Ctrl="yes" Alt="yes" Shift="yes" Key="46"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="^(\h*)(?!$)" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="//\1" /> <Action type="3" message="1702" wParam="0" lParam="896" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro> <Macro name="UNCOMMENT_LINES" Ctrl="yes" Alt="yes" Shift="yes" Key="35"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="^\/{2}(\/*)" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1602" wParam="0" lParam="0" sParam="\1" /> <Action type="3" message="1702" wParam="0" lParam="896" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" /> </Macro>
-
@ScienceD said in I found the place in the code where space is inserted in the comments:
^\/{2}(\/*)
Your backslashes here are unnecessary as
/
is not a regex metacharacter; this will suffice:^/{2}(/*)
-
@Alan-Kilborn IDK, I just followed advice of one regex site that said it might result in errors when copy pasting into code:
-
@ScienceD said in I found the place in the code where space is inserted in the comments:
I just followed advice of one regex site
Well you have to be careful who’s advice you follow.
There is a lot of differences in the specific regex flavors that various tools use.
Notepad++ uses the Boost regex engine.No worries, though; escaping something that doesn’t need to be escaped is usually not a problem.
-
@Alan-Kilborn said in I found the place in the code where space is inserted in the comments:
Or, you could script some behavior (which is less effort than a plugin)
Well, I got fed up by the temporal and quick solutions and decided I will go full on onto this problem. It is kind of funny to think that I dumped much larger amount of effort and time into this than anybody in the World would ever do. It took about 6 days of non-stop development to create and polish this plug-in, but, I think, I made the most advanced automatic comment toggler in the world. It was very tricky to make it work right, especially considering that its my first plug-in for Notepad++ and, in fact, any program.
It’s probably even better than Visual Studio one, because it still uses 2 buttons, while mine just 1 (and I also fixed some Visual Studio bugs too, so its better).
Github: https://github.com/ScienceDiscoverer/CommentToggler
The best demonstration is to show this most advanced feature of it:
I hope this will have the people with similar commenting problem in the future…