• Login
Community
  • Login

Tab replaces all leading spaces

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
18 Posts 6 Posters 5.3k 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.
  • P
    PeterJones
    last edited by May 14, 2019, 6:38 PM

    @László-Botka said:

    inserting an extra character and then the Tab, and then delete the extra character

    Glad you found a workaround. Sorry we didn’t have a better solution for you.

    I didn’t find this issue in other editors, but they don’t use Scintilla.

    I just confirmed SciTE (which is Scintilla’s test-bed GUI) does the same thing: if Options > Change Indentation Settings is set to “use tabs”, then hitting a TAB in the early whitespace will turn it all to TAB; if “use tabs” is disabled, it will convert it all to spaces. So the issue is in SciTE 4.1.4 (and they appear to keep the SciTE version number in sync with the Scintilla version number to avoid confusion) … (but that also means that our “maybe it’s already been fixed in a more recent Scintilla” standard answer won’t apply)

    1 Reply Last reply Reply Quote 3
    • A
      Alan Kilborn
      last edited by Alan Kilborn May 14, 2019, 6:49 PM May 14, 2019, 6:49 PM

      Memory might fail me but I think it was decided by the Scintilla folks that this is their desired behavior and it isn’t going to be changed, or a “preference” offered for. Could be wrong (I say that a lot).

      I can avoid this by inserting an extra character and then the Tab, and then delete the extra character.

      Sounds like a macro to me:

      • Start macro record with caret at desired spot
      • Press ~ (or other character, maybe best to pick one that won’t trigger Autocomplete)
      • Press Tab
      • Press left arrow
      • Press Backspace
      • Press Right arrow
      • End macro recording

      Assign it to a keycombination of your choosing.

      Rather a pain, and it will mess with the Undo buffer, but maybe useful.

      1 Reply Last reply Reply Quote 3
      • D
        dinkumoil @László Botka
        last edited by dinkumoil May 14, 2019, 7:02 PM May 14, 2019, 7:01 PM

        @László-Botka

        There are two plugins I havn’t tried yet but maybe they could help you.

        The first one is Elastic Tabstops. To obtain some infos about how it works have a look at >>> this site <<< . It can be downloaded via PluginsAdmin as 32 bit and 64 bit version.

        The second one is TabIndentSpaceAlign. It is not available via PluginsAdmin and it’s only 32 bit. You can download it >>> here <<< but you have to install it manually. This plugin was available via the old PluginManager. It hasn’t been included in PluginsAdmin’s plugin list because the DLL file doesn’t contain any version information, which is a requirement. But there are chances that it will run under Notepad++ v7.6 and above.

        1 Reply Last reply Reply Quote 3
        • L
          László Botka
          last edited by May 14, 2019, 7:15 PM

          After several years of use, this is the first time that this issue has occurred, in a free format text. Thanks for the recommended macro.

          1 Reply Last reply Reply Quote 2
          • L
            László Botka
            last edited by May 14, 2019, 7:59 PM

            @dinkumoil

            Thank you for looking at this.
            I’ll examine them in detail, but from the short descriptions I think they operate under strict rules - I simply want that a Tab pressed be Tab, a space pressed be space in the text.

            @ PeterJones

            It is very unfortunate that Scintilla does not support the above-mentioned operation, the most simple Tab/Space handling , which is naturally supported by the Windows editors like Notepad, Pspad, Ultraedit, FCW editor,

            E 1 Reply Last reply May 14, 2019, 8:34 PM Reply Quote 1
            • E
              Ekopalypse @László Botka
              last edited by May 14, 2019, 8:34 PM

              @László-Botka

              there is a way to work around it, but it involves a scripting plugin.
              One would need to set tab indents attribute to false for each buffer which gets activated.
              I hope I understood your request correctly.

              1 Reply Last reply Reply Quote 4
              • G
                guy038
                last edited by guy038 May 14, 2019, 10:35 PM May 14, 2019, 10:34 PM

                Hello, @lászló-botka, @peterjones, @alan-kilborn, @dinkumoil, @ekopalypse, and All,

                Have a look to the article, below :

                https://stackoverflow.com/questions/13973255/notepad-keeping-spaces-in-indent

                Answering to @ellak, the OP, @zennehoy, said something quite pertinent :

                We follow the principle that tabs are used for indentation, and spaces are used for alignment. This allows everyone to choose an indentation size they like, without running into misalignment issues when different people use different indentation sizes. The front two tabs are indentation, the spaces, [coming after], are alignment.


                Indenting problem is rather complex :

                • It depends on the key pressed ( Tab or Shift + Tab )

                • It depends on the position of cursor ( in the “indentation” part or in the “code” part )

                • It may depends of the character right before the cursor location ( a Tab character, a Space character or any other char )

                As for the indentation part of the next line, when hitting the Enter key :

                • It may be changed into a complete space characters area

                • It may be changed into a complete tab characters area, with additional space chars to respect the tabstops

                • It may fully copy the precedent indentation, without any modification


                I tested on N++ v7.6.3, both, the Elastic Tabstops and TabIndentSpaceAlign plugins. To install them :

                • Click on the Plugins > Open Plugins Folder.. option

                • Create a folder TabIndentSpaceAlign and/or a folder ElasticTabstops

                • Stop any Notepad++ instance

                • Place the downloaded dll files, inside its respective folder

                • Restart N++

                After some tests, it happened that the Elastic Tabstops is not suitable for your problem as it is rather used to align areas of text, in columns, separated with tabulation character(s), with elastic tabstops, which may be converted, later, in physical space characters

                Unfortunately, @ekopalypse, your Python work-around isn’t completely useful, too. Indeed, as soon as you hit the Enter key, the default N++ behavior occurs and changes most of the space characters to tabulation chars :-(

                So, @lászló-botka, I do think that the best, for you, would be to install the TabIndentSpaceAlign plugin ;-))


                Once the TabIndentSpaceAlign plugin enabled :

                • A hit on the Tab key, in the “indentation” part of a line :

                  • Adds a Tabulation character, if the previous character was a Tabulation character ( of N space size )

                  • Adds N space character(s) or less, if the previous characters was a space character

                • A hit on the Tab key, in the “code” part of a line :

                  • Adds N space character(s) or less, in all cases ( Hold down the Alt key and hit , successively, on keys 0 and 9, of the numeric keypad, if you really want to insert a tabulation character )

                • A hit on the Shift + Tab key, in the indentation part of a line :

                  • Remove the previous Tabulation character, right before the cursor location

                  • Remove all the previous area of space character(s), right before the cursor location

                • A hit on the Shift + Tab key, in the code part of a line :

                  • Simply move the cursor on the previous tabstop, whatever its location, without deleting* anything

                • A hit on the Enter key rewrites the exact indentation part of the current line in the next line

                Best Regards,

                guy038

                E 1 Reply Last reply May 15, 2019, 1:51 PM Reply Quote 2
                • L
                  László Botka
                  last edited by May 15, 2019, 6:53 AM

                  Many thanks to everyone for their help

                  @guy038

                  The TabIndentSpaceAlign plugin works fine with Alt numpad 09 in the “code” part.
                  But it’s complicate to press, and I’m sure I will sometimes press Tab and don’t notice when I write fast.
                  …
                  I found the solution:
                  If I use Ctrl V to Insert Tab (instead of pressing Tab), the result will be what I want: Tabs will be stored as Tab characters, Spaces will be stored as Space characters everywhere.

                  [ To achieve this, I already have a hotkey defined with Ditto, an extension to the Windows Clipboard. I use it regularly, to insert a Tab character into the 'Find what" field, searching in Normal mode in the Ctrl+F “Find window”. ]

                  1 Reply Last reply Reply Quote 3
                  • L
                    László Botka
                    last edited by May 15, 2019, 7:11 AM

                    Thanks for the Alt numpad 09 tip, it can also be used in in my original issue, without any extra plugin.

                    1 Reply Last reply Reply Quote 1
                    • A
                      Alan Kilborn
                      last edited by Alan Kilborn May 15, 2019, 12:25 PM May 15, 2019, 12:25 PM

                      …Alt numpad 09 tip…

                      It may be worth pointing out that one can easily insert a tab character, without pressing Tab or using the numpad technique, from the ASCII Insertion Panel. Make that panel visible from the Edit menu by choosing Character Panel. Double-clicking any line in that panel inserts the clicked-on character. Useful for others besides tab obviously (although limited to “ASCII” characters).

                      This panel is also a handy reference when you see “black boxed” characters in your (mostly text) file and you’re wanting to know their binary values (perhaps on your way to figuring out how/why they got into your file). You simply mentally note the text inside the black box and compare it to the Character column values on the panel…but let’s not go too far down this road as N++ is a text file editor, not a binary file editor.

                      1 Reply Last reply Reply Quote 3
                      • E
                        Ekopalypse @guy038
                        last edited by May 15, 2019, 1:51 PM

                        @guy038

                        your Python work-around isn’t completely useful, too. Indeed, as soon as you hit the Enter key, the default N++ behavior occurs and changes most of the space characters to tabulation chars :-(

                        does not happen to me.
                        If i hit enter the line stays as it was but if you refer to the next line, then yes,
                        this might happen if you have autoindent enabled but this doesn’t make
                        sense in this case, doesn’t it?

                        A 1 Reply Last reply May 15, 2019, 1:58 PM Reply Quote 2
                        • A
                          Alan Kilborn @Ekopalypse
                          last edited by May 15, 2019, 1:58 PM

                          @Ekopalypse said:

                          this might happen if you have autoindent enabled but this doesn’t make
                          sense in this case,

                          I’m going out on a limb to say that if one is coding, and autoindent is NOT turned on, N++ is too painful to use. :)

                          E 1 Reply Last reply May 15, 2019, 2:01 PM Reply Quote 1
                          • E
                            Ekopalypse @Alan Kilborn
                            last edited by May 15, 2019, 2:01 PM

                            @Alan-Kilborn

                            :-D, but if you like to insert spaces and tabs like YOU want, how should a program know this beforehand??

                            A 1 Reply Last reply May 15, 2019, 2:06 PM Reply Quote 0
                            • A
                              Alan Kilborn @Ekopalypse
                              last edited by May 15, 2019, 2:06 PM

                              @Ekopalypse said:

                              how should a program know this beforehand

                              I’m not following this thread super-closely because in my now 3 decades of software development, the coding standard has been to never allow the use of actual tab characters in source files. But I would think it should replicate the indentation exactly of the line-above, but let the user then edit that and leave it the way the user changes it…but I am too dumb about it to continue talking… :)

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