• Login
Community
  • Login

Column Index of Pipelined Lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 2 Posters 1.2k 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.
  • D
    Deniz Kasar
    last edited by Sep 20, 2022, 8:54 AM

    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.

    A 2 Replies Last reply Sep 20, 2022, 12:26 PM Reply Quote 0
    • A
      Alan Kilborn @Deniz Kasar
      last edited by Sep 20, 2022, 12:26 PM

      @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
      • A Alan Kilborn referenced this topic on Sep 20, 2022, 12:26 PM
      • A
        Alan Kilborn @Deniz Kasar
        last edited by Sep 20, 2022, 3:27 PM

        @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…

        D 2 Replies Last reply Sep 20, 2022, 5:27 PM Reply Quote 2
        • D
          Deniz Kasar @Alan Kilborn
          last edited by Sep 20, 2022, 5:27 PM

          @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
          • D
            Deniz Kasar @Alan Kilborn
            last edited by Sep 21, 2022, 5:56 AM

            @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.

            A 1 Reply Last reply Sep 21, 2022, 11:47 AM Reply Quote 0
            • A Alan Kilborn referenced this topic on Sep 21, 2022, 11:44 AM
            • A
              Alan Kilborn @Deniz Kasar
              last edited by Alan Kilborn Sep 21, 2022, 11:48 AM Sep 21, 2022, 11:47 AM

              @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
              4 out of 6
              • First post
                4/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors