Community
    • Login

    Change Indent Keyboard Shortcut?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    27 Posts 5 Posters 11.0k 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
      last edited by Alan Kilborn

      Perhaps of interest; they are links, click on them:

      • ISSUE 5493
      • ISSUE 5721
      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hi All,

        My bad ! I read too quickly ! Then, my previous post is quite irrelevant !


        So, if I completely understood the problem, the OP want, via a shortcut, to move the caret, from current position on a line to the next tabstop ? That is to say to the column = n x T + 1, where T is the tab size and n an integer >= 0 ?

        BR

        guy038

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

          @guy038 said in Change Indent Keyboard Shortcut?:

          to move the caret, from current position on a line to the next tabstop

          I don’t think so; I think OP would want to have the line indented one tab stop (be it x space characters or one tab character) and then have the caret remain in the line between the two characters it originally was between. But hey, I could be wrong.

          1 Reply Last reply Reply Quote 1
          • Michael VincentM
            Michael Vincent @Michael Vincent
            last edited by

            @Stefane-Guevremont
            @guy038
            @Alan-Kilborn
            @PeterJones
            @Michael-Vincent said in Change Indent Keyboard Shortcut?:

            Assume you may want the reverse as well.

            Not to beat a dead horse, but I updated my NppExec scripts. I liked @PeterJones MACRO, but like my scripts, if I had multiple lines selected, they only operated on the line where the cursor anchor point was. However, with multiple lines selected and the cursor in the middle of one of them, the Edit => Indent => menu options work as expected - they only don’t work when you have a single line and the cursor in the middle.

            I’ve tested lots of cases and I think the following scripts work as I expect.

            • With only a single line either highlighted or cursor anywhere in the line - INDENT or UNINDENT - keeping the cursor where it was IF it was in the middle of the text somewhere. Note if the cursor is in the preceding whitespace, indents are inserted at the far left margin, so the cursor shifts INDENT# of spaces with each insert.

            • If multiple lines are selected and the cursor is anywhere either fully selecting the lines or in the middle of them somewhere - INDENT or UNINDENT ALL LINES - cursor may not stay in the current position, rather the highlighting is fully completed to all lines. See example:

            cb3c7db3-5825-49c2-9441-1a94f121255d-image.png

            5f79c162-3ab8-4b5b-8a2b-604ae9f138a8-image.png

            The scripts:

            ::lineindent
            NPP_CONSOLE keep
            
            SCI_SENDMSG SCI_GETSELECTIONSTART 
            SCI_SENDMSG SCI_LINEFROMPOSITION $(MSG_RESULT)
            SET LOCAL START = $(MSG_RESULT)
            
            SCI_SENDMSG SCI_GETSELECTIONEND
            SCI_SENDMSG SCI_LINEFROMPOSITION $(MSG_RESULT)
            SET LOCAL END = $(MSG_RESULT)
            
            IF "$(START)"!="$(END)" THEN
                NPP_MENUCOMMAND Edit\Indent\Increase Line Indent
            ELSE
                SCI_SENDMSG SCI_GETCURRENTPOS
                SET LOCAL POS = $(MSG_RESULT)
                SCI_SENDMSG SCI_GETTABWIDTH 
                SET LOCAL TAB = $(MSG_RESULT)
            
                SCI_SENDMSG SCI_GOTOLINE $(CURRENT_LINE)
                NPP_MENUCOMMAND Edit\Indent\Increase Line Indent
                SET LOCAL POS ~ $(POS) + $(TAB)
                SCI_SENDMSG SCI_GOTOPOS $(POS)
            ENDIF
            
            ::lineunindent
            NPP_CONSOLE keep
            
            SCI_SENDMSG SCI_GETSELECTIONSTART 
            SCI_SENDMSG SCI_LINEFROMPOSITION $(MSG_RESULT)
            SET LOCAL START = $(MSG_RESULT)
            
            SCI_SENDMSG SCI_GETSELECTIONEND
            SCI_SENDMSG SCI_LINEFROMPOSITION $(MSG_RESULT)
            SET LOCAL END = $(MSG_RESULT)
            
            IF "$(START)"!="$(END)" THEN
                NPP_MENUCOMMAND Edit\Indent\Decrease Line Indent
            ELSE
                SCI_SENDMSG SCI_GETCURRENTPOS
                SET LOCAL POS = $(MSG_RESULT)
                SCI_SENDMSG SCI_GETTABWIDTH 
                SET LOCAL TAB = $(MSG_RESULT)
            
                SCI_SENDMSG SCI_GOTOLINE $(CURRENT_LINE)
                NPP_MENUCOMMAND Edit\Indent\Decrease Line Indent
                SCI_SENDMSG SCI_GETLINEINDENTATION $(CURRENT_LINE)
                IF "$(MSG_RESULT)"!="0" THEN
                    SET LOCAL POS ~ $(POS) - $(TAB)
                ENDIF
                SCI_SENDMSG SCI_GOTOPOS $(POS)
            ENDIF
            

            I then use NppExec to add them to the Macro menu and then Shortcut Mapper to add the “Ctrl + Alt + [ and ]” shortcuts as @PeterJones did (note the OP’s request of “Ctrl + [ and ]” are already taken by SCI_PARAUP and SCI_PARADOWN respectively)

            b8099f98-63c9-4849-847a-47cb9194666c-image.png

            Cheers.

            1 Reply Last reply Reply Quote 2
            • Alan KilbornA
              Alan Kilborn
              last edited by

              More horse beating:

              So it sure seems odd.
              These commands seem to have Tab and Shift+Tab tied to them:

              a159b54f-45c8-44eb-9ba1-5cb349e14415-image.png

              These commands aren’t in the Shortcut Mapper (that I could find, in the Edit category) so perhaps what is boxed in blue above is a hard-coding?

              At run-time the corresponding code is not hit with the key presses but only invoking via the menu items:

                  case IDM_EDIT_INS_TAB:
                      _pEditView->execute(SCI_TAB);
                      break;
              
                  case IDM_EDIT_RMV_TAB:
                      _pEditView->execute(SCI_BACKTAB);
                      break;
              

              And, when invoking via menu, all they do is the same thing a Tab or Shift+Tab does via the normal Scintilla page mappings in Shortcut Mapper.

              This certainly is odd.

              But then onto the actual behavior.
              This is all Scintilla behavior.
              Someone in that project decided that this is how SCI_TAB and SCI_BACKTAB should work.
              It seems very reasonable for the multiline selection case.
              As discussed above, for the non multiline case, it is less so.

              Probably I am not adding new information, but the oddness of this situation made me do my own little investigation.

              Michael VincentM 1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn
                last edited by Alan Kilborn

                Interestingly, if you remove the Tab and Shift+Tab mappings on the Scintilla commands page in Shortcut Mapper, the indent stuff in the Edit menu now looks like this:

                1664f52f-4814-4a11-89e3-71897761ec51-image.png

                Note, no key mappings shown to the right of the commands.

                So then it would seem that Tab and Shift+Tab are now totally unmapped.

                BUT…trying them in an editor window I see that Tab still works. Curiouser and curiouser… Of course, maybe now it is at the point where it is just inserting a raw \x09. :-)

                1 Reply Last reply Reply Quote 1
                • Michael VincentM
                  Michael Vincent @Alan Kilborn
                  last edited by

                  @Alan-Kilborn said in Change Indent Keyboard Shortcut?:

                  Probably I am not adding new information, but the oddness of this situation made me do my own little investigation.

                  Thanks Alan - I surmised as much and it’s good to have someone confirm by actually looking at N++ source (I didn’t know where to begin to find it). I had assumed they were just calling the SCI_TAB and SCI_BACKTAB and looks like indeed that’s what they do.

                  You can find the SCI_TAB and SCI_BACKTAB in Shortcut Mapper as well as some shortcuts for Cut / Paste:

                  46509dd5-28ad-4992-bf3d-f2da6ddeb1ef-image.png

                  And notice the Edit menu for Cut / Paste:

                  23c7e941-b00c-4225-92a4-50a4e16c63b8-image.png

                  The two (multiple) shortcuts are assigned, something you can’t do with Shortcut Mapper, so again, assuming N++ code is somehow adding the shortcuts based on Scintilla “defaults” or something?

                  So to sum up from our previous comments, it seems the Edit => Indent => menu items are not quite doing what they advertise. Not sure this is a bug, rather just a discrepancy between what the menu item implies and what it actually does.

                  To be honest, I never knew they were there but now that I do, I like the functionality I’ve implemented above with NppExec - it’ll come in real handy when editing Python where indents MATTER and i can’t just add or comment out loops (like with Perl) when troubleshooting - I need to also change indent levels. It’ll be easier now with my new shortcuts!

                  Cheers.

                  Alan KilbornA 1 Reply Last reply Reply Quote 2
                  • Alan KilbornA
                    Alan Kilborn @Michael Vincent
                    last edited by

                    @Michael-Vincent said in Change Indent Keyboard Shortcut?:

                    You can find the SCI_TAB and SCI_BACKTAB in Shortcut Mapper

                    Yes, but if it was that alone we would be talking about “weirdness”. :-)

                    The two (multiple) shortcuts are assigned, something you can’t do with Shortcut Mapper…

                    You can assign multiple, but only for the Scintilla commands.

                    Edit => Indent => menu items are not quite doing what they advertise … I never knew they were there but now that I do, I like the functionality I’ve implemented above…

                    Yes, but it seems like standard Notepad++ could do better here. I mean, the stuff in the Edit -> Indent menu is rather pointless if it is just going to do the same thing as Tab or Shift+Tab.
                    Or maybe the idea is to give script writers a way to invoke these keys without calling a “key sender”?
                    I have no idea of the history on this.
                    But I do know that Increase Line Indent (and Decrease) surely seems misleading (unless you have a multiline selection).

                    BTW, if you like source code references, here’s where in Scintilla the Tab keycombos get processed, and you can see the difference in the multiline versus non-multiline handling: https://github.com/notepad-plus-plus/notepad-plus-plus/blob/3b2d2bb300d01fe02091c837bc65f87d07cf6b8c/scintilla/src/Editor.cxx#L3953

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

                      @Michael-Vincent

                      I was browsing the code link in my post just above, and noticed that the Scintilla code handles multi-selections and rectangular selections as well as the more usual single selection.

                      I’m not much of a NppExec scripter, but I’m curious about what your scripts will do with those circumstances, so I may just try it out! :-)

                      Michael VincentM 1 Reply Last reply Reply Quote 0
                      • Michael VincentM
                        Michael Vincent @Alan Kilborn
                        last edited by Michael Vincent

                        @Alan-Kilborn said in Change Indent Keyboard Shortcut?:

                        I’m not much of a NppExec scripter, but I’m curious about what your scripts will do with those circumstances, so I may just try it out! :-)

                        My script basically looks at the selection and if it’s single line - it does some magic before calling the Edit=>Indent=>menu options. If it’s multiline selection, I just call the Edit=>Indent=>menu options.

                        I don’t fully grok the source code at your link, but if all that’s in there, I wonder if it may be an easy lift for a talented N++ developer to change the current simple menu code to sending SCI_TAB/BACKTAB to actually doing some logic about single / multiline selection and making the menu items “do what they say”.

                        Til then, I’m loving my scripts (since I’m actually editing Python right now with the exact troubleshooting use case I described above). Everything “looks like a nail” now to me I guess …

                        Cheers.

                        Alan KilbornA 1 Reply Last reply Reply Quote 2
                        • Alan KilbornA
                          Alan Kilborn @Michael Vincent
                          last edited by

                          @Michael-Vincent said in Change Indent Keyboard Shortcut?:

                          I wonder if it may be an easy lift for a talented N++ developer to change the current simple menu code to sending SCI_TAB/BACKTAB to actually doing some logic about single / multiline selection and making the menu items “do what they say”.

                          That’s a good idea, but I quoted some “issue” links above on it, and it doesn’t appear they’ve generated enough interest for any of the talents to work on it.

                          1 Reply Last reply Reply Quote 0
                          • Cr8zy_IvanC
                            Cr8zy_Ivan @Michael Vincent
                            last edited by

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • Cr8zy_IvanC
                              Cr8zy_Ivan
                              last edited by

                              Oh wow, quite the topic I see.

                              I’m trying to get this to work but finding it a bit frustrating.

                              @Michael-Vincent, thank you so much for the plugin and the code!

                              I’m a novice at Notepad++ and coding and general. I’ve installed the plugin, but then I’m confused as to what to do next. Macro\Modify Shortcut/Delete Macro? Plugins\NppExec\Show Console…? Save the code into a dll file? (I’m not even sure how dll files work)… oh boy

                              Michael VincentM 1 Reply Last reply Reply Quote 0
                              • Michael VincentM
                                Michael Vincent @Cr8zy_Ivan
                                last edited by

                                @Stefane-Guevremont said in Change Indent Keyboard Shortcut?:

                                I’m a novice at Notepad++ and coding and general. I’ve installed the plugin, but then I’m confused as to what to do next. Macro\Modify Shortcut/Delete Macro? Plugins\NppExec\Show Console…? Save the code into a dll file? (I’m not even sure how dll files work)… oh boy

                                Plugins=>NppExec=>Execute. In the window, paste one of the “scripts” without the name and save with that name instead:

                                e5c7e7f6-1f32-4a4e-a153-601c4cb877a9-image.png

                                Do the same for the other saving it as the other name.

                                Then, Plugins=>NppExec=> Advanced Options…

                                2c012a93-81aa-408a-9850-2691ecc218db-image.png

                                Add a name, select the script name you saved that matches and press the Add/Modify button. Make sure the “Place to the Macros submenu” at the top is checked.

                                Finally, open Setting=>Shortcut Mapper… and add the “Ctrl + Alt + [” shortcuts:

                                1f7c46d6-5891-46b0-8889-b1842e6fab2b-image.png

                                Cheers.

                                1 Reply Last reply Reply Quote 5
                                • Cr8zy_IvanC
                                  Cr8zy_Ivan
                                  last edited by

                                  Wow, that’s so awesome. Thank you!

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

                                    Here’s a weird condition…maybe:

                                    Select one or more empty lines.
                                    Press Tab.
                                    Exactly nothing happens.

                                    My goal was to have leading whitespace inserted on all lines at once, for each press of the tab key.

                                    1 Reply Last reply Reply Quote 2
                                    • First post
                                      Last post
                                    The Community of users of the Notepad++ text editor.
                                    Powered by NodeBB | Contributors