Babel and Python

This is a sort of Public Service Announcement. One of the great things about Org mode is the code block where you can run code in an Org buffer and have the results inserted into the Org document. I use this all the time. It’s a particularly elegant way of practicing literate programming and writing “live” documents that automatically rewrite themselves when the data the changes.

It’s usually a seamless process but there are gotchas for some languages. Sadly, Python, a widely used language, is one of those where you have to be careful. If you don’t follow the rules correctly, you can end up with erroneous results.

Recently, on the Org Mode mailing list there was a nice discussion of the problems that Python can present. As of right now, there are only three posts in the thread so you should read them all to get a full idea of what’s going on. The TL;DR is that you (usually) have to provide an explicit return in your Python code to get the correct results into your Org buffer.

Python is the only language that I use—even occasionally—that has these problems: usually things just work. It is, therefore, worth spending a few minutes familiarizing yourself with the problems that Python and a few other languages have in the Babel environment.

Posted in General | Tagged , | Leave a comment

Using .authinfo With Org Code Blocks

As most of you know, I’m a big fan of using literate programming techniques in the context of what might be described as “devops”. The technique boils down to writing an Org file with code blocks that document how you are solving a particular problem. The key is that the code blocks are executable and are what you actually use to solve the problem. Howard Abrams has a really good introduction to the idea in a post and subsequent video.

Magnus Therning has a nice nice post that expands on the same theme. His wrinkle is that the applications he’s interacting with require login credentials. For a long time, he simply kept those credentials as plain text in his Org file but, of course, he realized that was a bad thing.

He solved the problem by putting his credentials in his .authinfo file and accessing them with the auth-source library. He wrote a couple of functions that used the auth-source library to retrieve the necessary credentials. He populated these in a properties block. This is perfect because the source code doesn’t show any secrets but those secrets are made available to the executing code.

I do something similar to retrieve secrets that I don’t want exposed in plain text. The .authinfo file and associated library is a really useful set of tools to enable access to secure applications without exposing the required credentials. Take a look at his post to see how easy it is.

Posted in General | Tagged , | Leave a comment

Converting Between Miles and Kilometers

Peteris Krumins has a nice post on using Fibonacci numbers to covert between miles and kilometers. The TL;DR is that if you take any two consecutive Fibonacci numbers, X and Y, there will be approximately Y kilometers in X miles (and vice versa, of course). The approximations are amazingly precise.

There’s more. The above works only if the number you want to convert is a Fibonacci number but you can express the number you do want to convert as a sum of Fibonacci numbers and sum up the corresponding pair numbers to get the conversion. Take a look at Krumins’ post for an example.

It’s not an accident that it works, of course. The secret is the ratio of consecutive Fibonacci numbers, \(F_{n+1} / F_{n}\) converges to the Golden Ratio, \(\frac {1+\sqrt{5}} {2} \approx 1.618034\). The key is that there are 1.609344 kilometers per mile, which is very close to the Golden ratio.

Serendipitously, John Cook, a Mathematician, has a recent post on the same subject. He makes an interesting observation. The higher the value of n the closer \(F_{n+1} / F_{n}\) gets to the Golden Ratio so, naively, one expects the kilometer-mile approximation to get better too. That works for a while, but for larger n, the \(F_{n+1} / F_{n}\) ratio gets closer to the Golden Ratio than the number of kilometers per mile. Cook calculates where the ratio is the best approximation to kilometers per mile and, surprisingly, it’s at 21/13, a lower number than I would have expected.

Cook also mentions Lucas numbers, which are very similar to Fibonacci numbers except for the starting values. It turns out that Lucas numbers provide an even better approximation but, really, both methods are back of the envelope approximations so who cares.

Perhaps I find this interesting only because I’m a Mathematician but I’m pretty certain the average Irreal reader will find it so too.

Posted in General | Tagged | Leave a comment

🥩 Red Meat Friday: Should You Replace Emacs With An “AI Editor”?

Over at the Emacs subreddit, harmanola, an Emacs user of 16 years, says that he’s recently switched from Emacs to Cursor, the AI code editor. It’s his opinion that Emacs has become unstable, that he’s tired of its “non-standard defaults”, that AI can increase his productivity by 5 times, that Emacs doesn’t scale, and that its developers aren’t on Discord. He also thinks that Emacs might be history soon.

One hardly knows where to begin. Well, I may not but the commenters certainly do. If there was ever a legitimate point to harmanola’s post, it got demolished by one or more of the commenters. To me, the silliest of his arguments is that one needs an “AI editor” to be productive. It seems to me that the AI suggestions are usually just slightly better than the code generated by previous editors that offered to write code for you: great for folks who are mostly generating boilerplate but used by virtually no one else.

The silliness about the Emacs developers not being on Discord strikes me as revealing a sense of entitlement: “I would like your help but I don’t want to go where you give it; please come over here instead.” If you spend 10 minutes on the Emacs mailing list you can’t help but be impressed by how much time guys like Eli Zaretskii spend—for free—on Emacs. As one of the commenters noted, all the things that comprise a healthy development environment—bug fixes, responding to pull requests, and regular updates—are, in fact, happening.

I’m sorry to see harmanola abandon Emacs and I hope he finds happiness elsewhere but his arguments for why we should leave Emacs for an AI editor just don’t withstand scrutiny.

Posted in General | Tagged , | Leave a comment

More On Upgrading Builtins

Last month, I wrote about Charles Choi’s post on the the on package-install-upgrade-built-in variable and how it controls the upgrading of builtin packages. The TL;DR is that when it’s set to t, package.el treats builtin packages as if they had been installed like any other 3rd party package for upgrading purposes.

My first inclination was to wonder why anyone would not want to have it set to t. I could imagine some outlying cases where it didn’t make sense but mostly I’d have expected that upgrading builtin packages was what most users wanted.

Apparently not. Over at the Emacs subreddit, jonas37 asks if people are setting package-install-upgrade-built-in and the comments are revealing. It’s hard to imagine the answer would be controversial but lots of people have strong feelings on the matter.

Take a look at the comments to see what I mean. The answer, as it usually is, is that “it depends”. In short, it’s hard to automate the decision. Sometimes you want to upgrade the builtins and sometimes you don’t.

It’s easy to take the position that your editor, whatever it is, should take care of things for you, but people who do take that position are the first to complain when the algorithmic decision is not to their liking. Sadly, sometimes we just need to engage with Emacs and tell it what we want it to do about upgrading our packages. For many cases. setting apackage-install-upgrade-built-in to t is probably the right decision but sometimes not. It, as they say, depends.

Posted in General | Tagged | Leave a comment

Casual Agenda

Charles Choi is announcing another member of his casual suite: Casual Agenda. Like the other members of his suite, Casual Agenda provides a Transient driven menu that helps you navigate the arcane functionality of Org Agenda View.

I say “arcane” because although it’s easy to use Agenda View to simply list the content of the target files, there’s a lot more functionality hidden in obscure commands that even if you know they exist are hard to remember. Remembering the commands is even harder because Org makes them context sensitive.

Take a look at Choi’s post to see the menus and how they work with each other. It’s a nice system and probably worth installing even if you don’t use the commands often. Especially if you don’t use them often.

I know these command exist but I can never figure out how to access them so I’m really glad to see this latest addition to Choi’s suite. If you’re in the same situation, you should consider installing Casual Agenda.

You can, alternatively, simply install Casual Suite to get all the apps in the collection. This has the advantage that you automatically get additions to the suite when Choi adds them. All the apps have to be invoked explicitly so they never get in the way. If, like me, you follow Choi’s recommendation to bind them all to Ctrl+o, you need only remember a single command to bring up the appropriate menu when you need it.

As I’ve said before, I really like this set of applications and recommend you install the ones you need or possibly just install the entire suite.

Posted in General | Tagged | Leave a comment

Show Font

The ever industrious Protesilaos Stavrou (Prot) just uploaded another nice package to MELPA. It’s a simple little app that displays a font in an Emacs buffer but for those who are on an eternal quest for the perfect font it’s perfect.

The app displays a (configurable) bit of text—think “The quick brown fox…”—and an (again configurable) set of characters underneath. Currently, the app works only with locally installed fonts but Prot is planning to upgrade it to be able to display and install any font.

Prot describes it as a work in progress but it’s already useful and will probably become more so as Prot refines it. It’s not a big thing but it’s another nice example of how Emacs is—or can be made to be—a complete editing environment.

Posted in General | Tagged | Leave a comment

Ant Bridges

This is doubtlessly beyond the remit of Irreal but it’s so interesting I thought I’d write about it anyway. It’s about ants, for crying out loud but take a look and see if you don’t find it interesting too.

As most of you probably know, army ants can use their bodies to build bridges across gaps. That by itself is pretty amazing but consider: how do they know how to do this. The individual ants are practically blind and have very small brains seemingly incapable of organizing such feats.

Simon Garner has been studying this behavior and has reached some conclusions. It’s all instinctual, of course, but how does it work? Army ants move very quickly (about 12 cm/sec) but when they find a gap, they slow down. That causes the ants behind them to march over their backs. When an ant feels that, it freezes in place and subsequent ants move a bit further into the gap until they too feel ants on their back. Bit by bit the ants form a bridge that the rest of the ants can march over. Take a look at the linked article. There’s a video of the process. The article also discusses how the ants know how to dismantle the bridge.

Even more interesting is what happens when there’s a V-shaped gap and the ants are at the top of the V. They could build the bridge there but that takes a lot of ants that could otherwise be employed. They could build it at the bottom but means further travel for the ants. There’s another video that shows the ants solving this problem.

I am by no means an entomologist and my interest in insects is mostly confined to keeping them out of my house. Still, I find this really fascinating and think you will too.

Posted in General | Leave a comment

The Emacs Writing Studio Is Finished and Available

I’ve written about Peter Prevos and his Emacs Writing Studio several times [1, 2, 3, 4 ]. It’s a series of articles on using Emacs for long form writing. Now, happily, Prevos has announced that the project—or at least the first version of it—is finished and available as a book from several e-bookstores. The source files are also available from his GitHub respository.

This is, as I’ve written, a great resource with lots of useful information. But don’t take my word for it. Protesilaos Stavrou also has a few words to say about it. He has, in fact, contributed those words as a forward to the book.

Those of you who have been around for a while know that I’m very interested in stories about people who use Emacs for non-technical purposes such as prose writing. Those who share that interest will find Prevos’ book a handy resource for using Emacs in their own projects.

I’ve read a lot of Prevos’ articles but never read them through as a book. I’m looking forward to reading the complete work.

Posted in General | Tagged | Leave a comment

Remote Emacs in Terminal Mode

There are some people who prefer to run Emacs in terminal mode. I have no problem with that but I do think that GUI Emacs has so much more to offer that it’s usually the best choice. Sometimes there’s no choice.

The need to use terminal mode often comes up when developers have to work on remote systems rather than their local machine. The usual advice is to use Tramp, which often works well and solves the problem but sometimes—especially with remote servers that are not on the local network—tramp can be too slow.

Wai Hon Law is in that situation. His employer does not allow source code on individual machines so he has do all his development on a remote server. Tramp didn’t work for him so he had to find another solution.

That solution involves a good terminal emulator and tmux. The two main problems are getting good colors for syntax highlighting and enabling the clipboard. These mostly depend on choosing the right terminal emulator but Law’s solution may not help too much because he’s using Chrome OS but there are doubtless terminal emulators suitable for your system.

The TL;DR is that you may have to experiment a bit to find the right emulator for your OS but once you do, you can look at Law’s post to get an idea of the other things you need.

I’m lucky that I’ve never been in this situation and could always just use Emacs in GUI mode but if you aren’t so lucky, take a look at Law’s post to see some possible ways forward.

Posted in General | Tagged | Leave a comment