In a private viewing cinema in Soho last week I caught myself letting fly with a four-letter expletive at Bill Keller, the former executive editor of the New York Times. It was a confusing moment. The man who was pretending to be me – thanking Keller for "not giving a shit" – used to be Malcolm Tucker, a foul-mouthed Scottish spin doctor who will soon be a 1,000-year-old time lord. And Keller will correct me, but I don't remember ever swearing at him. I do remember saying something to the effect of "we have the thumb drive, you have the first amendment".

The fictional moment occurs at the beginning of the DreamWorks film about WikiLeaks, The Fifth Estate, due for release next month. Peter Capaldi is, I can report, a very plausible Guardian editor.

This real-life exchange with Keller happened just after we took possession of the first tranche of WikiLeaks documents in 2010. I strongly suspected that our ability to research and publish anything to do with this trove of secret material would be severely constrained in the UK. America, for all its own problems with media laws and whistleblowers, at least has press freedom enshrined in a written constitution. It is also, I hope, unthinkable that any US government would attempt prior restraint against a news organisation planning to publish material that informed an important public debate, however troublesome or embarrassing.

On Sunday morning David Miranda, the partner of Guardian columnist Glenn Greenwald, was detained as he was passing through Heathrow airport on his way back to Rio de Janeiro, where the couple live. Greenwald is the reporter who has broken most of the stories about state surveillance based on the leaks from the former NSA contractor Edward Snowden. Greenwald's work has undoubtedly been troublesome and embarrassing for western governments. But, as the debate in America and Europe has shown, there is considerable public interest in what his stories have revealed about the right balance between security, civil liberties, freedom of speech and privacy. He has raised acutely disturbing questions about the oversight of intelligence; about the use of closed courts; about the cosy and secret relationship between government and vast corporations; and about the extent to which millions of citizens now routinely have their communications intercepted, collected, analysed and stored.

In this work he is regularly helped by David Miranda. Miranda is not a journalist, but he still plays a valuable role in helping his partner do his journalistic work. Greenwald has his plate full reading and analysing the Snowden material, writing, and handling media and social media requests from around the world. He can certainly use this back-up. That work is immensely complicated by the certainty that it would be highly unadvisable for Greenwald (or any other journalist) to regard any electronic means of communication as safe. The Guardian's work on the Snowden story has involved many individuals taking a huge number of flights in order to have face-to-face meetings. Not good for the environment, but increasingly the only way to operate. Soon we will be back to pen and paper.

Miranda was held for nine hours under schedule 7 of the UK's terror laws, which give enormous discretion to stop, search and question people who have no connection with "terror", as ordinarily understood. Suspects have no right to legal representation and may have their property confiscated for up to seven days. Under this measure – uniquely crafted for ports and airport transit areas – there are none of the checks and balances that apply once someone is in Britain proper. There is no need to arrest or charge anyone and there is no protection for journalists or their material. A transit lounge in Heathrow is a dangerous place to be.

Miranda's professional status – much hand-wringing about whether or not he's a proper "journalist" – is largely irrelevant in these circumstances. Increasingly, the question about who deserves protection should be less "is this a journalist?" than "is the publication of this material in the public interest?"

The detention of Miranda has rightly caused international dismay because it feeds into a perception that the US and UK governments – while claiming to welcome the debate around state surveillance started by Snowden – are also intent on stemming the tide of leaks and on pursuing the whistleblower with a vengeance. That perception is right. Here follows a little background on the considerable obstacles being placed in the way of informing the public about what the intelligence agencies, governments and corporations are up to.

A little over two months ago I was contacted by a very senior government official claiming to represent the views of the prime minister. There followed two meetings in which he demanded the return or destruction of all the material we were working on. The tone was steely, if cordial, but there was an implicit threat that others within government and Whitehall favoured a far more draconian approach.

The mood toughened just over a month ago, when I received a phone call from the centre of government telling me: "You've had your fun. Now we want the stuff back." There followed further meetings with shadowy Whitehall figures. The demand was the same: hand the Snowden material back or destroy it. I explained that we could not research and report on this subject if we complied with this request. The man from Whitehall looked mystified. "You've had your debate. There's no need to write any more."

During one of these meetings I asked directly whether the government would move to close down the Guardian's reporting through a legal route – by going to court to force the surrender of the material on which we were working. The official confirmed that, in the absence of handover or destruction, this was indeed the government's intention. Prior restraint, near impossible in the US, was now explicitly and imminently on the table in the UK. But my experience over WikiLeaks – the thumb drive and the first amendment – had already prepared me for this moment. I explained to the man from Whitehall about the nature of international collaborations and the way in which, these days, media organisations could take advantage of the most permissive legal environments. Bluntly, we did not have to do our reporting from London. Already most of the NSA stories were being reported and edited out of New York. And had it occurred to him that Greenwald lived in Brazil?

The man was unmoved. And so one of the more bizarre moments in the Guardian's long history occurred – with two GCHQ security experts overseeing the destruction of hard drives in the Guardian's basement just to make sure there was nothing in the mangled bits of metal which could possibly be of any interest to passing Chinese agents. "We can call off the black helicopters," joked one as we swept up the remains of a MacBook Pro.

Whitehall was satisfied, but it felt like a peculiarly pointless piece of symbolism that understood nothing about the digital age. We will continue to do patient, painstaking reporting on the Snowden documents, we just won't do it in London. The seizure of Miranda's laptop, phones, hard drives and camera will similarly have no effect on Greenwald's work.

The state that is building such a formidable apparatus of surveillance will do its best to prevent journalists from reporting on it. Most journalists can see that. But I wonder how many have truly understood the absolute threat to journalism implicit in the idea of total surveillance, when or if it comes – and, increasingly, it looks like "when".

We are not there yet, but it may not be long before it will be impossible for journalists to have confidential sources. Most reporting – indeed, most human life in 2013 – leaves too much of a digital fingerprint. Those colleagues who denigrate Snowden or say reporters should trust the state to know best (many of them in the UK, oddly, on the right) may one day have a cruel awakening. One day it will be their reporting, their cause, under attack. But at least reporters now know to stay away from Heathrow transit lounges.

• Alan Rusbridger has replied to several comments in the thread below. Here are a selection of his answers:

Lionel said:

I frankly am not clear on the extent to which suspects come into this matter. It has been indicated several times that police at Heathrow can operate without being suspicious. When exactly are they expected to operate?

Alan Rusbridger replied:

You're right. In fact, the point of Schedule 7 is that they are supposedly not "suspects". Because then the authorities would have to arrest them and they would have many rights they don't have as, er, non-suspects.

StopGMO said:

Free speech must be maintained for ALL of us, not just 'reporters', so while we care about this abuse, make sure you are not just supporting 'reporters' rights, but speak up for your OWN. Do not let the greasy UN get it's hands on the internet, and speak up for your rights, and the rights of reporters to furnish the truth. All two of the reporters who still bother to do that.

Alan Rusbridger replied:

You're right of course: it's not just about reporters. But it would be a good start if more journalists saw what was potentially at risk here...

AlanC said:

If you meekly give into their demands without insisting that they take you to court then you've as good as admitted that they can do whatever they like as far as the UK press is concerned. Now if you had made that story a front page feature the day after it happened then you might have a point but, as far as I can remember, there was nary a cheep.

Alan Rusbridger replied:

Play out the scenario for me in which fighting this case in court would have enabled us to do a better job of reporting the Snowden documents. I'm not sure I quite see it...

Crowfoot said:

Ok Alan, There's a tide of us ordinary folks out here, shocked witless, cross, affronted by the degree to which basic democratic rights have been usurped, and fully support The Guardian's David stance against Goliath.

But what does one proactively do with one's anger? How can we help? How to galvanise the public's response?

Alan Rusbridger replied:

Keeping reading the Guardian... and I suppose you could support Snowden's defence fund.

Iskra1903 said:

Is it possible, Mr Rusbridger, for you to acknowledge that the people who held Mr Miranda may have done so with the aim of preventing their efforts to prevent a terrorist attack being compromised? They may well have transgressed their legal powers, and their actions (and the governance over those actions) does indeed need to be scrutinised. But your article only permits the conclusion that these people are acting in bad faith, and abusing their powers in an Orwellian fashion.

Alan Rusbridger replied:

As the article says, there's a balancing act to be done between security, freedom of speech, privacy etc. But it's impossible to have that debate without informed knowledge. For another point of view - in the Guardian - try this.

Gman79 said:

It's called a D Notice. And even if the Guardian had been issued with one, they wouldn't be able to tell us.

Alan Rusbridger replied:

That's not quite how DA Notices operate. They are actually standing notices, available here.

They did (ill-advisedly imho) circulate a reminder of them when the Snowden allegations broke. But there was no "ban" and it didn't stop us from reporting the NSA or GCHQ stories.

dperth said:

Why the basement and who chose to go there? It adds a nice element of the macabre to the story - or is that how spooks always work. (Interestingly, I have just finished reading Le Carre's "A Town in Germany" and that has scenes of unauthorised secretive work being carried out in a British Embassy basement).

Alan Rusbridger replied:

Really smashing up computers turns out to be quite messy work...