Tapatalk

Collapsing tags at the same level

Collapsing tags at the same level

1
NewbieNewbie
1

    Jun 16, 2014#1

    Dear Community:

    I saw this discussion thread in 2005 and would like to know: Is there a solution in the current version of UltraEdit Professional Text/HEX Editor Version 21.10.0.1032? I want to collapse tags that are at the same level instead of going one by one which is really disgusting/boring and tiring.

    Thanks in advanced.

    XML_Developer

    6,685587
    Grand MasterGrand Master
    6,685587

      Jun 17, 2014#2

      There is no built-in command to collapse all based on folding level in UE v21.10.0.1032 which I think would be a nice feature.

      Such a feature could be implemented with an UltraEdit script for certain languages if the active file is well indented. Here is an example for such a script quickly written because of your question.

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Define environment for this script.
         UltraEdit.insertMode();
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
      
         // Remember current position of caret in the file.
         var nLine = UltraEdit.activeDocument.currentLineNum;
         var nColumn = UltraEdit.activeDocument.currentColumnNum;
         var sIndent = "";
      
         // Move caret to column 1 in current line.
         UltraEdit.activeDocument.gotoLine(nLine,1);
         // Select the whitespaces at beginning of this line.
         UltraEdit.activeDocument.selectWord();
         // Nothing is selected if caret is currently on a blank line.
         if (UltraEdit.activeDocument.isSel())
         {
            // Get the selected indent (= selected "word").
            var sIndent = UltraEdit.activeDocument.selection;
            // Is really an indent or a word selected?
            if (sIndent.search(/\S/) >= 0) sIndent = "";
         }
         // Move caret to top of the active file.
         UltraEdit.activeDocument.top();
      
         // For C/C++/C# and JavaScript the open fold string is an open brace.
         var sFold = "%" + sIndent + "{";
      
         // Define the parameters for an UltraEdit regular expression search.
         UltraEdit.ueReOn();
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=true;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
         {
            UltraEdit.activeDocument.findReplace.searchInColumn=false;
         }
      
         // Fold all blocks with an opening brace at current indentation level.
         // Block comments are not folded with this scripting code.
         while(UltraEdit.activeDocument.findReplace.find(sFold))
         {
            UltraEdit.activeDocument.gotoLine(0,1);
            UltraEdit.activeDocument.hideOrShowLines();
            UltraEdit.activeDocument.key("DOWN ARROW");
         }
         // Move caret back to initial position on script start.
         UltraEdit.activeDocument.gotoLine(nLine,nColumn);
      }
      Note: This script does not work for C/C++/C# or JavaScript files using styles like java attach, Kernighan & Ritchie, stroustrup, banner, linux, otbs or lisp as explained on help page with title Artistic Style Formatter dialog. Such coding styles would require a much smarter UltraEdit script.
      Best regards from an UC/UE/UES for Windows user from Austria