Would like to hide comments

Would like to hide comments

20
Basic UserBasic User
20

    Jul 04, 2012#1

    probably by changing comment color to background color... how do I do that automatically?
    I want to press a shortcut key and have the comments turn to white,
    and press another key to turn the color back to what it was.

    If that is not possible, I could invoke an external program that would edit the UEW file.
    I could just edit the file for C lang (which I use most), but it would be better if I could detect which UEW is currently in use... possible?
    Then, how do I force UE to refresh the screen with the new colors?

    As a last option, I could have two sets of UEW files, one with visible comments, and one with non visible comments,
    probably in two separate folders. How would I quickly change between them? (of course, this option I don't like much.)

    2362
    MasterMaster
    2362

      Jul 04, 2012#2

      These options you list simply will not work well at all.

      Even if you find a way to change the UEW file, it is loaded into memory by UE and the changes will not be recognized.

      Let me give you a possibility:
      The only way to have UE recognize the changes is to have the particular UEW file in question loaded into an edit window, and make sure that UE is configured to automatically detect file changes, and reload a file when changed. Then, you can write an external compiled program that can be launched via user tool, that would search and replace the necessary colors in the UEW file. Focus will change to that tool, then, once focus returns to UE, it will detect the change to the UEW file that has been loaded. This will update the colors in question.

      This is not exactly an ideal solution, but is the only solution I can think of that will actually work the way you wish.

      If you don't have the UEW file you wish to change loaded, and if UE isn't set to detect and reload changed files, then it simply won't work.

      Of course, I have not tested this, but I have used an external program to make "live" changes to a UEW file and seen the changes take place on the file types controlled by that particular UEW file, so I am fairly sure the theory of doing it this way would work.

      20
      Basic UserBasic User
      20

        Jul 05, 2012#3

        I know nothing about UE scripts, but, could I (or someone else :)) write a script that would open some specific UEW file, do a search & replace (/Colors = ...), and then save and close the file?
        That should update the UE syntax engine, right?

        I did a quick glimpse at scripts - it seems that it can be done.

          Jul 05, 2012#4

          Hey, I did it :)

          UltraEdit.open("path and file");
          UltraEdit.activeDocument.top();
          UltraEdit.activeDocument.findReplace.replace("/Colors = blah, blah, blah,", "/Colors = blah2, blah2...,");
          UltraEdit.closeFile("path and file",1);

          6,686585
          Grand MasterGrand Master
          6,686585

            Jul 05, 2012#5

            It would be perhaps better to use for this task a macro stored in a macro file being automatically loaded on startup. Scripts usually destroy contents of active output window on execution which you perhaps don't want here. Running the same commands from within a macro would avoid a modification of contents of active output window.

            Another idea: Instead of modifying the used wordfile, you could use 2 wordfiles with identical contents, but slightly different language name and of course a different color setting for comments. The second wordfile which hides the comments has no File Extensions = at end of first line.

            Now you can switch for the active file via View - View as (Highlighting File Type) from wordfile displaying the comments to the wordfile hiding the comments and vice versa. For the first 20 languages in this list a hotkey or chord can be assigned in the key mapping configuration dialog to quickly switch by key the wordfile respectively view of the comments.

            If you are using smart language templates you have to duplicate also the language template file to have access to the smart templates independent of which wordfile is currently used for syntax highlighting.

            The advantage of using 2 wordfiles is that the wordfile must not be opened, modified, saved and closed and therefore the recent file list is not modified with the name of the wordfile.

            17
            Basic UserBasic User
            17

              Dec 11, 2012#6

              I'm also interested.

              1. Are the comments foldable? How?
              2. Is there a way to switch quickly between with and without comments or, in other words, hide and show comments?

              6,686585
              Grand MasterGrand Master
              6,686585

                Dec 11, 2012#7

                Block comments as defined in the syntax highlighting wordfile applied to active file can be folded. UltraEdit offers for all block comments spanning over at least 2 lines the symbol to fold it.

                This is not supported for multiple consecutive lines containing line comments. The reason is quite simple. Multiple consecutive lines with line comments could contain also parts not belonging to the line comments. So it would be necessary to evaluate if there is nothing else between beginning of a line and line comment starting string than spaces and tabs. It is possible with a macro or script to fold multiple consecutive lines containing only line comments.

                For example the following macro folds all blocks of multiple consecutive lines containing only line comments in C/C++/C#/Javascript files.

                InsertMode
                ColumnModeOff
                HexOff
                PerlReOn
                Top
                Loop 0
                Find MatchCase RegExp "^(?:[ \t]*//.*\r\n){2,}"
                IfFound
                HideShowSelection
                Key DOWN ARROW
                Else
                ExitLoop
                EndIf
                EndLoop
                Top

                It is also possible to use the advanced find option Hide Lines to hide all lines containing for example //. But this would hide also lines containing not only a line comment. Therefore it would be better to use Unix/Perl regular expression search string ^[ \t]*// or UltraEdit regexp search string %[ ^t]++// with Hide Lines to hide only lines containing only a line comment.

                aleksazr used a different method as he hides all comments by setting the color for the comments to the background color.

                17
                Basic UserBasic User
                17

                  Dec 12, 2012#8

                  Thanks Mofi very much for the macro.

                  It runs well as after I press the shortcut key the consecutive // comment lines now becomes
                  --- Lines Are Hidden ---

                  One other problem is when I press the shorcut again, the display does not expand to the original unfolded state.

                  6,686585
                  Grand MasterGrand Master
                  6,686585

                    Dec 12, 2012#9

                    Well, the macro is designed only for folding (collapsing) consecutive lines containing only line comments.

                    It is not possible with a macro or script to find out if a selection contains already folded lines. Therefore the same macro cannot be used to expand all collapsed blocks with consecutive line comments. It is necessary to use a second macro stored in same macro file with a different hotkey to expand all line comment blocks. This second macro is very similar to the first one for folding the comments.

                    InsertMode
                    ColumnModeOff
                    HexOff
                    PerlReOn
                    Top
                    Loop 0
                    Find MatchCase RegExp "^(?:[ \t]*//.*\r\n){2,}"
                    IfFound
                    HideShowExpandAll
                    Else
                    ExitLoop
                    EndIf
                    EndLoop
                    Top

                    If nothing other is folded than blocks of line comments it is also possible to use View - Hide/Show Lines - Expand All without having anything selected.

                    Please note that the behavior of find within a folded block is controlled with setting Automatically unfold hidden areas on Find and Goto at Advanced - Configuration - Editor Display - Code Folding.

                    17
                    Basic UserBasic User
                    17

                      Dec 13, 2012#10

                      Mofi wrote: <snip>
                      Please note that the behavior of find within a folded block is controlled with setting Automatically unfold hidden areas on Find and Goto at Advanced - Configuration - Editor Display - Code Folding.
                      Thanks Mofi.

                      I now have 2 further requirements:

                      1. I hope the position of caret before collapsing could be retained after the collapsing;
                      2. I hope the affected part, or-if that is not easy-all, of the collapsed lines expand automatically when edit takes place in the collapsed comment lines.

                      6,686585
                      Grand MasterGrand Master
                      6,686585

                        Dec 13, 2012#11

                        1. The macro environment does not support variables. To keep current caret position there are 3 possibilities:
                        1. The macro code is converted to script code as scripts support variables and therefore can remember current line and column position and set caret back after making the collapses. Scripts added to the script list can be also executed by hotkey or chord. The disadvantage in comparison to a macro is that a Cancel dialog is always displayed and usually the content of active output window is overwritten by script status information.
                        2. If you usually don't use bookmarks, the macro command ToggleBookmark can be inserted above first command Top to bookmark current line and column with configuration setting Bookmark column with line at Advanced - Configuration - Editor - Bookmarks checked. The second command Top at end of the macro must be replaced by the commands

                          GotoBookMark -1
                          ToggleBookmark


                          to move caret back to initial position on macro start.
                        3. If you often use bookmarks, it is possible to insert a special string to mark current position of the caret by inserting for example above first command Top the write command "CaReT". Below second command Top the commands

                          Find MatchCase "CaReT"
                          Replace ""


                          need to be appended to the macro to restore the caret position and remove the marker string. The disadvantage of this solution is a modification of the file with producing 2 undo steps.
                        Whichever solution is used, restoring the caret position after script/macro execution works only if the caret before execution is not on a line which is collapsed after script/macro execution.


                        2. I do not really understand your second requirement. If you want to edit something in the collapsed lines, you have to expand this part first. This can be done easily by clicking with mouse button on the [+] symbol left the collapsed lines or set caret on first line of collapsed block (with the [+] symbol left) and execute the command View - Hide/Show Lines - Hide/Show Selection. Do not select anything to expand a collapsed block. The hotkey for this command can be also configured at Advanced - Configuration - Key Mapping.

                        17
                        Basic UserBasic User
                        17

                          Dec 13, 2012#12

                          Thanks Mofi.

                          My 2nd requirement often related such scenario -

                          Suppose I'm deleting something after the collapsed lines with the Backspace. Sometimes I'd like the operation to goes on to the hidden lines. I hope the hidden lines could expand automatically.

                          I know this may not make much sense.