Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Pythonscript: Is there a way to detect changes in bookmarks?

    Help wanted · · · – – – · · ·
    pythonscript bookmarks bookmark callback plugin
    3
    7
    132
    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.
    • kiyn
      kiyn last edited by

      My need is to detect any addition or removal of bookmarks.

      The closest I have found is the callback SCINTILLANOTIFICATION.MARGINCLICK, which works fine if you edit bookmarks from the left margin, but cannot detect if they are edited in any other way (shortcuts, macros, toolbar, menu, plugin GUI).

      Any kind of suggestions or help will be greatly appreciated.
      Thanks

      Alan Kilborn dail 2 Replies Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @kiyn last edited by

        @kiyn

        I don’t think you’re going to be able to get anything like a “notification” about this. Meaning that you would likely have to resort to a “polling” approach, where you examine every line in a file as to whether it current has or doesn’t have a bookmark. This is probably not the answer you wanted. :-(

        Alan Kilborn 1 Reply Last reply Reply Quote 1
        • dail
          dail @kiyn last edited by

          @kiyn

          You can catch the SCN_MODIFIED notification and check for the SC_MOD_CHANGEMARKER flag.

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

            @Alan-Kilborn said in Pythonscript: Is there a way to detect changes in bookmarks?:

            I don’t think you’re going to be able to get anything like a “notification” about this

            @dail said:

            You can catch the SCN_MODIFIED notification and check for the SC_MOD_CHANGEMARKER flag.

            I love to be wrong, especially when we get increased functionality from my wrongness. :-)

            Here’s a PS demo of what dail expressed above:

            # -*- coding: utf-8 -*-
            
            from Npp import editor, SCINTILLANOTIFICATION, MODIFICATIONFLAGS
            
            def callback_sci_MODIFIED(args):
                if args['modificationType'] & MODIFICATIONFLAGS.CHANGEMARKER:
                    line = editor.lineFromPosition(args['position'])
                    print('bookmark placed/removed on line {}'.format(line + 1))
            editor.callback(callback_sci_MODIFIED, [SCINTILLANOTIFICATION.MODIFIED])
            
            1 Reply Last reply Reply Quote 5
            • Alan Kilborn
              Alan Kilborn last edited by

              I guess we can refine it a bit more, in order to tell a placement from a removal:

              # -*- coding: utf-8 -*-
              
              from Npp import editor, SCINTILLANOTIFICATION, MODIFICATIONFLAGS
              
              MARK_BOOKMARK = 24  # from N++ source code
              
              def callback_sci_MODIFIED(args):
                  if args['modificationType'] & MODIFICATIONFLAGS.CHANGEMARKER:
                      line = editor.lineFromPosition(args['position'])
                      if editor.markerGet(line) & (1 << MARK_BOOKMARK):
                          print('bookmark placed on line {}'.format(line + 1))
                      else:
                          print('bookmark removed on line {}'.format(line + 1))
              editor.callback(callback_sci_MODIFIED, [SCINTILLANOTIFICATION.MODIFIED])
              
              1 Reply Last reply Reply Quote 6
              • kiyn
                kiyn last edited by

                That’s exactly what I was hoping for.
                I would never have succeeded by myself.
                Thanks a lot to both of you!

                1 Reply Last reply Reply Quote 2
                • Alan Kilborn
                  Alan Kilborn last edited by

                  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 4
                  • First post
                    Last post
                  Copyright © 2014 NodeBB Forums | Contributors