Community
    • Login

    Macro to switch indentation

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 966 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.
    • elusiveorganizationE
      elusiveorganization
      last edited by

      Is it possible to make a shortcut macro to switch between tab and space identation? I’ve tried the following:

      <Macro name="Tab (Ctrl + E)" Ctrl="yes" Alt="no" Shift="no" Key="69">
      	<Action type="0" message="2124" wParam="0" lParam="1" sParam="" />
      </Macro>
      <Macro name="Space (Ctrl + R)" Ctrl="yes" Alt="no" Shift="no" Key="82">
      	<Action type="0" message="2124" wParam="0" lParam="0" sParam="" />
      </Macro>
      

      *2124 is SCI_SETUSETABS(bool useTabs)

      1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones
        last edited by

        @elusiveorganization said:

        Is it possible to make a shortcut macro to switch between tab and space identation

        It should be… but I couldn’t make it work, either. I believe the bool useTabs argument should be the wParam, not the lParam, but it didn’t work whether I used yours or whether I moved the 1 to wParam instead. I don’t know what’s wrong with that.

        <Macro name="Tab (Ctrl + E)" Ctrl="yes" Alt="no" Shift="no" Key="69">
            <Action type="0" message="2124" wParam="1" lParam="0" sParam="" />
        </Macro>
        <Macro name="Space (Ctrl + R)" Ctrl="yes" Alt="no" Shift="no" Key="82">
            <Action type="0" message="2124" wParam="0" lParam="0" sParam="" />
        </Macro>
        

        However, if I use the NppExec plugin, I can send the 2124 Scintilla message and have it toggle the mode, as shown in this animation.

        To make those into keyboard-executable scripts in NppExec:

        1. Plugins > NppExec > Execute
          1. Make the Command(s): sci_sendmsg 2124 1
          2. Click Save…, name it use-tabs, and click Save
          3. Change the sci_sendmsg 2124 1 to sci_sendmsg 2124 0, and save again as use-spaces
          4. Cancel
        2. Plugins > NppExec > Advanced Options, in the Menu Item section:
          1. Name = Use Tabs, Associated Script = use-tabs, Add/Modify
          2. Name = Use Spaces, Associated Script = use-spaces, Add/Modify
          3. Okay twice, then restart Notepad++
        3. At this point, Macro > Use Tabs or Macro > Use Spaces will toggle.
        4. To set the shortcut, Macro > Modify Shortcut / Delete Macro
          1. Change to Plugin Commands tab.
          2. If available, set Filter to NppExec, otherwise just scroll down until you find the NppExec commands
          3. At the end of the NppExec commands should be Use Tabs and Use Spaces.
          4. Click Modify on each, and set to Ctrl+E and Ctrl+R, or whatever keystrokes you want
          5. Close the shortcuts dialog when don.
          6. Keyboard shortcuts should now work (assuming there wasn’t a conflict with the shortcuts; in v7.6.6 and newer, shortcut conflicts should be highlighted, even with filters active)

        Good luck.

        1 Reply Last reply Reply Quote 2
        • dailD
          dail
          last edited by

          Another option would be LuaScript. Edit the startup file, add the following, and restart.

          npp.AddShortcut("Toggle Indentation", "Ctrl+E", function()
          	editor.UseTabs = not editor.UseTabs
          end)
          
          1 Reply Last reply Reply Quote 3
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors