Community
    • Login

    Button to toggle Tabs/Spaces?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 6 Posters 944 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.
    • myfirstnameispaulM
      myfirstnameispaul
      last edited by myfirstnameispaul

      Is there a way to have a button that toggles between Tabs/Spaces so I can easily configure while editing?

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

        @myfirstnameispaul ,

        Sorry, no, there is a checkbox in the Settings > Preferences > Language > Tab Settings > Replace by space. But I don’t think that can be toggled easily without going into that dialog. (Unfortunately, I don’t even think that it is exposed to the API, so I don’t think you could toggle that using PythonScript or similar scripting/plugin interface… but one of the other PythonScript gurus can feel free to prove me wrong.)

        myfirstnameispaulM 1 Reply Last reply Reply Quote 2
        • myfirstnameispaulM
          myfirstnameispaul @PeterJones
          last edited by

          @peterjones said in Button to toggle Tabs/Spaces?:

          Settings > Preferences > Language > Tab Settings > Replace by space

          Yeah, that’s why I was looking for a button option. For me, it’s an issue when I’m dealing with different configuration files since I don’t do any development work, but the files end up looking really weird, I have to spend time reformatting, I have to go through those menus, or I have to use a second different editor.

          I do see there is an automatic detection tool, but most of my editing is copying from terminal into blank document, but maybe I should play around with that more.

          You wouldn’t happen to know how I might get Tab into a Find or Replace field?

          PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @myfirstnameispaul
            last edited by

            @myfirstnameispaul

            If you spend most of your time copying into blank documents, then changing between two languages (which you choose to have different tab/space settings) might be enough. You might even just keep two tabs open, renamed (but not saved) as tab config and space config, with the language on each tab selected so that each has the right tab setting.

            To find a tab, you can use Extended Mode or Regular Expression Mode and use \t in the FIND WHAT field.

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

              @myfirstnameispaul said in Button to toggle Tabs/Spaces?:

              You wouldn’t happen to know how I might get Tab into a Find or Replace field?

              @peterjones said in Button to toggle Tabs/Spaces?:

              To find a tab, you can use Extended Mode or Regular Expression Mode and use \t in the FIND WHAT field.

              If you want to stick to Normal search mode you can get a tab into the FW box by selecting it first in the editing window and then pressing Ctrl+f. In the FW box it will just look like a really wide space.

              1 Reply Last reply Reply Quote 4
              • EkopalypseE
                Ekopalypse
                last edited by

                Using SCI_SETUSETABS could do this for the current buffer, but must be reapplied each time the buffer is activated.

                Michael VincentM 1 Reply Last reply Reply Quote 3
                • EkopalypseE
                  Ekopalypse
                  last edited by

                  But it’s not that easy, is it?
                  If we load a file and it looks strange, how do we know what to do?
                  I mean, if a tab is used, how does the script know that it has to be replaced by 2 or 4 or 8 spaces?

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

                    @ekopalypse said in Button to toggle Tabs/Spaces?:

                    Using SCI_SETUSETABS could do this for the current buffer, but must be reapplied each time the buffer is activated.

                    Yep, I have a little NppExec script that does this for me on the rare occasion I need to deal with tabs in files (other than Makefile which has “use tabs” set in my Notepad++ preferences); I use convert tabs to 4 spaces by default everywhere else:

                    ::tab
                    NPP_CONSOLE keep
                    
                    IF "$(ARGC)"<="1" THEN
                        // SCI_SENDMSG SCI_GETCURRENTPOS
                        // SCI_SENDMSG SCI_INSERTTEXT $(MSG_RESULT) "$(TAB)"
                        SCI_SENDMSG SCI_ADDTEXT 1 "$(TAB)"
                    ELSE IF "$(ARGV[1])"~="$(ON)" THEN
                        SCI_SENDMSG SCI_SETUSETABS 1
                        IF "$(ARGC)">"2" THEN
                            SCI_SENDMSG SCI_SETTABWIDTH $(ARGV[2])
                        ENDIF
                    ELSE IF "$(ARGV[1])"~="$(OFF)" THEN
                        SCI_SENDMSG SCI_SETUSETABS 0
                    ELSE IF "$(ARGV[1])"~="bs" THEN
                        IF "$(ARGC)">"2" THEN
                            IF "$(ARGV[2])"~="$(FALSE)" THEN
                                SCI_SENDMSG SCI_SETBACKSPACEUNINDENTS $(FALSE)
                            ELSE
                                SCI_SENDMSG SCI_SETBACKSPACEUNINDENTS $(TRUE)
                            ENDIF
                        ELSE
                            SCI_SENDMSG SCI_GETBACKSPACEUNINDENTS
                            ECHO Backspace Unindents = $(MSG_RESULT)
                        ENDIF
                        GOTO END
                    ELSE IF "$(ARGV[1])"~="status" THEN
                        SCI_SENDMSG SCI_GETUSETABS
                        SET LOCAL TABON = $(MSG_RESULT)
                        SCI_SENDMSG SCI_GETTABWIDTH
                        SET LOCAL WIDTH = $(MSG_RESULT)
                        ECHO TABS         = $(TABON) ($(WIDTH))
                        SCI_SENDMSG SCI_GETBACKSPACEUNINDENTS
                        ECHO BS Unindents = $(MSG_RESULT)
                    ELSE
                        GOTO USAGE
                    ENDIF
                    GOTO END
                    
                    :USAGE
                    ECHO Usage:
                    ECHO   \$(ARGV[0])           = insert a tab (non-expanded regardless of setting) at current position
                    ECHO   \$(ARGV[0]) status    = current tab setting
                    ECHO   \$(ARGV[0]) $(ON) [W] | $(OFF) = enable tabs (no space convert) using optional W tab width | disable (convert to spaces)
                    ECHO   \$(ARGV[0]) bs $(ON) | $(OFF)  = enable | disable backspace unindents
                    
                    :END
                    

                    Note the $(ON) and $(OFF) are set in my NppExec startup:

                    ...
                    SET TRUE=1
                    SET FALSE=0
                    SET ON=$(TRUE)
                    SET OFF=$(FALSE)
                    ...
                    

                    Cheers.

                    Alan KilbornA Torax MaluT 2 Replies Last reply Reply Quote 5
                    • Alan KilbornA
                      Alan Kilborn @Michael Vincent
                      last edited by

                      I get the mental image of the OP playing a version of WHACKAMOLE with tab characters.

                      1 Reply Last reply Reply Quote 2
                      • Torax MaluT
                        Torax Malu @Michael Vincent
                        last edited by

                        Sorry to re-open such an old thread. Don’t want to run a necromantic job… but I’ve seen the option to switch between the indent singe temporarily per document via a switch in the status line in several copycats of Notepad++. why not re-copy this into notepad++!? Perhaps this is an idea for an feature request which shouldn’t be difficult to implement, if I understand the implications right…

                        what you think guys?

                        PeterJonesP 2 Replies Last reply Reply Quote 0
                        • PeterJonesP
                          PeterJones @Torax Malu
                          last edited by PeterJones

                          @Torax-Malu ,

                          That was talked about more last autumn in this conversation, though that specific discussion didn’t get very detailed.

                          I am remember something from approximately the same timeframe, where I thought that someone investigated in more detail, and (IIRC) found that “shouldn’t be difficult to implement” doesn’t always equate to “actually isn’t too difficult to implement” – but I cannot find either a post here or the coment that I vaguely remember in any issues or PRs, even though there were other tab/indentation fixes made last autumn…

                          Hopefully someone who remembers (or is better at searching than I am) will be able to remember/find the discussion I am thinking about.


                          update: ugh, per this comment, it was earlier than I was thinking, and the user who I thought had the best chance of remembering/finding it couldn’t find it even then. :-( So now I have confirmation that someone else also remembered that discussion, but still haven’t been able to find it. :-(

                          1 Reply Last reply Reply Quote 2
                          • PeterJonesP
                            PeterJones @Torax Malu
                            last edited by

                            @Torax-Malu ,

                            @Alan-Kilborn messaged me a link to this post, where he shared a script for the PythonScript plugin, which can be used to set the current file to either tabs or spaces

                            Useful link: FAQ: How to install and runscripts with PythonScript plugin – also includes instructions for assigning a keyboard shortcut. And you can even use the Plugins > PythonScript > Configuration… to add a script to the toolbar, allowing you to have a toolbar button to activate it.

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