Tapatalk

Indentation macro

Indentation macro

1
NewbieNewbie
1

    Feb 24, 2005#1

    Can anybody help me to write a macro to reeindent all the files in a directory with the current indentation settings? Thanks.

    261
    Basic UserBasic User
    261

      Feb 28, 2005#2

      That's an interesting question. My mind is going places like indenting code based If-Then-Else etc. Is this what you mean?

      If it's just putting one indent at the beginning of each line in all files, it should be easy with Replace in Files:

      Replace:
      ^(.)
      With:
      \t\1

      (Replace the first character on each line with tab followed by that character.)

      Make sure Unix RE are on.

      A word of caution: make sure this is what you want to do first, because it will change every line of every file you designate!

      Dave
      ASTTMan
      I'm not a Texan, I just live here.

      5
      NewbieNewbie
      5

        Mar 16, 2005#3

        I use the open source program 'Artistic Style' for indentation of C, C++ and Java files. It can be downloaded from SourceForge (https://sourceforge.net/projects/astyle/).

        I added a project tool entry with following data:

        Command Line: "C:\Programs\util_astyle\astyle.exe" --mode=c --style=ansi --indent=spaces=3 --indent-switches %F
        Working Directory: U:\dev\sw\source\app
        Menu Item Name: Indent Current File

        What I'm still looking for is a way to execute this command on file load or save. I tried to install a macro that executes the project tool, but it doesn't seem to work properly. Any ideas?

        261
        Basic UserBasic User
        261

          Mar 16, 2005#4

          I'll look into the 'Artistic Style'. I've read some other comments about it in the forum.  

          As for running the tool from a macro, I assume you tried the "RunTool" macro command.  If you can get it to run from a macro, you could, designate that macro to run on the Macro | Set Macro for File Load/Save menu.  I haven't tried this, but it seems like it should work.

          Good Luck!

          Dave
          ASTTMan
          I'm not a Texan, I just live here.

          5
          NewbieNewbie
          5

            Mar 16, 2005#5

            Yes, I used RunTool "Indent Current File" in the macro. However, it looks like UltraEdit loads the file and executes the macro. The changes to file are however not apparent unless I switch to a different application/desktop and then back to UltraEdit. UE tells me then that the file was modified by an other application.

            This makes sense because astyle creates a copy of the file. I guess I will attach the macro to the save command and not to the load command.

            Thanks for your help!

            261
            Basic UserBasic User
            261

              Mar 16, 2005#6

              Good! I'm glad it worked.

              Since you suggested the Project Tool configuration, I decided to give it a try, also. I am writing a Perl script, so I made a tool to run the script. The script creates an output file, which I edited.

              When I run the script a second time, I got the same behavior you described! I have to change applications, then go back to UltraEdit to see the changes. Like you say, this makes sense.

              Thanks for the ideas!

              Dave
              ASTTMan
              I'm not a Texan, I just live here.

              1
              NewbieNewbie
              1

                Oct 13, 2020#7

                For the record for anyone wondering, ASTTMan's Mar 16, 2005#4 Unix/Regular Expression response works as a regular find/replace in a macro as well. THANKS!!

                Replace:
                ^(.)
                With:
                \t\1