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 652 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.
    • Alan KilbornA
      Alan Kilborn @ScienceD
      last edited by

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

      ScienceDS 2 Replies Last reply Reply Quote 0
      • ScienceDS
        ScienceD @Alan Kilborn
        last edited by

        @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
        • Alan KilbornA
          Alan Kilborn
          last edited by

          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.

          ScienceDS 1 Reply Last reply Reply Quote 2
          • ScienceDS
            ScienceD @Alan Kilborn
            last edited by

            @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
            
            Alan KilbornA ScienceDS 2 Replies Last reply Reply Quote 1
            • Alan KilbornA
              Alan Kilborn @ScienceD
              last edited by

              @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
              • ScienceDS
                ScienceD @ScienceD
                last edited by ScienceD

                @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>
                
                Alan KilbornA 1 Reply Last reply Reply Quote 0
                • Alan KilbornA
                  Alan Kilborn @ScienceD
                  last edited by

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

                  ScienceDS 1 Reply Last reply Reply Quote 3
                  • ScienceDS
                    ScienceD @Alan Kilborn
                    last edited by

                    @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

                    Alan KilbornA 1 Reply Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @ScienceD
                      last edited by

                      @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
                      • ScienceDS
                        ScienceD @Alan Kilborn
                        last edited by ScienceD

                        @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
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors