/> Calling PerlTidy from SubEthaEdit - christian renz // bassist - Stuttgart

05/05

2005

Calling PerlTidy from SubEthaEdit

SubEthaEdit is a wonderful editor with many features, but it lacks one thing for me: A comfortable way to call external utilities. In the last few weeks, I became a PerlTidy aficionado. Using the following AppleScript, you can call PerlTidy from the script menu. It replaces the text of the active document. If something goes wrong, ⌘Z reverts the changes.

tell application "SubEthaEdit"
	set pt to "-ce -bar -vtc=2 -pt=2 -sbt=2 -bt=2 -wba=\"? : .\""
	if the number of documents > 0 then
		set doc_text to the text of document 1 as string
		
		set f_perltidy_in to "/tmp/perltidy.in"
		
		try
			do shell script "rm " & f_perltidy_in & " "
		end try
		
		set f_in to open for access (f_perltidy_in as POSIX file) ¬
			with write permission
		try
			write doc_text to f_in
			close access f_in
		on error
			close access f_in
			return
		end try
		
		set cmd to "perltidy " & pt & " < " & f_perltidy_in
		set output to do shell script cmd
		set the text of document 1 to output
	end if
end tell

Keine TrackBacks

TrackBack-URL: http://www.renzwertig.com/mt/mt-tb.cgi/53