[TxMt] Re: how does the html bundle preview a document with unsaved changes?

Stephen Bannasch stephen.bannasch at deanbrook.org
Tue Sep 10 23:13:34 UTC 2013


At 12:05 PM +0200 9/9/13, Allan Odgaard wrote:
>On 8 Sep 2013, at 1:13, Stephen Bannasch wrote:
>
>>  > [Š]
>>I solved this by specifying input from document and and inputFormat 
>>as text in the "Hint (without save)" command and then using this in 
>>the nodejs code to read the currentDocument: [Š]
>
>I had a longer response partially written, as there's a lot of 
>options related to the overall goal here, but I'll put that in the 
>manual instead and drop a link here (when finished).

I look forward to it.

I ended up making a number of other changes to jshint.tmbundle ... 
then Felix Gnass made me a repo collaborator so they are all in the 
master branch now.

I'm sure there are some things I could do better but it seems to work 
reasonably well now.

Regarding integration with TextMate -- the bundle code written in 
JavaScript and running on nodejs is sending html output to the 
console log and running process.exit(205).

https://github.com/fgnass/jshint.tmbundle/blob/3f709/Support/jshint-tm.js#L183-L192

One of the features I added was to have the JSHint window with errors 
close if you fix all the errors.

Along with the ability to use ctrl-shift-L  to check the current 
document (instead of just the saved file done with command-S) I use 
this iteratively until the JSHint error window goes away and then 
save.

There might be a better way ... but this is what I did to close the window.

When JSHint is invoked and there are errors it creates a window with 
the title "JSHint: <name of file>".

When it is invoked and there are no errors it executes this in nodejs:

https://github.com/fgnass/jshint.tmbundle/blob/3f7091/Support/jshint-tm.js#L183-L192

   function closeWindowWithTitle(title) {
     spawn('osascript',  ['close-window.applescript', title], { cwd: 
__dirname });
   }

Which runs this very simple applescript:

https://github.com/fgnass/jshint.tmbundle/blob/3f7091b8c1311154af3d1575ca19f39e3c598989/Support/close-window.applescript

   on run argv
     set window_name to item 1 of argv
     try
       tell application "TextMate" to close window named window_name
     on error number -1728
     end try
   end run

This is of course not perfect ... but it seems to be good enough.



More information about the textmate mailing list