Clear All Bookmarks in Macro?

Clear All Bookmarks in Macro?

3
NewbieNewbie
3

    Feb 09, 2010#1

    Is there a way to clear all bookmarks in an macro? I don't see a hot key defined by default. Do I need to define one? Or is there a command or a way to selected it from a menu from a macro?

    I want to avoid defining a hot key because this macro will be used by other people then I will have to make sure they have the same hot key defined.

    6,681583
    Grand MasterGrand Master
    6,681583

      Feb 10, 2010#2

      Macros can't execute menu commands. In macros only those commands are available which are listed in the macro editor dialog and its help page. There is no macro command to delete all bookmarks in the active file.

      To delete all bookmarks in the active file from within a macro you can use following code:

      Loop
      Bottom
      PreviousBookmark
      Key END
      IfEof
      ExitLoop
      Else
      ToggleBookmark
      EndIf
      EndLoop
      Key UP ARROW
      PreviousBookmark

      Key END
      IfEof
      ToggleBookmark
      EndIf

      Top

      2
      NewbieNewbie
      2

        Jun 19, 2011#3

        Hi,
        I know this topic is a little bit old, but I need some help as I am having issues with the macro mentioned here.
        For some reason the macro always ends with an endless loop on bottom line toggling the bookmark on and off.

        I thought adding the command "Bottom" right after "ToggleBookmark" will fix it because "IfEof" can only happen on "Bottom", but it doesn't...
        Am I missing something here?

        Thank you in advance

          Jun 19, 2011#4

          I got some progress here...

          "PreviousBookmark" command always put the cursor on the beginning of the line, therefore when the bottom line is bookmarked and containing any text, "IfEof" never happen and the loop is endless. Putting "Key END" right after fixes this issue. But this creates another sort of a problem when the bottom line is bookmarked because this is also the Eof and the Loop will just exit. I fixed that by inserting a line before the loop and remove it right after.

          This is my final macro, any improvments are welcome:
          Bottom
          InsertLine
          Loop 0
          Bottom
          PreviousBookmark
          Key END
          IfEof
          ExitLoop
          Else
          ToggleBookmark
          EndIf
          EndLoop
          Bottom
          Key BACKSPACE
          Top

          6,681583
          Grand MasterGrand Master
          6,681583

            Jun 19, 2011#5

            It depends on configuration setting Bookmark column with line available since UE v12.20 and UES v6.00 to which column the caret is set on execution of PreviousBookmark command. If this setting is not enabled, the caret is always set to beginning of the bookmarked line. But if this setting is enabled, the caret is positioned on the column the caret was on setting the bookmark.

            You are correct that my initial macro has not cleared all bookmarks if
            • The file ends with a line termination and a bookmark was set at end of file (on the blank line at bottom).
            • The file does not have a line termination at end, and Bookmark column with line is enabled, and the bookmark was set as caret was at end of file.
            In both cases the macro exited after clearing all bookmarks except the bookmark at end of file. A bookmark at end of file is removed now also with the green highlighted macro code added to the macro code in my first post.

            Daemon, your solution works usually also, but always modifies the file which is not good and of course fails on a read-only file.

            I could also reproduce the endless loop. If setting Bookmark column with line is not enabled and the file does not end with a line termination and command PreviousBookmark is executed with no bookmark present anymore UltraEdit v17.10.0.1010 moves the caret to beginning of the last line. This was an unexpected behavior for me and is in my point of view definitely not correct. The caret should not be moved if a goto bookmark command is executed, but there is no bookmark set. It looks like UltraEdit is moving always first the caret to start of current line and then jumps to the bookmarked line which fails if there is no line bookmarked anymore. A better behavior would be first to check if the bookmark to jump exists and only if this is the case, the caret should be moved to start of the bookmarked line. I reported this issue by email to IDM support and IDM rated it as a wrong behavior.

            I found a workaround for above described issue of UltraEdit by inserting twice the command Key END highlighted in my previous post with red color as you, Daemon, have done too.

            There is now just one problem left. If the active file is completely empty and no bookmark is set, execution of the macro results in setting a bookmark. But I expect that nobody runs this macro on an empty file with no bookmark set.