Community
    • Login

    Backspace Unindents

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    24 Posts 6 Posters 5.1k Views 2 Watching
    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.
    • astrosofistaA Offline
      astrosofista @Alan Kilborn
      last edited by

      @Alan-Kilborn, @guy038 and All

      Haven’t read all this thread, but in case you want to make a comparation, the Extended Settings plugin provides a similar feature. Works fine, by the way.

      Cheers.

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

        @astrosofista

        the Extended Settings plugin provides a similar feature

        Sure; I’m actually quite surprised no one earlier in the thread mentioned that.
        If I used Extended Settings plugin, I’d like to think I would have mentioned it.
        At the time the plugin came out, I already had most of its functionality, thru scripts.

        I even had a backspace-unindenter script (different from the one above); not realizing that Scintilla provided the function, my script did it manually and was tied to the Backspace key binding.
        (In some ways I liked my earlier script better than Scintilla’s function!)

        1 Reply Last reply Reply Quote 2
        • guy038G Offline
          guy038
          last edited by guy038

          Hello @alan-kilborn and All,

          OK ! When doing tests, the TAB key was set to write a four positions TAB character and I principally did tests with leading tab chars ! But never mind, now, I understood the whole thing :

          First, from the Scintilla documentation, I saw that there a similar message to BackspaceUnindents, which is TabIndents. Note that, by default Notepad++ starts with the TabIndents message activated and with the BackspaceUnindents message deactivated !

          So, I created an other python script, called TabIndents.py, in order to activate/deactivate the TabIndents message. I get absolutely no credit because it’s just a copy/paste of the Alan’s script !

          from Npp import editor, notepad, NOTIFICATION
          
          class TabIndents(object):
          
              def __init__(self):
                  self.activated = True
                  notepad.callback(self.callback_for_bufferactivated, [NOTIFICATION.BUFFERACTIVATED])
                  self.callback_for_bufferactivated(None)  # set it for the currently active document
          
              def callback_for_bufferactivated(self, args):
                  # this document property won't automatically be applied to newly created tabs; adjust for that:
                  editor.setTabIndents(self.activated)
          
              def is_activated(self): return self.activated
          
              def set_activated(self, b):
                  self.activated = b
                  self.callback_for_bufferactivated(None)
          
          if __name__ == '__main__':
          
              try:
                  tab_indents
              except NameError:
                  tab_indents = TabIndents()
                  notepad.messageBox('TabIndents installed and activated')
              else:
                  if tab_indents.is_activated():
                      tab_indents.set_activated(False)
                      notepad.messageBox('TabIndents deactivated')
                  else:
                      tab_indents.set_activated(True)
                      notepad.messageBox('TabIndents activated')
          

          Then I played around, with a sample line of mixed TAB and SPACE chars, both, in the leading part and further on, between usual characters :

          • Activating / deactivating the TabIndents.py and/or the BaskspaceUnindents.py messages

          • Choosing, either, 1 TAB char of 4 positions long OR 4 SPACE chars, when you hit the TAB key, for language normal, in Preferences... > Language > Tab Settings > normal

          • Moving caret within the leading blank chars OR in subsequents blanks ranges, further on, in current line

          And, here is, below, a summary of my observations :


          Regarding the BACKSPACE key behaviour :

          • If caret within the leading blank range of chars AND BackspaceUnindents message activated [ NEW backspace behaviour ] :

            • If setting TAB to 4 SPACE chars, a hit on the BACKSPACE key :

              • Deletes previous char(s) to get the previous indentation level
              • Normalizes all preceding blank chars, till beginning of line, to SPACE chars
              • Moves the caret after the last leading SPACE char
            • If setting TAB to 1 TABchar of 4 positions long, a hit on the BACKSPACE key :

              • Deletes previous char(s) to get the previous indentation level
              • Normalizes all preceding blank chars, till beginning of line, to TAB chars
              • Moves the caret after the last leading TAB char
          • If caret outside the leading blank range of chars OR BackspaceUnindents message deactivated OR by DEFAULT, a hit on the BACKSPACE key :

            • Deletes previous char to get the correct or previous indentation level
            • Leave the caret at current position

          Regarding the TAB key behaviour :

          • If caret outside the leading blank range of chars, whatever the status of the TabIndents message :

            • When setting TAB to 4 SPACE chars, a hit on the TAB key :

              • Adds up to 4 SPACE char(s) to get the next indentation level
              • Leave the caret right after these added SPACE char(s)
            • When setting TAB to a 1 TAB of 4 positions long , a hit on the TAB key :

              • Adds a TAB char to get the next indentation level
              • Leave the caret right after the added TAB char
          • If caret within the leading blank range of chars :

            • If the TabIndents message is activated OR by DEFAULT :

              • When setting TAB to 4 SPACE chars, a hit on the TAB key :

                • Adds up to 4 SPACE char(s) to get the next indentation level
                • Normalizes all preceding blank chars, till beginning of line, to SPACE chars
                • Moves the caret after the last leading SPACE char
              • When setting TAB to a 1 TAB of 4 positions long , a hit on the TAB key :

                • Adds a TAB char to get the next indentation level
                • Normalizes all preceding blank chars, till beginning of line, to TAB chars
                • Moves the caret after the last leading TAB char
            • If the TabIndents message is deactivated [ NEW tab behaviour ] :

              • When setting TAB to 4 SPACE chars, a hit on the TAB key :

                • Adds up to 4 SPACE char(s) to get the next indentation level
                • Leave the caret right after these added SPACE char(s)
              • When setting TAB to a 1 TAB of 4 positions long , a hit on the TAB key :

                • Adds a TAB char to get the next indentation level
                • Leave the caret right after the added TAB char

          Best Regards,

          guy038

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

            Based upon @guy038’s in-depth treatment just ABOVE, and some experimentation on my own based upon it, I decided that I think I don’t like how Scintilla’s backspace-unindents works. :-(

            So I am getting rid of the script I posted above, and going back to the script I had previously (where I did things much more “manually”), which did more of what I want/expect. :-)

            1 Reply Last reply Reply Quote 1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors