[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] BBEdit MacPerl Window?



I've just been catching up on the mailing list, and have been very
interested in people's recent comments on Alpha, BBEdit and MacPerl. I
would like to say that while I switched from Alpha to BBEdit because I
just plain like it better, Alpha has some really nice links to MacPerl
that I sorely miss.

I have written some AppleScripts to fill some of the gaps between
BBEdit and MacPerl, and use the MacPerl BBEdit extensions all the
time.  But using untitled windows for STDOUT, etc., gets old after a
while, because you're constantly having to close them, hit Command-D,
etc.

In MacPerl, there's one output window. If you close it, it closes, if
you leave it open, it accumulates output.

I thought it would be nice if people who write BBEdit extensions and
scripts could agree on a way to emulate the MacPerl windowin BBEdit,
so there would always only be one, and if you wanted to clear it, you
could close it, just like in MacPerl -- but if you kept it open it
would accumulate your output ad infinitum. 

The AppleScript at the end of this post is an attempt at demonstrating
this kind of technique (although in this case, the MacPerl window is
cleared of its contents and repositioned each time the script runs),
which involves creating a folder inside the BBEdit folder called
"MacPerl Message Window Ä:" (the last character in the name here is
the Option-F character).

A file called "MacPerl" is placed inside this folder, and saved after
it has been filled, which means the user can simply close the window
at any time.

Does this seem like something other people would like to use?


Richard

__________________________
Richard Pfeiffer <pfeiffer@well.com>
Publishing Automation/Database Consulting/Book Production
BMUG Scripting SIG -- Next Meeting: FileMaker Pro
Monday 3/17/97, BMUG offices @ 6:00 p.m.


---------------------------------------------
(*
Runs a MacPerl syntax check on the Perl program being edited in the
frontmost BBEdit window.

If the syntax check fails, we dump the error messages into a new
BBEdit 
window, while displaying and highlighting the line in the Perl program

that contains the first error.
 
Otherwise, we just beep twice.
*)

property MakeNewPerlFile : false

-- Create the containing folder and file path for the MacPerl messages
window,
-- which will live in a special folder inside the BBEdit folder.
tell application "Finder"
	set BBEditFile to (file of every process whose frontmost is true) as
alias
	set BBEditFolder to container of BBEditFile as text
	set MacPerlMessageFolder to BBEditFolder & "MacPerl Message Window
Ä:"
	if not (folder MacPerlMessageFolder exists) then
		make new folder at folder BBEditFolder with properties
{name:"MacPerl Message Window Ä"}
	end if
	set MacPerlMessages to MacPerlMessageFolder & "MacPerl"
	if not (exists file MacPerlMessages) then set MakeNewPerlFile to true
end tell

--Copy the Perl program we're working on
tell application "BBEdit 4.0" to set thePerlProgram to contents of
window 1

tell application "MacPerl"
	
	-- Make sure we have a fresh MacPerl window, so that our error
messages aren't
	-- mixed in with previous messages
	if Window "MacPerl" exists then Close Window "MacPerl"
	
	-- Check the syntax of the Perl program
	try
		Do Script thePerlProgram with Çclass CHCKÈ
		
	on error
		-- If the Perl program failed the syntax check, copy the error
messages from the
		-- MacPerl window, close it, and then set things up to look at the
error messages in BBEdit
		set errorLog to contents of document 1
		Close document 1
		
		tell Application "BBEdit 4.0"
			
			-- Set the bounds of the new error log window
			-- If this is a 13" monitor, put the window close to the left edge
of the screen
			tell application "Finder" to set {a, b, c, d} to bounds of window
of desktop
			if c is less than 700 then
				set NewLeft to 15
			else
				-- Otherwise put the new window a little further out
				set NewLeft to 150
			end if
			set NewTop to 244
			set NewRight to NewLeft + 600
			set NewBottom to NewTop + 120
			
			-- Create a new MacPerl window, if necessary, then position it,
etc.
			if not (exists window "MacPerl") then
				if MakeNewPerlFile then
					make new window at end with properties {index:-1,
bounds:{NewLeft, NewTop, NewRight, NewBottom}, status bar:false, line
numbers:false, cursor position:false}
					save window -1 to MacPerlMessages
				else
					open MacPerlMessages
				end if
			end if
			
			if not MakeNewPerlFile then
				set index of window "MacPerl" to -1
				set bounds of window -1 to {NewLeft, NewTop, NewRight, NewBottom}
				set status bar of window -1 to false
				set line numbers of window -1 to false
				set cursor position of window -1 to false
			end if
			
			set contents of window -1 to errorLog
			set first visible line of window -1 to 1
			
			-- Select the line with the first syntax error
			if word -2 of line 2 of window -1 is "Line" then
				set lineNum to word -1 of line 2 of window -1
				
				save window -1 to MacPerlMessages -- so the user isn't prompted on
closing it
				
				try
					set lineNum to lineNum as integer
				on error
					-- Display the error log window	
					set index of window -1 to 1
					return
				end try
				
				select line lineNum of window 1
				
				if lineNum is greater than 9 then
					set first visible line of window 1 to (lineNum - 9)
				end if
				
				-- Display the error log window	
				set index of window -1 to 1
				
			end if
		end tell
		beep
		return
	end try
	
	-- If the Perl program passed the syntax check, close the MacPerl
window
	Close document 1
	
end tell

beep 2
---------------------------------------------