Launch external reformatter

Launch external reformatter

2
NewbieNewbie
2

    Nov 12, 2006#1

    Hello,

    I'd like to add reformatting capabilities to UE. I already have a tool that can reformat whole files, but I'd like to reformat just a selection, for example. I have a program that can take the code from the clipboard, reformats it and puts it back into the clipboard) and I'd like to use it.

    The UE macro should do this:

    - (optional) save the current clipboard content
    - save the current selected text to the clipboard (this is the text that needs to be reformatted)
    - launch an external application (something like reformat.exe -useClipboard)
    - replace the selected text with the one from the clipboard (reformat.exe has modified the text in the clipboard and now it's nice and formatted :D)
    - (optional) restore the previous clipboard content

    Is this be possible with macros?
    Thanks

    344
    MasterMaster
    344

      Nov 12, 2006#2

      Hi

      1st: What kind of "formatting" are you talking 'bout ?
      Pls give some examples...
      2nd: I don't THINK that a modified clipboard can be returned from another external process ... but a simple file based handshake should be easy...

      rds Bego
      Normally using all newest english version incl. each hotfix. Win 10 64 bit

      2
      NewbieNewbie
      2

        Nov 12, 2006#3

        Well it seems I haven't explained very well what I want:
        I need to format java code to look nicer. Something like putting the { on a separate line, removing extra blank lines, vertical-aligning if/else, etc. Also my java code includes many #define, #include and other preprocessor directives that I want to align nicely.
        The external program is made by me so I have full control of what it does. It takes the text from the clipboard, formats it and then puts it back into the clipboard.

        And now, my question :)
        I want to write a macro that takes the selected text, puts it into the clipboard, calls the external program, waits for it to finish and then replaces the selection with the text from the clipboard. Optionally it should keep the previous clipboard content. Unfortunately I don't have much experience in writing UE macros. So I need some hints, like: is there a limit to the length of text that can me put to/from clipboard? Or is it possible to wait for the external program to finish, or UE launches it and then continues without waiting?

        Thank you

        6,684586
        Grand MasterGrand Master
        6,684586

          Nov 12, 2006#4

          Your task should be no problem. You have to setup your tool as a user tool for UltraEdit - see Advanced - Tool Configuration.

          To run your tool with the current selection use following macro (with a hotkey).

          IfSel
          Clipboard 9
          Copy
          NewFile
          Clipboard 0
          Paste
          Clipboard 8
          SelectAll
          Cut
          Clipboard 9
          Paste
          Clipboard 0
          SelectAll
          Cut
          RunTool "Case sensitive name of user tool"
          NextWindow
          Paste
          PreviousWindow
          Clipboard 8
          Paste
          ClearClipboard
          Clipboard 9
          ClearClipboard
          Clipboard 0
          SelectAll
          Cut
          CloseFile NoSave
          EndIf

          Hope, this marco really works because not tested.

          Well, saving the content of the Windows clipboard with this method is only possible if the Windows clipboard contains text data and not a file or graphic data or something other binary.

          It would be much easier and better to save the selection to a file, run your tool with the file as input and write the output to a file or stdout. Stdout would have the advantage that UE could capture it and replace the existing selecting directly with the captured output from your tool. Problem with stdout is only the line length limit.
          Best regards from an UC/UE/UES for Windows user from Austria