Detecting editor exit events in Sublime - sublimetext2

Is there a way to detect editor exit event in Sublime 2?
It is not listed in the API reference and I've tried using EventListener.on_close, but that works only for detecting view closing, which is not what I need.
I just want to execute something before the editor exits, is that possible?

There is no way to do this in ST2. In ST3, you could try to capture the exit command by using sublime_plugin.EventListener.on_window_command(), or possibly on_text_command() (not sure what kind of command exit is, probably do both for safety), but I've never tried it myself.

Related

Shorcut for `Run Line(s)` in Octave / Matlab

In RStudio it is Ctrl+Enter, while in PyCharm it is Ctrl+backslash, but I can't find a similar shortcut for Octave (not so interested in Matlab). There has to be a way to run a single line of code on the editor without running the entire document. I know there is a method to run chunks of code, but this doesn't seem practical, either.
You need to select the code that you want to run first. The actual shortcut to then execute the selection is configurable (Edit > Preferences...) but defaults to F9.
Or you can right click on the editor which shows you the options and shortcut:

VB Editor pops up for no reason

I have an MS Access form, and on a button click it runs VBA code to run the Shell Command.
private sub cmdOpen_click()
dim vValue as String
vValue = Listbox.column(1) 'Retrieving a path name from a list
shell "C:\Adobe's Path\Arco.exe " & vValue
end sub
When I first run this script the first time I open this database, it stops running, opens the script editor, and highlights the shell line. There is no error code, in fact if I just hit the Run button it finishes just fine. If run it a second time there is no issue. Only when I close it down and reopen it.
No there is no Breakpoints/stops in the code. Would anyone have any idea why this is happening? I can't seem to fine anyone else with a similar issue.
I have had issues with this in Access 2010. I found that there was a breakpoint on that line, and for some reason Access seemed to remember it even after closing the application. For me, it usually happened when I fixed code and someone else ran it.
The only thing I found that seemed to fix it was to set a breakpoint on that line, save the project, then clear it and save it again. Sometimes I had to open and close the project once or twice to get it to completely forget the breakpoint was there.
It seems to me that it's a random, esoteric bug in the Access IDE. It would be fantastic if they would actually make this a feature, but it's not even a bug that can be relied on.
I've had similar experiences with Access and what always helped for me is to copy the text into a Notepad .txt file (or other basic text processing program). Then select it all in the .txt and copy it back.
Decompiling the Access application will solve this too.
Previous SO question: How does one decompile and recompile a database application?

Tk's clipboard command sometimes not setting system clipboard

I've noticed that Tk's clipboard command sometimes does not really append to the system clipboard. I've noticed this in other programs previously (tkcon for example) where if I copy some text and try to paste it into another program (notepad for example) I get nothing. Sometimes I need to do the copy again in order to get the text into the clipboard.
I'm currently developing my own text editor (see pure console text editor 2 on the tcler's wiki or on github) and I can't get the clipboard to work accross applications.
The implementation looks simple enough:
clipboard clear
clipboard append -- [join $copy_lines \n]
but it doesn't work. By doesn't work I mean it works within the running application but if I have two applications open and try to copy from the first and paste into the second then it doesn't work.
Not sure what else I need to do. From the documentation it looks like it should work.
Found the problem (at least for my program). My program runs in plain old tclsh, not wish and waits for inputs in a busy loop (peppered with after commands so as to reduce CPU usage). As such, it never enters the event loop. Turns out Tk updates the clipboard in the event loop (presumably on idle) so the system clipboard never gets updated (though the internal data structures stores the copied text just fine).
The solution is to enter the event loop. Ideally I'd refactor my code to use fileevents instead of a while loop. For a quick fix I'm just calling update whenever I process user inputs.
As for Tk in general, it appears that copied text dies with the application. So the copied text is available while the program is running but disappears when the program quits. It doesn't seem to happen on my Ubuntu machine. I guess I've got a daemon running that maintains the clipboard. That's OK. I can live with it for now.

How can I get Hudson to continue a build after a windows command fails?

I've got a build script from a 3rd party tool. It does it's job properly, but throws a useless exception at the end which I need to ignore.
But Hudson doesn't ignore it. It stops my build when this script exits with an error code != 0. Which it does, even when the last line is 'exit 0'.
There is no option in the Hudson build configuration to specify how to treat failure of a particular build step.
Is there a hidden option to tell Hudson to soldier on? Where is the general reference for Hudson's config.xml?
On Unix systems, one way around the problem is to run it in a sub shell of bash, with an "exit 0" as the final command. For example:
bash -c "false; exit 0"
This will run "false" but will have a return value of 0.
This is a little hacky but does work. I do not know if a similar solution exists for windows.
One of Hudson's key properties is that everything can be configured via the web interface. So looking at the config.xml is not the right approach.
In Hudson, your windows command can be launched via a batch file. I suggest looking into making that batch file return a zero error code, regardless of what your third party tool does. The first line would invoke your tool, and the second line would be 'exit 0'
Seems that one has to wrap the offending script in it's own bat:
copy con wrapper.bat
>myErrorMakingScript.bat
>exit /b 0
and then fire wrapper.bat from Hudson.
Use the Join trigger Plugin
work great for me.
check the "Trigger even if some downstream projects are unstable" option

Modifying a program to fake a button press

I have an MFC application that I was given (without source code) which opens a window with an 'Update' button, which then performs a very long update after being clicked.
I'd like to modify the program so that when the window is created (or somewhere else such as DoModal), a message is sent to the program to make it think that the button was pressed.
I've been toying around with this for a while in Ida Pro and OllyDbg to no avail. I looked at possibly using PumpMessage, but this did not bring any success.
Any advice?
If you don't like the idea of using a secondary "macro" program, you could patch the original program's binary to call the button's BM_CLICK handler. If you can find some space for the call (minimum 5 bytes without arguments), you can do this with OllyDbg alone (after editing the code, select it, and select "Copy to executable" -> "Selection" from the right-click menu). Otherwise, you'll need to create a new code section with a PE editor (e.g. LordPE or PE Tools) and add your code there (typically you'll want to change a call in the program to a jump to your section, where you perform the original call plus the call to the button's click handler, then jump back to the old position after your patched jump).
There are a few ways to do it using test automation techniques, but the simplest is to simply get the window handle for the button you want and send it a BM_CLICK message. This assumes that you have a working knowledge of C/C++ on Windows. If not, there are other means using .NET or other technologies. I'm not familiar with ida-pro or ollydbg.
See this perl module win32::guitest it could help you to do this.you can write with it a perl script and embed it in your program. or you can use the win32 api that wrap your required needs and use it.
Just create a 2nd program that will lunch it and will send a mouse click using SendInput(...)