Community
    • Login

    UserListGotoLine to goto lines of interest

    Scheduled Pinned Locked Moved General Discussion
    8 Posts 3 Posters 308 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.
    • mpheathM
      mpheath
      last edited by

      UserListGotoLine

      Requires at least PythonScript v2.1 or v3.0.21.
      Get UserListGotoLine.py from https://github.com/mpheath/user-list-goto-line-for-notepad-plus-plus

      Searches the current buffer for lines of interest in Notepad++ and shows a user list that will goto to the line of the selected item.

      The initial list can have these items:

      any word style 0
      bookmarks
      change history
      change history modified
      change history reverted to modified
      change history reverted to origin
      change history saved
      codes
      codes extended
      codes uppercase
      comments
      comments block
      comments doc
      comments docline
      comments nested
      comments reminder
      current char style 0
      current selection
      current selection style 0
      current word
      current word style 0
      folds
      log
      log error
      log fatal
      log timestamp
      log warn
      

      Some items may not be shown if no selection exists, Change History is turned off, …

      • any word style 0
        • List lines that match any word in the detected style number and goto selected line.
      • bookmarks
        • List bookmark lines and goto selected line.
      • change history
        • List all change history lines and goto selected line.
      • change history modified
        • List modified change history lines and goto selected line.
      • change history reverted to modified
        • List reverted to modified change history lines and goto selected line.
      • change history reverted to origin
        • List reverted to origin change history lines and goto selected line.
      • change history saved
        • List saved change history lines and goto selected line.
      • codes
        • List matched code lines and goto selected line.
      • codes extended
        • List matched code lines with an extended pattern and goto selected line.
          Setup for Batch, Inno, Lua and Swift.
      • codes uppercase
        • List matched code lines and with an uppercase word pattern and goto selected line.
          Targets what is known as code constants.
          Example: ABC_7 is valid in a language preset style.
          Setup for Au3, Bash, CoffeeScript, C#, D, GDScript, Go, Inno, Java, JavaScript, Lua, Matlab, Perl, PHP, Powershell, Python, Raku, Ruby, Rust and Swift.
      • comments
        • List comment lines and goto selected line.
      • comments block
        • List comment block lines and goto selected line.
          Setup for Au3, C, C++, C#, EScript, FreeBasic, GDScript, Go, Java, JavaScript, Lua, MSSQL, PHP, Powershell, Python, Raku, Ruby, Rust, SQL and Swift.
      • comments doc
        • List comment document lines and goto selected line.
          Setup for C, C++, C#, COBOL, FreeBasic, Go, Java, JavaScript, Raku, Rust, SQL and Swift.
      • comments docline
        • List comment single line document lines and goto selected line.
          Setup for D.
      • comments nested
        • List comment nested document lines and goto selected line.
          Setup for D.
      • comments reminder
        • List lines containing debug:, reminder:, todo: in line comments and goto selected line.
          Lines of code with end of line comments can be in the list.
      • current char style 0
        • List lines that match current char in the detected style number and goto selected line.
      • current selection
        • List lines that match selection and goto selected line.
      • current selection style 0
        • List lines that match selection in the detected style number and goto selected line.
          Must be word characters matched by re.match ^\w+$ so can be part of a word.
          Added provided it has good use though could change to improve or be removed if it has issues.
      • current word
        • List lines that match current word and goto selected line.
      • current word style 0
        • List lines that match current word in the detected style number and goto selected line.
      • folds
        • List fold lines and goto selected line.
      • log
        • List lines containing error, fatal and warn word variants and goto selected line.
          Files of the type .log are recognized.
      • log error
        • List lines containing word error variants and goto selected line.
      • log fatal
        • List lines containing word fatal and goto selected line.
      • log timestamp
        • List lines with timestamps and goto selected line.
          Language text with .LOG on first line which causes Notepad.exe to auto-insert timestamps.
          If timestamp format re pattern is unspecified in __init__, then the next non-empty line will be read to create a re pattern.
          The created re pattern will detect lines with only a timestamp, though specifying a re pattern will let the user decide the conditions.
          View DotLogTimestamp.py source to use .LOG with Notepad++ using the PythonScript plugin.
      • log warn
        • List lines containing word warn variants and goto selected line.

      An example showing the codes list:

      list.png

      The same format is used for the other lists. The integers on the left are line numbers. The remainder is the line text.

      Languages setup for style detection currently:

      Ada
      Assembly
      AutoIt
      AviSynth
      Batch
      C             (no codes)
      C#
      C++           (no codes)
      CMake
      COBOL
      CoffeeScript
      CSS
      D             (basic codes)
      Diff
      EScript       (no codes)
      Fortran
      FreeBasic
      GDScript
      Go
      HTML
      INI file
      Inno Setup
      Java
      JavaScript
      JSON
      Lua
      Makefile
      Matlab
      MMIXAL
      MSSQL
      Nim
      NSIS
      Pascal
      Perl
      PHP
      Powershell
      Properties
      Python
      Raku
      Registry
      Resource file
      Ruby
      Rust
      Shell
      SQL
      Swift
      TOML
      User: dBASEPlus
      User: Markdown
      User: NppExec
      Visual Basic
      XML
      

      Items like bookmarks, change history, … where style detection is not required can work for any language.

      Note that Notepad++ >= v8.7.6 will style the whole document by default rather than the previous setting of style only of what is shown. Scrolling in later versions may not be needed initially to style the whole document.

      Searching by default is case sensitive unless overridden. So current word search for WORD will find WORD and will not find word.

      Selections other than a main stream selection are not currently handled so attempts at using other selection types may show undesirable results.

      Lines of text added to the list will be maximum 120 characters so long lines may look incomplete. Passing a parameter to the existing called class named UserListGL() like for example

              user_list_gl = UserListGL(150)
      

      will increase the maximum to 150 characters.

      PythonScript plugin:

      • v3.0.21.0 tested as OK.
      • v2.1.0.0 tested and seems OK.
      • v2.0.0.0 is not supported as it is missing some needed functions.

      Get UserListGotoLine.py from https://github.com/mpheath/user-list-goto-line-for-notepad-plus-plus

      Interest in helping with improvements may attract my attention.

      Lycan ThropeL mpheathM 2 Replies Last reply Reply Quote 5
      • Lycan ThropeL
        Lycan Thrope @mpheath
        last edited by

        @mpheath ,
        This works really nice like we talked about. Thanks for this additional tool for languages. Great tool to find lists of program code per language, even UDL’s. :-)

        mpheathM 1 Reply Last reply Reply Quote 1
        • mpheathM
          mpheath @Lycan Thrope
          last edited by

          @Lycan-Thrope Thanks for the praise.

          PROSHEET.txt for the dBASEPlus UDL posted in a Github comment shows lines like:

                function = "!"
          

          which looks like an attribute assignment though function is matched by style 14 so I updated the codes pattern to avoid listing these unwanted lines with an assertion to check ahead for the = character.

          Lycan ThropeL 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn
            last edited by

            I like the idea, and I like the script as-is as a “demo”. Nice job.

            I think for real use it needs to be “subsetted” a bit. For my use, I’d like it for listing out bookmarks and as a quick-search feature for the current word. I can see myself adapting it for these two purposes, probably in two separate scripts.

            The way this works for showing bookmarks is so nice that I’m wondering if it is reasonable as a standard feature in Notepad++.

            I’m always looking for ways to make searching easier, and this could be one of them. (I simply find opening the Find dialog and slogging through FindNext, FindNext, etc. just too annoying/distracting, so I rarely do it – I have some helper scripts that easily run file-level searches and show me Search results, making much less of a disturbance).

            mpheathM 1 Reply Last reply Reply Quote 2
            • Lycan ThropeL
              Lycan Thrope @mpheath
              last edited by

              @mpheath ,
              What you found, is actually a property for an Entryfield object in dBASE Plus, that formats the text in it to look a certain way. In this case, that option converts the letters to uppercase inside of the entryfield object.

              Yes it’s unfortunate, but one of the shortcomings of using the General Purpose parser, is that a property named function will also be highlighted as the keyword Function. Luckily, because of the Function List parser, it won’t be flagged as a function because it doesn’t follow the pattern for Functions in the language. :-)

              1 Reply Last reply Reply Quote 1
              • mpheathM
                mpheath @Alan Kilborn
                last edited by

                @Alan-Kilborn

                I like the idea, and I like the script as-is as a “demo”. Nice job.

                Glad you like the idea.

                The “demo” is a good description of the experience for what is possible. As developing from scratch, it sometimes is unknown what will be the end result.

                I think for real use it needs to be “subsetted” a bit.

                The concept of loading a main script which creates new objects with each run is concerning. The hope is the garbage collector is cleaning up the global environment of unused objects each time an existing class or function is reloaded. It is surely inefficient to do this reloading.

                Ideally, what I did with xconfig with using the lib folder helps to avoid this repetitive reloading. The code could then be broken up as it is contained in the modules imported namespace. The main script then works just with the instance object. Setup of the startup script to do the import is the users script so must be cautious in interacting with it to setup.

                The class was setup a little more like an application rather than a library. The methods could return the searched lines rather than directly calling the user list method. Then other options instead of the user list could be used like output to console, edit pane or to the dark side of the moon.

                The way this works for showing bookmarks is so nice that I’m wondering if it is reasonable as a standard feature in Notepad++.

                Notepad++ could use a graphical listing of such items. Why stop at Bookmarks when Change History, … are also just as satisfying to view in a list. Though I understand that doing one can lead to the next and trying to do it all at once might be very ambitious. If a precedent exists, then perhaps a plan can be formed.

                I’m always looking for ways to make searching easier, and this could be one of them.

                As-is OK. As lib, later perhaps. It takes time to make something grand. ;)

                Here is an example of filtering bookmarked lines in the editor by hiding lines. It toggles. Put the caret to a line and show the lines will put the line with the caret to the top of the editor control.

                # about: Filter bookmarked lines in the editor
                # help: https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript
                # src: https://community.notepad-plus-plus.org/topic/26651
                
                from Npp import editor, notepad
                
                def bookmarks():
                    '''Show only bookmarked lines.'''
                
                    def toggle():
                        '''Toggle hide or show lines.'''
                
                        bookmark = notepad.getBookMarkID()
                        mask = 1 << bookmark
                        items = []
                        last_line = editor.getLineCount()
                
                        for line in range(last_line):
                            if editor.markerGet(line) & mask != 0:
                                items.append(line)
                
                        if not items:
                            return
                
                        if last_line not in items:
                            items.append(last_line)
                
                        pairs = []
                        prev_line = 0
                
                        for line in items:
                            if prev_line <= line:
                                pairs.append([prev_line, line - 1])
                                prev_line = line + 1
                
                        func = editor.hideLines if toggle.hide else editor.showLines
                
                        for items in pairs:
                            editor.ensureVisible(items[0])
                            func(*items)
                
                        if func == editor.showLines:
                            pos = editor.getCurrentPos()
                            line = editor.lineFromPosition(pos)
                            editor.setFirstVisibleLine(line)
                
                        toggle.hide = not toggle.hide
                
                    toggle.hide = True
                    return toggle
                
                try:
                    toggle
                except:
                    toggle = bookmarks()
                
                toggle()
                

                That could be adapted for current word I would presume. It is a little disruptive as bookmarked lines need to shown before hiding them else they will not be visible when in filtered view.

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

                  @mpheath

                  editor.hideLines()

                  As has been discussed in the Community many times, the “hide lines” feature of Notepad++ has problems, so much so that I (at least) have deemed it unusable. If you have success in using it, then good for you.

                  1 Reply Last reply Reply Quote 0
                  • mpheathM
                    mpheath @mpheath
                    last edited by

                    Added marks item to list lines with find, incremental, smart, token 1, token 2, token 3, token 4 or token 5 marks.

                    The marks item and the change history item will open a 2nd user list so the main user list can show less items.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors