The bottom line is, this isn't a situation the EU rules cover adequately, and it'll be a point of interesting discussion. But since we want to be in the EU, and the EU certainly wants us, it's kind of hard to imagine where the will to force us out will come from.
(the EU would certainly rather we don't leave the UK, of course, but that's another question entirely and one which colours matters now)
And for everyone pointing at articles and trying to work with the uncertainty therein- the articles aren't divine writ, if the EU wants us in (which by and large it will, I think we'll agree) then it is within their scope to create an article of secession or a treaty of accelerated entry to their satisfaction. Especially where the alternative would be to end up being forced in a direction nobody wants, by rules that were never meant to have that effect. That's the fun thing about being a lawmaking and rulemaking body.
Yes yes, Spain, but the obvious truth is that Scotland and Catalunya are not directly comparable, and the Spanish have taken (undemocratic and ethically dismal) steps to ensure that already, so they really gain very little in practical terms by seriously resisting Scotland's entry/retention in the EU.
Meanwhile, they would quite like to keep their fishing industry, which is largely dependent on the access to the north atlantic fisheries which they gain through our EU membership. It'd be a very brave Spanish politician who makes hundreds of thousands of people unemployed with a single vote.
The Spanish do have good reasons to not want us to be independent- as well as their own independence issues, they've benefited massively from the UK's willingness to barter away scottish fisheries. Oh hey, is this a good time to mention that Scotland weirdly has 87% of UK fisheries yet receives only 40% of the european fisheries funding? (distribution set by Westminster, dur)
So in short- we want in, the eu wants us in, and the eu makes the rules. And those who claim to oppose it have little reason to do so and great reason not to. So where really is the issue?