Copying all bookmarked lines to active clipboard

Copying all bookmarked lines to active clipboard

2
NewbieNewbie
2

    Mar 24, 2011#1

    Is there any way of copying all bookmarked lines?

    6,686585
    Grand MasterGrand Master
    6,686585

      Mar 24, 2011#2

      Not with an internal command. There is a macro solution, see Copy to clipboard bookmarked lines?

      Nowadays I would do that with a script which would have the advantage to not modify the file because the line number of first bookmark could be remembered and compared in the loop for exit condition.

      Update: Commands to cut or copy all bookmarked lines to clipboard are available since UltraEdit for Windows v22.00 and UEStudio v15.10.

      2
      NewbieNewbie
      2

        Mar 25, 2011#3

        Thanks Mofi

        Sounds like an enhancement request to me.

        6,686585
        Grand MasterGrand Master
        6,686585

          Mar 26, 2011#4

          Why requesting and waiting for something which you can easily already have using existing macro or using a script added to the list of scripts?

          I have developed now a script with a function to copy all bookmarked lines to active clipboard. Hard to deal with is first line of file bookmarked. Therefore the script is more complicated as I first thought to handle this situation also correct in any case.

          Please note: The command selectLine() selects only the displayed line of a soft wrapped long line. Therefore the script as is does not copy the long line entirely if a wrapped line is bookmarked. For that task it would be necessary to select a bookmarked line with a regular expression search. But I think the users using this script do not work often with wrapped lines and simply turning off word-wrap before using this script and then enable it again should not be too difficult.

          I expect that not many users really need that function. The menu View has already too many commands for a resolution of 1024x768 and menu Edit is also nearly full of commands. Therefore I think, such commands not needed by a really big number of UltraEdit users should not be added by IDM to UltraEdit. Such extensions can be solved by scripts or macros.

          Code: Select all

          function CopyBookmarkedLines () {
             // Remember active caret position.
             var nActLine = UltraEdit.activeDocument.currentLineNum;
             var nActCol = UltraEdit.activeDocument.currentColumnNum;
             if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nActCol++;
             // Move caret to top of file.
             UltraEdit.activeDocument.top();
             // Move caret to next bookmark.
             UltraEdit.activeDocument.gotoBookmark(-1);
             // Get line number of first bookmark.
             var nFirstBookmark = UltraEdit.activeDocument.currentLineNum;
             // Is the caret still on first line of the file?
             if (nFirstBookmark > 1) {
                // No, then the file has bookmarked lines. But it is possible that
                // first line is also bookmarked and the caret is now already on
                // second bookmark. To check this, the Goto Previous Bookmark command
                // is executed next. If the line number is then 1, the first line
                // is bookmarked, otherwise the first Goto Next Bookmark command
                // moved the caret really to first bookmarked line in the file.
                UltraEdit.activeDocument.previousBookmark();
                if (UltraEdit.activeDocument.currentLineNum != 1) {
                   UltraEdit.activeDocument.gotoLine(nFirstBookmark,1);
                } else nFirstBookmark = 1;
                // Copy the first bookmarked line to active clipboard.
                UltraEdit.activeDocument.selectLine();
                UltraEdit.activeDocument.copy();
                var nLineCount = 1;
                // Append all other bookmarked lines to active clipboard.
                while (1) {
                   UltraEdit.activeDocument.gotoBookmark(-1);
                   if (UltraEdit.activeDocument.currentLineNum == nFirstBookmark) {
                      // All bookmarked lines copied. Restore initial position
                      // of the caret and return the number of copied lines.
                      UltraEdit.activeDocument.gotoLine(nActLine,nActCol);
                      return nLineCount;
                   }
                   UltraEdit.activeDocument.selectLine();
                   UltraEdit.activeDocument.copyAppend();
                   nLineCount++;
                }
             }
             else {
                // Yes, either the first line is bookmarked and the first line is the
                // only bookmarked line, or the file does not contain any bookmark.
                // Bookmark on first line is very difficult to find out because it
                // is possible that the file contains only a string at top of the
                // file and no line termination at all (= no second line). The command
                // Next Bookmark moves caret to start of active line or does not move
                // the caret depending on configuration setting "Bookmark column with
                // line" if no bookmark is set. However, with moving the caret one
                // character to right if at start of first line ore to left and
                // additionally one line down (if there is a second line), remembering
                // the caret position, running Next Bookmark command again and check
                // the new caret position, it can be find out if the first line is
                // bookmarked or not, independent of the configuration setting and
                // if there is a second line at all or not. It is possible that one
                // bookmark is set on empty file, but then there is nothing to copy.
                if (UltraEdit.activeDocument.isColNum(1)) {
                   UltraEdit.activeDocument.key("RIGHT ARROW");
                } else {
                   UltraEdit.activeDocument.key("LEFT ARROW");
                }
                UltraEdit.activeDocument.key("DOWN ARROW");
                var nFilePos = UltraEdit.activeDocument.currentPos;
                UltraEdit.activeDocument.gotoBookmark(-1);
                if (UltraEdit.activeDocument.currentPos == nFilePos ||
                    UltraEdit.activeDocument.currentLineNum == 2) {
                   UltraEdit.activeDocument.gotoLine(nActLine,nActCol);
                   return 0;
                }
                // Just the first line of the file is bookmarked. Copy that line
                // to the clipboard and move caret back to initial position.
                UltraEdit.activeDocument.selectLine();
                UltraEdit.activeDocument.copy();
                UltraEdit.activeDocument.gotoLine(nActLine,nActCol);
                return 1;
             }
          }
          
          if (UltraEdit.document.length > 0) {
             var nCopiedLines = CopyBookmarkedLines();
             if (!nCopiedLines) UltraEdit.messageBox("The active file does not contain any bookmarked line.","Copy Bookmarked Lines");
             else {
                var sLine = (nCopiedLines == 1) ? "line" : "lines";
                UltraEdit.messageBox(nCopiedLines.toString() + " bookmarked " + sLine + " copied to clipboard.","Copy Bookmarked Lines");
             }
          }

          1
          NewbieNewbie
          1

            Feb 11, 2015#5

            Looks like this and or UE has a 500 limit?
            It runs fine and correct, but ends at 500 bookmarks copied.
            I have a file of 1500 bookmarks and as I stated the JS script stops at 500?

            6,686585
            Grand MasterGrand Master
            6,686585

              Feb 12, 2015#6

              Yes, there is the limit of 500 bookmarks as written already once, see Is there a limit for bookmarks per file?

              Bookmarks can be saved for each opened file on exit of a project/workspace in workspace file and are restored in this case on opening project/workspace again. Therefore it makes sense to limit the number of bookmarks per file.

              This script is not needed anymore with UltraEdit for Windows v22.00 and UEStudio v15.10 and any later version of UE/UES because of the commands Copy All Bookmarked Lines and Cut All Bookmarked Lines in menu Search - Bookmarks which are available also as macro and scripting commands like the other new command Trim Leading Spaces in menu Format also introduced with UE v22.00 / UES v15.10.
              Best regards from an UC/UE/UES for Windows user from Austria