Anyone watching events in Catalonia right now will be experiencing a strong sense of constitutional déjà vu.

A coalition of independence supporters promising secession on an 18-month timescale, scaremongering about the EU and pensions, talk of federalism as a possible compromise; it’s tempting to say been there, done that.

By the time this column appears it ought to be clear whether a de facto referendum has been won and Catalans are on a doubtlessly rocky road to a unilateral declaration of independence from Spain.

Even if that carries majority Catalan support, of course, Madrid will say no. Constitutionally they’d be correct – the Constitución Española prohibits such plebiscites – but politically it will be massively counterproductive, as has been the whole approach of Spanish Unionists for several years now.

Tell a group of people they can’t have something, and it’s axiomatic that more of them will end up wanting it. Had Madrid been a little more flexible in the past – and of course the Spanish constitution could have been amended – then the current situation in Barcelona might have been very different.

But then of course it’s easy to be wise after the event. Nevertheless, events in Spain offer valuable lessons to British Unionists in terms of managing interminable speculation about the circumstances surrounding another independence referendum in Scotland.

The SNP has skillfully created a convenient narrative that allows for another ballot following vaguely defined “material change” in circumstances. And, given the precedent created by the first referendum, another majority Scottish Government would be in a strong position to demand another referendum from Westminster.

And if Westminster says no, in the manner of Spain, it doesn’t take Ipsos MORI to figure out what would happen next: support for independence would surge, creating unstoppable momentum. Importantly, the SNP has never conceded the point that it’s constitutionally incapable of holding a referendum without the UK’s permission, a la Catalonia almost exactly a year ago.

There are several ways of managing this situation, none of them ideal. Under a written constitution the UK Government could make unilateral secession illegal (as in the US and Spain), or it could compromise and concede that right but qualify it with certain conditions. As David Melding, the Welsh Conservative constitutional thinker, put it a few years ago: “A right of secession needs to be recognised but set at a high level for operation.”

This might take the form of what the Canadians called a “Clarity Act”, passed in the wake of the 1995 referendum in Quebec. This stipulated many things but ducked the issue of a threshold, thus becoming, in a gift to satirists, a rather unclear form of clarity. Nevertheless it at least reasserted the role of the federal government in the constitutional affairs of the Provinces.

Such a move would require a written constitution, which currently the UK (along with Israel and New Zealand) lacks. Recently, however, there have been interesting shifts in Unionist thinking. First, clauses added to the Scotland Bill in an imperfect attempt to make Holyrood “permanent” hint at a codified constitution, while two senior figures have explicitly backed a written constitution.

In a recent Nuffield College paper, “All aboard the Constitutional Express? Where is the Scotland Bill taking the UK?”, Professor Jim Gallagher – a key figure in most recent Unionist strategy – talks approvingly of the Smith process making Holyrood “more like a legislature in a federal system whose status is set out clearly in a written constitution”.

Similarly, speaking at a private dinner in Edinburgh last week the former UK Attorney General Dominic Grieve also voiced his support for a codified constitution, telling me later that it was necessary “if our new constitutional arrangements are to be accepted and durable”. Now this is far from a mainstream view, but not the sort of thing either would have said a few years ago.

According to recent reports, meanwhile, the Corbyn-led Labour Party is finally preparing to embrace the no-brainer that would be a federal UK. Echoing his PSC counterparts in Spain, MP Jon Trickett told The Times he believed something “near to a federal arrangement” was the logical destination for a settled British constitution. And a federal UK would naturally require a codified constitution.

I would, however, go further. A written constitution shouldn’t just codify the status quo (and Mr Grieve agreed on this point) but actively move things on. A Cabinet Office initiative is already attempting to co-ordinate more closely developments in Scotland and Wales, although the peculiar dynamic in Northern Ireland and uneven process in England means this is by its nature messy.

A written constitution doesn’t have to be tidy – indeed messiness is arguably an intrinsic part of the British constitutional tradition. But at the same time it should also be viewed as an opportunity not just to explain but innovate. Indeed an explicit recognition of the right to secede would not only be pretty radical, but merely formalising something implicitly acknowledged by the Northern Irish “border poll” of 1973 and last year’s referendum in Scotland.

What of the caveats? This part would require careful handling. Given the baggage of the 1979 devolution referendum and the precedent set last year anything other than a 50 per cent + 1 threshold is a non-starter, but lots of other conditions could pass the credibility test: “once in a generation”, for example, could be set at, say, 15 years (a la Quebec), while the need for a clear mandate at Holyrood speaks for itself.

Defining a “material change” is necessarily subjective, but the point is that it would concede – from a Unionist perspective – the possibility of another referendum without accepting that it might happen entirely at the whim of the SNP (sorry, I meant to say the “Scottish people”). Watching the First Minister speak at a Scottish Parliamentary Journalists Association lunch last week I was struck that she seemed to equate “democracy” with a referendum vote.

But it is much more than that, comprising institutions, people and politics, all of which are fluid rather than fixed. More to the point, we’re now into “neverendum” territory in terms of speculation if not practice. How can a state adequately function when secession is a moment-to-moment prospect? How can it plan or invest? I wouldn’t go so far as calling it, as historian Neil Oliver has, a “cancerous presence”, but I know what he’s getting at.

At the same lunch Nicola Sturgeon also said she believed the power to hold a second independence referendum ought to be devolved (which contradicts her government’s insistence that it already has it), something Westminster will obviously resist. Moves towards a written constitution, though clearly not straightforward, would make this easier to counter.

Power – or “sovereignty” – no longer solely resides at Westminster; that constitutional ship sailed decades ago, but it’s time for theory to catch up with practice. In the Iberian Peninsula there’s much talk of Spain as “a nation of nations”, and Unionists shouldn’t fear looking at the United Kingdom in the same way.