I’ve recently “discovered” using a two-column layout when doing TDD: I put the tests in one group and the associated files in the other. This lets me see both my tests and the code under test at the same time. I like it a lot. So, being the tinkerer that I am, I thought it would be nice to write a little plugin that activated the associated file in the other group when I switched to its counterpart. I’ve been working with CoffeeScript lately, so if I switch to my_model.js.coffee in group 0, i’d like my_model_test.js.coffee to be activated in group 1. [Over simplifying here … obviously have the issue of looking to see if the file exists and all that jazz] So to just get my bearings on moving views around group to group, I hard coded some file names and started tinkering.
Given a path to an existing file, if I did window.open_file(path) in the on_activated event, ST2 would crash. Every time. If I open the console and enter the same command, the file would open just fine. Then I tried to move an already open file to a different group using window.set_view_index, which also resulted in a crash. I used a method something like:
for v in window.views():
if v.file_name() == <hard coded name of file>:
the_view = v
break
window.set_view_index(the_view, 1, 0)
Should these sorts of operations be possible in on_activated? If not, how would one go about making sure an associated file is open in another group when a particular file is activated? If possible, I’d like it to happen automatically and not depend on a key combination. I can bind it to a key combination if necessary, I’d just like to not have to think about it.