avoid that the main context can be #poped
Summary:
avoids that the main context can be #poped
+ ensure we abort the switching loop if we arrive at it
Test Plan: make && make test
Reviewers: dhaumann, vkrause, nibags
Reviewed By: vkrause
Subscribers: kwrite-devel, kde-frameworks-devel
Tags: Kate, Frameworks
Differential Revision: https://phabricator.kde.org/D15835