Community
    • Login

    Column Index of Pipelined Lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 677 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.
    • Deniz KasarD
      Deniz Kasar
      last edited by

      Hello,
      I have a line like that:
      aaa|bbb|ccc|ddd|eee|fff

      I want it show me the zero based column index of clicked part.
      For example:
      when i click to bbb , i want to see 1,
      when i click to eee, i want to see 4 on the app window.

      I have very long lines. It would be perfect to see its column index. Thank you.

      Alan KilbornA 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Deniz Kasar
        last edited by

        @Deniz-Kasar

        If you are willing to use the PythonScript plugin to achieve this, a script that I call ShowDelimitedColIndexOnStatusBar.py is shown below:

        # -*- coding: utf-8 -*-
        from __future__ import print_function
        
        # references:
        #  https://community.notepad-plus-plus.org/topic/23501/column-index-of-pipelined-lines
        
        from Npp import *
        
        #-------------------------------------------------------------------------------
        
        class SDCIOSB(object):
        
            def __init__(self):
                self.debug = True if 0 else False
                editor.callback(self.updateui_callback, [SCINTILLANOTIFICATION.UPDATEUI])
        
            def updateui_callback(self, args):
                self.print('UPDATEUI:', args)
                cp = editor.getCurrentPos()
                self.sb_output('Column-group index:', len(editor.getTextRange(editor.positionFromLine(editor.lineFromPosition(cp)), cp).split('|')))
                # aaa|bbb|ccc|ddd|eee|fff
        
            def print(self, *args):
                if self.debug:
                    #console.show()
                    print('SDCIOSB:', *args)
        
            def sb_output(self, *args):  # output to N++'s status bar (will be overwritten by N++ e.g. when active tab is changed)
                notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, ' '.join(map(str, args)))
        
        #-------------------------------------------------------------------------------
        
        # to run via another file, e.g., startup.py, put these lines (uncommented and unindented) in that file:
        #  import ShowDelimitedColIndexOnStatusBar
        #  sdciosb = ShowDelimitedColIndexOnStatusBar.SDCIOSB()
        
        if __name__ == '__main__': SDCIOSB()
        

        When the script is active, it will show the information in the Notepad++ status bar:

        4b33a282-015d-4d2c-adec-6473c0c411ae-image.png

        Basic information about PythonScripting is found HERE.

        1 Reply Last reply Reply Quote 2
        • Alan KilbornA Alan Kilborn referenced this topic on
        • Alan KilbornA
          Alan Kilborn @Deniz Kasar
          last edited by

          @Deniz-Kasar said in Column Index of Pipelined Lines:

          when i click to bbb , i want to see 1

          Hm, it looks like what I provided would output a 2 in such a circumstance. Simple enough to change the len(...) expression in the code to len(...) - 1…

          Deniz KasarD 2 Replies Last reply Reply Quote 2
          • Deniz KasarD
            Deniz Kasar @Alan Kilborn
            last edited by

            @Alan-Kilborn
            Waov, it is perfectly working. This solution is exactly what i look for. Thank you very much.

            1 Reply Last reply Reply Quote 1
            • Deniz KasarD
              Deniz Kasar @Alan Kilborn
              last edited by

              @Alan-Kilborn
              Hi Alan, i have one last a simple question.

              How can i set your script to run on startup? When i close and re-open NP++, your script needs to click to run.

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA Alan Kilborn referenced this topic on
              • Alan KilbornA
                Alan Kilborn @Deniz Kasar
                last edited by Alan Kilborn

                @Deniz-Kasar said in Column Index of Pipelined Lines:

                How can i set your script to run on startup?

                • see the instructions in the script code starting with to run via another file…
                • and also references to startup script HERE
                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors