Community
    • Login

    plugin that support auto-numbering

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    23 Posts 6 Posters 9.7k Views 1 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.
    • StoopidoManS Offline
      StoopidoMan @StoopidoMan
      last edited by

      @Alan-Kilborn
      One more thing 😬 if possible add this feature: pressing backspace would stop NumberingAutomagically, here is what I mean:

      1- test
      2- test
      3- (here if you entered backspace it would remove [3-] instead of pressing backspace 3 times to stop NumberingAutomagically )

      I think many would love that since that how Microsoft word Functions, And again, THANK YOU🙏

      BobbstermanB 1 Reply Last reply Reply Quote 0
      • BobbstermanB Offline
        Bobbsterman @StoopidoMan
        last edited by

        @StoopidoMan and anyone else still interested,

        I modded the script to add 2 new functionalities:

        • Bullet lists now supported (only “+” signs accepted at the moment)
        • If you create a new line but have not written anything after the bullet or number (anything other than non-word chars) then the list ends, adding no new list item. This is similar to how Word handles lists (where pressing “Enter” twice ends the list).

        Code below:

        # -*- coding: utf-8 -*-
        
        from Npp import editor, SCINTILLANOTIFICATION
        import re
        
        class NA(object):
        
            def __init__(self):
                self.eol = ['\r\n', '\r', '\n'][editor.getEOLMode()]
                editor.callback(self.callback_sci_CHARADDED, [SCINTILLANOTIFICATION.CHARADDED])
        
            def callback_sci_CHARADDED(self, args):
                if chr(args['ch']) == self.eol[-1]:
                    caret_pos = editor.getCurrentPos()
                    curr_line_num = editor.lineFromPosition(caret_pos)
                    if curr_line_num > 0:
                        prev_line = editor.getLine(curr_line_num - 1)
                        m = re.match(r'\s*(\d+)([^\w\r\n]+)', prev_line)
                        if m:
                            full = str(m.group(1)) + str(m.group(2))
                            full_prev = prev_line.rstrip('\r\n')
                            if (len(full_prev) > len(full)):
                            # if m:
                                prev_number = int(m.group(1))
                                symbols_after = m.group(2)
                                new_number = prev_number + 1
                                text_to_insert = str(new_number) + symbols_after
                                editor.insertText(caret_pos, text_to_insert)
                                new_caret_pos = caret_pos + len(text_to_insert)
                                editor.setEmptySelection(new_caret_pos)
                                return
                        m = re.match(r'\s*(\+)([^\w\r\n]+)', prev_line)
                        if m:
                            full = str(m.group(1)) + str(m.group(2))
                            full_prev = prev_line.rstrip('\r\n')
                            if (len(full_prev) > len(full)):
                            # if m:
                                bullet = m.group(1)
                                symbols_after = m.group(2)
                                text_to_insert = bullet + symbols_after
                                editor.insertText(caret_pos, text_to_insert)
                                new_caret_pos = caret_pos + len(text_to_insert)
                                editor.setEmptySelection(new_caret_pos)
                                return
        
        if __name__ == '__main__':
        
            try:
                na
            except NameError:
                na = NA()
        
        BobbstermanB 1 Reply Last reply Reply Quote 1
        • BobbstermanB Offline
          Bobbsterman @Bobbsterman
          last edited by Bobbsterman

          Tiny improvement (IMO) for bullet list: now it only copies spaces, no punctuation:

          
          from Npp import editor, SCINTILLANOTIFICATION
          import re
          
          class NA(object):
          
              def __init__(self):
                  self.eol = ['\r\n', '\r', '\n'][editor.getEOLMode()]
                  editor.callback(self.callback_sci_CHARADDED, [SCINTILLANOTIFICATION.CHARADDED])
          
              def callback_sci_CHARADDED(self, args):
                  if chr(args['ch']) == self.eol[-1]:
                      caret_pos = editor.getCurrentPos()
                      curr_line_num = editor.lineFromPosition(caret_pos)
                      if curr_line_num > 0:
                          prev_line = editor.getLine(curr_line_num - 1)
                          m = re.match(r'\s*(\d+)([^\w\r\n]+)', prev_line)
                          if m:
                              full = str(m.group(1)) + str(m.group(2))
                              full_prev = prev_line.rstrip('\r\n')
                              if (len(full_prev) > len(full)):
                              # if m:
                                  prev_number = int(m.group(1))
                                  symbols_after = m.group(2)
                                  new_number = prev_number + 1
                                  text_to_insert = str(new_number) + symbols_after
                                  editor.insertText(caret_pos, text_to_insert)
                                  new_caret_pos = caret_pos + len(text_to_insert)
                                  editor.setEmptySelection(new_caret_pos)
                                  return
                          m = re.match(r'\s*(\+)([\s*]+)', prev_line)
                          if m:
                              full = str(m.group(1)) + str(m.group(2))
                              full_prev = prev_line.rstrip('\r\n')
                              if (len(full_prev) > len(full)):
                              # if m:
                                  bullet = m.group(1)
                                  symbols_after = m.group(2)
                                  text_to_insert = bullet + symbols_after
                                  editor.insertText(caret_pos, text_to_insert)
                                  new_caret_pos = caret_pos + len(text_to_insert)
                                  editor.setEmptySelection(new_caret_pos)
                                  return
          
          if __name__ == '__main__':
          
              try:
                  na
              except NameError:
                  na = NA()
          
          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