Programmatically editing a file from Emacs Lisp

Programmatically editing a file from Emacs Lisp

This is something I frequently want to do: open a named file, work on it programmatically using Lisp code, and save it back – all without user intervention. Like a lot of things in Emacs, it’s easy once you know how.

The trick is to create a new, named, buffer for the file to get its contents. This is done with find-file-noselect as opposed to the more usual find-file that’s usually bound to C-x C-f, and as its name suggests finds (opens) the file without bringing it to the user’s attention. For example,

    ;; open the file in its own buffer
    (with-current-buffer (find-file-noselect fn)

      ;; work on it as required, as the current buffer
      (goto-char (point-min))
      (search-forward "#+END_COMMENT" nil t)
      (beginning-of-line 2)
      (delete-region (point) (point-max))
      (newline 2)

      ;; save the results back
      (save-buffer))

(This example comes from my Emacs interface to the Nikola static site builder used to maintain this site.) The code fragment leaves the current buffer unchanged as far as the user (and the rest of the code) is concerned, and so doesn’t need to be protected by save-excursion or the like.

Estates: An Intimate History

Lynsey Hanley (2007)

A social history of segregated housing in Britain, how thw dream of a more equal approach died, and the consequences for those who lived through it.

Mass social (or council) housing was intended, in the immediate aftermath of the Second World War, to act as a social glue by mixing all sorts of people together so as to break down the walls of class that blighted British society. It failed: Aneurin Bevin’s vision was diluted, as were the building standards, resulting in housing that was both inferior to private stock and immediately identifiable as such, making it stigmatic to live there. The result has been to enhance the blight, erecting what Hanley refers to as “a wall in the head” of people whose self-image is poisoned by poor housing, poor neighbours, and poor (or indeed non-existent) services.

The wall in the head exists in many forms, and one doesn’t have to have grown up on a council estate to have one. But however tall it is, the wall is easy to build when young and hard to climb when older, and it’ll affect you all your life in some way or other. Housing and class have a lot to do with forming the wall.

It’s impossible to miss the connection with Between the World and Me, not least because of the catchy and often-repeated phrasing. Ta-Nehisi Coates was more concerned with physical violence rather than social class, but the parallels are there: different people from different circumstances have completely different perceptions of the country in which they live and what it’s supposed to do for them. I see this all the time with different student cohorts. It’s to some extent a matter of expectations of others, but also of the ability to see opportunities beyond the present. An inward-looking social environment absolutely stunts people’s vision of what’s possible for them.

The book ends on quite q positive note: the willingness of housing providers to renovate (rather than simply dispose of) social housing stock, and the availability of cash to do so. Whether this is sufficient is an open question, and certainly we still see developers skirting-round the requirement to provide “affordable” housing, in some cases literally walling-off the social from the private units, just as happened with the first estates built in the 1940s.

4/5. Finished Tuesday 19 December, 2023.

(Originally published on Goodreads.)

Technofeudalism: What Killed Capitalism

Yanis Varoufakis (2023)

A penetrating analysis of where we are and why.

Varoufakis has form with analysing current political affirs, of course: he wrote about his short time as Greek finance minister during the 2008 financial crisis in Adults in the Room: My Battle with Europe’s Deep Establishment. In this book he tackles a bigger subject: how has the economic system we are now experiencing diverged from the capitalism we’ve known for over a century? Varoufakis’ take is that the torrent of government money that followed the crisis, and increased during the pandemic, was used by the owners of internet-based cloud providers and major platforms – the “cloudalists” – to build-up their capital stock risk- and cost-free, and used this to grab (and then sell) the attention of everyone. Moreover it allowed them to charge rents to everyone else looking to sell on the internet, since network effects made their platforms unavoidable. This return to rentier economics is what Varoufakis terms technofeudalism, and claims this is a better term that the other terms such as late-stage capitalism or hypercapitalism that fail to capture the return to rents as the major source of corporate income – to the point that the cloudalists don’t need to be selling profitable commodities any more.

Varoufakis has a keen eye for anecdotes and corners of the economy in which to test his hypotheses, such as how General Motors turned into a hedge fund with a sideline in cars, or the irony of capitalism being defeated by … more efficient capitalism. But the major point is that technofeudalism isn’t capitalism, and emerged largely because of government largesse leading to unintended consequences followed by significant political capture to keep the new status quo in place and without meaningful regulation.

This is a book about economics, but there’s a computer science perspective that’s perhaps worth taking too. Cloud systems may be inefficient in economic terms, because they extract rents from all users and service providers. But technically they’re almost always more efficient than owning and running your own computers to provide services, as well as reducing costs and risks for start-ups and being a lot more flexible and (potentially) energy-efficient. That’s not to say that there’s no evidence of rentier behaviour: the cloud providers segment the market to charge premium rates for not-very-different services, which in turn changes technical decisions in ways that might not benefit service providers, and they’re notorious for making their charging structures as opaque as possible.

It’s the network effects in terms of access to users’ attention where the rents really become too significant to ignore and almost entirely negative in their effects. We’re also seeing the platforms seek regulation to stifle competition, notably in AI, which will re-inforce their ownership of the most important means of computation.

Another thing to consider is that the cloudalists’ rents make offerings progressively worsen. Cory Doctorow terms this process enshittification, where platform-based services inevitably try to suck-in all the surplus value and squeeze-out other stakeholders – turning them into what Varoufakis terms “cloud serfs” living on whatever pittance of value the platforms don’t deign to hoover-up.

So far so negative. But Varoufakis doesn’t content himself with merely describing the emergence of the current situation. As a former Communist his class-based analysis (which I have to say strikes a chord with me) leads him to try to define an alternative economy that recognises the realities of the techologies we live with. His prescription seems utopian and hard to realise, although not as hard (as he points out) as when trades unions were first formed, or when right-wing dictatorships were defeated – and he provides possible strategies and rallying cries for us to fight back against the return of feudalism in a more pernicious form than anyone ever expected.

5/5. Finished Saturday 9 December, 2023.

(Originally published on Goodreads.)

The Man Who Solved the Market: How Jim Simons Launched the Quant Revolution

Gregory Zuckerman (2019)

A history both of quantitative investing and of one of its most successful proponents.

Jim Simons comes across as a fascinating character, who transitioned across academic science and made some important contributions before deciding to tackle the practical aspects of investing. Driven by the same sort of mindset that he employed as a scientist, his new company developed some of the first methods for properly managing and diversifying risk.

But… to what extent was Simons responsible? To what extent did he “solve” the market, and to what extent did he provide a management structure within which others could? The story told here tends to the latter interpretation.

It’s also impossible to escape some of the darker aspects of the story. First of all, once the market has been “solved” (at least to the extent of extracting considerable and predictable profits) the company closes it to other investors, and it exists purely as a vehicle for its own staff. That seems like the epitome of pure financialisation. Worse, Simons and his partner Robert Mercer use their wealth and power to drive a political agenda that’s entirely focused on advancing this kind of financialism at the expense of … well, everything else. It’s not clear that they actually have a broader agenda, which in some ways is more shocking than if they had, but is in keeping with the authoritarian politicians they somewhat succeed in promoting.

4/5. Finished Sunday 3 December, 2023.

(Originally published on Goodreads.)

The Invisible Library (The Invisible Library, #1)

Genevieve Cogman (2014)

An enjoyable premise and good story: a Library outside time whose Librarians collect different variations of fiction from parallel worlds whose inhabitants live under different constellations of science, magic, chaotic faerie infestations, vampires, and the like. Clearly the start of a series, and while I don’t think I’m really in the target audience, it’s a book I thoroughly enjoyed.

3/5. Finished Wednesday 29 November, 2023.

(Originally published on Goodreads.)