All is far from lost, both for party's hopes of remaining in power in Scotland and for cause of independence, says former adviser to Nicola Sturgeon and Alex Salmond.