new_window: only set $window and pass `-n` if a name is provided

Otherwise `new_window` after `new_window foo` would re-use the same
name, resulting in an error.
Add __get_current_window_index internal helper function
Set $window var based on currently active window

Previously $window was only set by the new_window() helper when it was
passed a name argument. This caused weird behavior cause if it was
called without a name it would simply attempt to recreate the same
window and fail. That was until @blueyed's fix in 2249cf8.

However, the $window var still wasn't being set correctly, leaving
split_v(), split_h() and other helpers to operate on the wrong
window. This is no longer an issue as $window is always set to the index
of the currently active window at the end of new_window() and
select_window().
Attempt to avoid timing issue which sometimes causes test to fail
Merge pull request #50 from jimeh/fix-new_window-active-window-tracking

Fix new window active window tracking