Launch external reformatter

Help with writing and playing macros

Launch external reformatter

Postby fili » Sat Nov 11, 2006 8:34 pm

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
User avatar
fili
Newbie
 
Posts: 2
Joined: Sat Nov 11, 2006 12:00 am

Re: Launch external reformatter

Postby Bego » Sat Nov 11, 2006 9:33 pm

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
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: Launch external reformatter

Postby fili » Sun Nov 12, 2006 8:49 am

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
User avatar
fili
Newbie
 
Posts: 2
Joined: Sat Nov 11, 2006 12:00 am

Re: Launch external reformatter

Postby Mofi » Sun Nov 12, 2006 1:21 pm

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4042
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros