• Login
Community
  • Login

I found the place in the code where space is inserted in the comments

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
11 Posts 2 Posters 662 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.
  • S
    ScienceD
    last edited by Jul 12, 2023, 10:04 AM

    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#L5097

    I 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!

    A 1 Reply Last reply Jul 12, 2023, 10:19 AM Reply Quote 0
    • A
      Alan Kilborn @ScienceD
      last edited by Jul 12, 2023, 10:19 AM

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

      S 2 Replies Last reply Jul 12, 2023, 10:25 AM Reply Quote 0
      • S
        ScienceD @Alan Kilborn
        last edited by Jul 12, 2023, 10:25 AM

        @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 =\

        1 Reply Last reply Reply Quote 0
        • A
          Alan Kilborn
          last edited by Jul 12, 2023, 10:43 AM

          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.

          S 1 Reply Last reply Jul 12, 2023, 12:25 PM Reply Quote 2
          • S
            ScienceD @Alan Kilborn
            last edited by Jul 12, 2023, 12:25 PM

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

            Screenshot 2023-07-12 14.16.55ddddd.png

            Here is buttons defined in CustomizeToolbar.btn file:

            Macro,COMMENT_LINES,,,,,butts\lcomm.ico
            Macro,UNCOMMENT_LINES,,,,,butts\undolcomm.ico
            
            A S 2 Replies Last reply Jul 12, 2023, 12:33 PM Reply Quote 1
            • A
              Alan Kilborn @ScienceD
              last edited by Jul 12, 2023, 12:33 PM

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

              1 Reply Last reply Reply Quote 3
              • S
                ScienceD @ScienceD
                last edited by ScienceD Jul 13, 2023, 4:04 AM Jul 13, 2023, 4:02 AM

                @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>
                
                A 1 Reply Last reply Jul 13, 2023, 11:51 AM Reply Quote 0
                • A
                  Alan Kilborn @ScienceD
                  last edited by Jul 13, 2023, 11:51 AM

                  @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}(/*)

                  S 1 Reply Last reply Jul 16, 2023, 4:01 PM Reply Quote 3
                  • S
                    ScienceD @Alan Kilborn
                    last edited by Jul 16, 2023, 4:01 PM

                    @Alan-Kilborn IDK, I just followed advice of one regex site that said it might result in errors when copy pasting into code:

                    49cd57d4-c6d6-4f9b-af37-b4275b3c8d62-зображення.png

                    A 1 Reply Last reply Jul 16, 2023, 4:06 PM Reply Quote 0
                    • A
                      Alan Kilborn @ScienceD
                      last edited by Jul 16, 2023, 4:06 PM

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

                      1 Reply Last reply Reply Quote 3
                      • S
                        ScienceD @Alan Kilborn
                        last edited by ScienceD Jul 20, 2023, 12:13 PM Jul 20, 2023, 12:12 PM

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

                        multi_select_block_line_single_combo.gif

                        I hope this will have the people with similar commenting problem in the future…

                        1 Reply Last reply Reply Quote 3
                        10 out of 11
                        • First post
                          10/11
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors