• Login
Community
  • Login

Shortcut for bookmark selected text?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 4 Posters 7.0k 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.
  • G
    Grenville Tryon
    last edited by Dec 13, 2016, 2:59 PM

    Is there any way to mark a block, and pressing a shortcut, bookmark all the coincidences in the file? I tried to make a macro for the task without success.
    (Currently I have to press control-F, select the mark tab, check the bookmark line and press “mark all”).
    Is a task I use 10 times a day, a shorcut for that task will be welcome.

    C 1 Reply Last reply Dec 13, 2016, 3:48 PM Reply Quote 0
    • C
      Claudia Frank @Grenville Tryon
      last edited by Dec 13, 2016, 3:48 PM

      @Grenville-Tryon

      may I ask what your final goal is. Is it just to have a visible indication about
      the same text or do you want to use bookmark function like cutting
      the bookmarked text or non-bookmarked text etc. ?

      Cheers
      Claudia

      1 Reply Last reply Reply Quote 0
      • G
        Grenville Tryon
        last edited by Dec 13, 2016, 4:03 PM

        Thanks for your time. Is a mix :
        50% times: f2 is a useful way to go to the next patch line without loose the attributes like color mark,
        20% times: replace text (with a visible mark to replace / test / undo replace only in some)
        10% times: copy all bookmarkes lines to a new file
        10% times: cut all bookmarks
        10% times: inverse selection

        1 Reply Last reply Reply Quote 0
        • G
          guy038
          last edited by Dec 13, 2016, 4:31 PM

          Hello, Grenville Tryon,

          I’ve been able to build a macro, which can be launched with a shortcut, to mark all occurrences of a specific text. But, unfortunately, as we cannot enter parameters, in N++'s macros, this text to search is written, namely :-((

          For instance, if you insert, in the macro section, of your active shortcuts.xml file, the text below, it would bookmark all lines, containing, at least, one occurrence, of the word Test, with that exact case, in normal search mode and downwards direction

              <Macro name="Mark Occurrences" Ctrl="yes" Alt="yes" Shift="no" Key="77">
                  <Action type="0" message="2316" wParam="0" lParam="0" sParam="" />
                  <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                  <Action type="3" message="1601" wParam="0" lParam="0" sParam="Test" />
                  <Action type="3" message="1625" wParam="0" lParam="0" sParam="" />
                  <Action type="3" message="1702" wParam="0" lParam="530" sParam="" />
                  <Action type="3" message="1701" wParam="0" lParam="1615" sParam="" />
              </Macro>
          

          Note that you must :

          • Close any N++ instance, first

          • Edit the Shortcuts.xml file, with an OTHER editor than Notepad++ ( Important ! )

          • Insert the block of text and save it

          • Finally, re-open N++

          Later, you should change, in Shortcuts.xml, the present word Test by the other word to search for :-(( Not acceptable, of course !

          But, certainly, your goal could be achieved with a Python or Lua script !

          Best Regards,

          guy038

          G 1 Reply Last reply Dec 13, 2016, 4:42 PM Reply Quote 0
          • G
            Grenville Tryon @guy038
            last edited by Dec 13, 2016, 4:42 PM

            @guy038 , I tried your shortcut test as indicated and works as desired (as you marked, only for the “Test” word). Still looking, but you gave a couple of clues. Thanks!

            C 1 Reply Last reply Dec 13, 2016, 5:26 PM Reply Quote 0
            • C
              Claudia Frank @Grenville Tryon
              last edited by Claudia Frank Dec 13, 2016, 5:26 PM Dec 13, 2016, 5:26 PM

              @Grenville-Tryon

              the problem with macros and selected text is that it records the text as well,
              which, I guess, isn’t desirable in your case.

              What I could offer would be a python script, which basically emulates
              npps bookmark functionality. This has the advantage that you can use npps
              builtin functions like cut bookmarked lines, clear bookmark etc.

              If you haven’t installed python script plugin already than I would suggest
              to download the msi from here instead using plugin manager.

              Once installed, run Plugins->PythonScript->New Script, give it a meaningful name
              and put the following into it.

              SCE_UNIVERSAL_FOUND_STYLE = 31
              MARK_BOOKMARK = 24
              
              def clear_previous_marks():
                  editor.setIndicatorCurrent(SCE_UNIVERSAL_FOUND_STYLE)
                  editor.indicatorClearRange(0,editor.getTextLength()) 
                  editor.markerDeleteAll(MARK_BOOKMARK)
              
              def match_found(m):
                  targetStart = m.span(0)[0]
                  foundTextLen = m.span(0)[1] - m.span(0)[0]
                  
                  editor.setIndicatorCurrent(SCE_UNIVERSAL_FOUND_STYLE)
                  editor.indicatorFillRange(targetStart, foundTextLen)
              
                  lineNumber = editor.lineFromPosition(targetStart)
                  editor.markerAdd(lineNumber, MARK_BOOKMARK)
              
              clear_previous_marks()
              pattern = editor.getSelText()
              if pattern != '':
                  editor.research(pattern, match_found) 
              

              Save it.
              Now you either can assign a shortcut or put it into the context menu (right click menu).
              If you need help solving this - let us know.

              Cheers
              Claudia

              G 1 Reply Last reply Dec 13, 2016, 6:10 PM Reply Quote 0
              • G
                Grenville Tryon @Claudia Frank
                last edited by Dec 13, 2016, 6:10 PM

                @Claudia-Frank
                Work exactly as needed. Thank you very much, you made my day!

                C 1 Reply Last reply Dec 13, 2016, 6:26 PM Reply Quote 0
                • C
                  Claudia Frank @Grenville Tryon
                  last edited by Dec 13, 2016, 6:26 PM

                  @Grenville-Tryon

                  just noticed that I was using

                  editor.research(pattern, match_found)
                  

                  but maybe you wanna use

                  editor.search(pattern, match_found)
                  

                  instead, otherwise the string is treated as a regular expression.

                  Cheers
                  Claudia

                  1 Reply Last reply Reply Quote 0
                  • P PeterJones unlocked this topic on Dec 20, 2022, 11:12 PM
                  • A
                    Alan Kilborn
                    last edited by Dec 21, 2022, 12:03 AM

                    The marker ID used for bookmarks changed in Notepad++ 8.4.6 (and later). It is now 20, instead of 24. So, all references to 24 in this thread and/or its script(s), should be changed to 20.

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