Community
    • Login

    Paste preserving the indentation + Whitespace conversion issue.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    15 Posts 4 Posters 10.7k 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.
    • gstaviG
      gstavi
      last edited by

      Do you have any plugins that may auto-indent code?
      What application do you copy from?
      Did you consider that this app may copy un-indented text to the clipboard and NP++ just pastes whatever in there?

      1 Reply Last reply Reply Quote 1
      • SalviaSageS
        SalviaSage
        last edited by

        I don’t have plugins for autoindenting code aside from n++ automatic indent on new line behaviour.
        I copy the code from discord and without spaces thats true, and paste into notepad++ but the text in notepad++ has the indents, and they get wiped.

        I cant just copy the whole block for this reason, Now, I copy things that have indents line by line, which of course has more steps than just being able to copy paste and keep the indents.

        That’s all.

        1 Reply Last reply Reply Quote 0
        • gstaviG
          gstavi
          last edited by gstavi

          Pasting is not identical to typing the text “symbol by symbol”.
          The auto-indent logic is triggered by the “enter” key press. This does not happen with paste and 99% of users will not want it to happen since pasting already indented text between source files, which is what code developers do, will become a mess.
          Paste just inserts at the cursor a bulk of text: symbols, spaces, tabs and new-line symbols. Then NP++ redo syntax highlighting from the insertion place.

          The semi-easy solution is: copy all the lines, select them, and indent them as a block.
          You may even be able to create a macro for that.

          1 Reply Last reply Reply Quote 1
          • SalviaSageS
            SalviaSage
            last edited by

            How to do that?

            gstaviG 1 Reply Last reply Reply Quote 0
            • Scott SumnerS
              Scott Sumner
              last edited by

              I don’t see anything wrong with the way Notepad++ pasting works.

              It is not often that pasted code is indented to the same level as the code being pasted into; I do this type of pasting A LOT. What would be best here would be if Scintilla kept the pasted text selected (if it is whole-line text that is either being inserted at the caret point, and–optionally-- is replacing a previous selection of whole lines). If it were kept selected, a quick TAB or Shift+TAB press(es) would adjust it to the right indent level quickly.

              Otherwise, we have to be careful that we don’t talk about potential features that do too much mind-reading. Notepad++ isn’t an IDE that is really good at one language-it’s a general purpose tool that tries to do a lot of things acceptably well. It largely succeeds.

              1 Reply Last reply Reply Quote 1
              • gstaviG
                gstavi @SalviaSage
                last edited by

                @SalviaSage said:

                How to do that?

                Select lines with shift-arrows.
                Click tab to indent or shift-tab to unindent.

                1 Reply Last reply Reply Quote 1
                • Scott SumnerS
                  Scott Sumner
                  last edited by Scott Sumner

                  One of the neat tricks about a stream selection that contains one or more line-endings is that you don’t have to have a selection covering an integral number of lines in order to tab-indent (or [shift-]tab-outdent) the lines touched. An example:

                  Imgur

                  Note that in the beginning, only part of the first line and part of the last line are selected. A tab (or shift+tab) press affects the lines as if they were entirely selected, and in fact after the first tab keypress they are entirely selected.

                  1 Reply Last reply Reply Quote 2
                  • SalviaSageS
                    SalviaSage
                    last edited by SalviaSage

                    That’s nice. I didn’t know you could do that. That effectively solves my problem. Although I may not be able to preserve the indents, I can then just select my lines and press tab.

                    This of course doesn’t work for those infidel space indenters, Which is why I need the convert spaces to tabs working correctly.

                    Look at my example above. If a space indenter indented with 4 spaces and I have my tab length set to 2 spaces, when I do the operation, I get 2 tabs when I should get 1. Can this be fixed with a script?

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

                      Hi, @salviasage, and All,

                      To my mind, it’s quite normal that N++ replace a 4-spaces indented text with 2-tabulations of size 2, because, from your preferences, you decided :

                      • To use tabulation characters instead of spaces

                      • To define that each tabulation will take 2 positions

                      Indeed, if you expect a unique tabulation, taking 4 positions, it would, then, contradict your preferences !!

                      Cheers,

                      guy038

                      1 Reply Last reply Reply Quote 1
                      • SalviaSageS
                        SalviaSage
                        last edited by

                        that would be the case if it was you who was also indenting with 2 spaces, but you are not the only one who codes, you get a code from other people who may indent with 4 spaces, 6 spaces, 8 spaces or whatever it is that they decided to indent with.

                        Then, you want to convert that to your own style, and you cannot do this automatically, you still have to manually do it, by going into the preferences and changing your tab length to whatever the other coder formatted with, then you open another code formatted with a different set of spaces, then you do the same etc.

                        At least, it would be nice if we had like a tab length : 2 option in the status bar, where you can quickly set your tab length.

                        We can easily see what EOL the file is formatted with and convert the EOLs from the statusbar.
                        I really like that EOL option offered there on the status bar, and is perfect.
                        But, the same is simply not the case for the indents. That area, I think can be improved upon programmatically.

                        If anyone knows a script to make these conversions more automatic, please let me know.

                        1 Reply Last reply Reply Quote 0
                        • Alan KilbornA Alan Kilborn referenced this topic on
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors