A Blast From The Past: Making Gnupg Work With Emacs

I was a little bored today so I thought, “I know, I’ll upgrade all the programs I’ve installed with homebrew.” There were 58 of them that were out of date so it was probably time. I fired off

brew upgade

and sat back to wait for it to complete. I was watching the results fly by and I saw gnupg being upgraded and I thought, “Damn. Now gnupg is broken again when invoked from Emacs.” That’s because Gnupg versions after 2.4.1 have a conflict with Emacs.

The solution is to downgrade to version 2.4.0 but that can be a pain if you use brew to install Gnupg. Happily Álvaro Ramírez has a quick and easy solution that I wrote about here. I searched Irreal for the post and re-downgraded Gnupg. It would be nice if there was some way of telling brew not to upgrade certain packages but in the meantime it’s pretty easy to downgrade it1.

Michael Alan Dorman commented to my original post with another, easier way of solving the problem. I haven’t tried it but if you’re experiencing the problem (on any OS) it may be worth giving it a try.

In any event, consider this a PSA for when you encounter the problem initially or subsequently like I did.

Footnotes:

1

After I wrote this I discovered that you can pin packages but I couldn’t get it to pin any version but the latest (2.4.3), which I don’t even have installed.

Posted in General | Tagged | Leave a comment

Zamansky: Learning Elisp #13

Mike Zamansky has published the latest video in his emoji project. It’s a short video but, for me, the most useful so far. That’s because it’s about something I didn’t understand very well: overlays.

In the last video, Zamansky showed how to automatically replace an emoji keyword with the corresponding emoji. That worked pretty well but the problem is that it permanently changes the buffer and, if saved, the file. This episode shows how to change the display to show the emoji without altering the buffer.

That works by placing an overlay containing the emoji over the keyword. Then the display shows the emoji but the underlying buffer is unchanged. If it is saved and examined, the keyword, not the emoji, will be there. I always thought that the overlay system was complicated and obscure but it’s actually just another text property and handled the same way as the others.

To overlay whatever is at point positions BEG to END with Irreal, you simply make the call

(put-text-property BEG END 'display "Irreal")

If BEG and END mark the position of the keyword and Irreal is replaced by the emoji, the display will show the emoji without changing the buffer. The only change required from the previous code was to replace the code that killed the keyword and inserted with emoji with the code above. It could hardly be simpler.

The video is only 9 minutes, 12 seconds long so it should be easy to fit in. If you’ve ever wondered how overlays work, this video is just what you need to explain it all.

Posted in General | Tagged , | Leave a comment

Running Unix v6

There are lots of people who enjoy the opportunity to experience what it was like to work on early Unix systems. That’s been possible for a long time. Indeed, there’s a cottage industry of experimenters who have built PDP emulators, resurrected early Unix sources, and gotten the original systems running. If you’re interested in that sort of thing, take a look at the Unix Heritage Society and its news list.

The problem is that it’s a lot of work even if you’re using the software that others have already written. Much too much work for those of us with a merely casual interest in trying out one of the historical Unix systems. Fortunately, Russ Cox has solved that problem for us.

Cox has ported Unix v6 to Go, written a PDP-11 emulator, compiled the whole thing to Web Assembly and put up a site that allows you to run the emulator and Unix v6 in your browser. Just follow the link and try it out. You can log in as dmr, ken, or root. Be warned, though, it can suck up a lot of your time.

Cox has a Github repository with all the code for the emulator and ported v6 OS. The userland stuff is the original C versions from various Unix archives so you’re running the original Unix software. If you login as ken you will find the code for Thompson’s famous compiler hack that I wrote about previously. Presumably you can compile it as described in Cox’s post about the hack and try running it on the emulator.

It won’t be quite the same experience of those who have somehow acquired and restored an old PDP-11 and are running v6 on it but it will give you the flavor and, if nothing else, make you realize how easy us kids have it today.

Afterword

This is the third and final post in the Ken Thompson/Old Unix triptych. If, after yesterday’s post, you have an itch to try out ed, Cox’s V6 emulator is a great place because you’ll be working in the original environment and, in any case, it’s the only editor available.

Posted in General | Tagged , | Leave a comment

The ed Video

After yesterday’s post on Thompson’s famous hack, I watched the video of Thompson’s talk at this year’s Southern California Linux Expo that Cox mentioned. That was pretty interesting as another example of Thompson’s curiosity and genius but the point for this post is that YouTube recommended a related video that turned out to be an Emacs Elements video on the ed editor. It covers most of what you need to know to use ed in real life. If you prefer a written tutorial, Brian Kernighan’s tutorial on ed is excellent and what I usually refer to when I forget something.

As I’ve written before, I use ed to edit my mbsync log file. I do this mainly to keep current on ed against the day I need it to recover a Unix or Linux box where nothing else works. With modern systems, that day probably won’t come but if it does, I’m prepared. In the meantime, I’m maintaining my connection with the old ways.

Emacs Elements says that he sometimes uses ed for short editing jobs and for scripts. You can see an example of scripting with ed in Cox’s post about the Thompson Hack. I like ed a lot but I can’t imagine using it as my regular—or even frequent—editor. Others disagree and do just that. It is, in any event, very useful for scripting and worth knowing for that alone. And for you Vi(m) users out there, almost everything in ed is available as a colon command so a knowledge of ed is especially useful for you.

Posted in General | Tagged , | Leave a comment

How The Thompson Hack Worked

Every year or so I revisit and write about Ken Thompson’s 1983 Turing Award lecture, Reflections on Trusting Trust. It’s one of those papers that should be read every year: it seems there’s always something new to learn. The paper is only 3 pages and—unlike the usual academic paper—very easy for any programmer to read.

The TL;DR is that Thompson modified the Unix C compiler so that when it compiled the login module it inserted code to accept a special password for any login. That may seem mundane but Thompson’s hack went one step further: he also modified the compiler to insert code to insert the login backdoor when the compiler itself was being compiled. He then recompiled the compiler, removed all the backdoor code from the compiler source, and recompiled it again with the backdoored compiler. From that point on the compiler would create backdoors for login and for the compiler but with no trace in the compiler source.

Thompson says only that the code he added recognized when login or the compiler was being compiled but offered no details. I’ve often wondered about the details and assumed he used the file name (login.c or cc.c) to decide which code to modify. It turns out that Thompson kept that code and recently Russ Cox obtained it and wrote a post with a complete exegesis of the code and how it worked.

The frightening thing is how simple it was. It operated on the source code and merely looked for the code it wanted to modify. When it found it, it simply inserted the back door code into the source and let the compiler compile it as normal.

The really clever part was how he inserted the backdoor code (that the binary was executing) back into the compiler. That explains his otherwise unexplained mention of what we now call quines in his paper.

Just about everybody in our field recognizes that Thompson is a programming genius and his Turning paper proves the accolades are deserved. Cox’s explanation of how the whole thing worked will leave you even more convinced. Believe me, you really, really want to read Thompson’s paper and Cox’s explanation of the exploit code.

Posted in General | Tagged , | Leave a comment

Does Working From Home Damage Productivity?

I was shuffling through my browser tabs and discovered an item that I meant to write about but had forgotten. It’s dated September 29 so it’s not that old and it’s still germane to the remote work discussion. It’s an article from The Hill entitled Does working from home damage productivity? Just look at the data. The TL;DR is that although there is much discussion on the effects of remote work on worker productivity, almost all of it is anecdotal and lacking evidence.

The article is by Nick Bloom, a professor of Economics at Stanford. He set out to study worker productivity in the face of remote work. He anticipated that they would discover that workers goofed off when not in the office but was surprised to discover that they actually worked longer and were more productive per minute worked than when they were in the office.

Leaving aside the irony of a professor—who, after all, does his research wherever he pleases—being surprised that “ordinary” workers also don’t require constant supervision to be productive, there’s a lesson here: Rather than listen to so called experts bloviate on the matter, it pays to take a look at the data. Bloom captures this idea nicely with the quote:

The work-from-home conversation needs to shift from big-name CEO anecdotes and stories to data and research. When it comes to making decisions impacting millions of employees and firms, we deserve better. The data and research show well-managed work from home can raise and maintain productivity, while cutting costs and raising profits.

The micromanagers will hate that message, of course, but it’s still what the data tells us. Take a look at the article and share it with your management if they’re making noises about getting people back in the office. The data simply doesn’t support their prejudices, no matter how strongly held.

Posted in General | Tagged | Leave a comment

Org-flow-mode

jouke hijlkema has published a nifty project that uses Org mode to draw flow charts. “Uses Org mode” means, in addition to the obvious, that the Org source tree reflects the diagram tree. The project is still new and development is ongoing but it seems to be usable now if you want to try it out. Hijlkema has installation instructions at the repository so it should be easy to give it a spin.

These days, flowcharts aren’t used very much to describe the logic of a program for “coders”. Still, the idea of a flowchart is useful for describing process flows even if they aren’t used as a precursor to writing code. The example Hijlkema shows is pretty complex and it’s easy to imagine it being adapted for all sorts of applications. If nothing else, it would be useful for documenting an algorithm flow.

The “source code” for the example is straightforward and shows that it would be easy to learn and use the application. If you have a need for something like this, take a look at the GitHub repository.

Posted in General | Tagged , | Leave a comment

🥩 Red Meat Friday: You Don’t Need A Terminal Emulator

Andrey Listopadov has an interesting post that advances the notion that you don’t need a terminal emulator. To developers, that’s already an idea worthy of being included as a Red Meat Friday offering but the real reason this is a Red Meat Friday item is the diagram at the top of Listopadov’s post. Vim users aren’t going to like it and VS Code users are really going to hate it.

But fun and games aside, Listopadov is advancing a serious proposition: power users don’t need a terminal emulator. Well, at least if those power users are Emacs users. One thing you can say for Listopadov is that he’s walking the walk. He deleted vterm from his configuration and tries to do everything from within Emacs.

His basic method is to use async-shell-command for most situations where a terminal user would use an interactive command. He has other strategies as well so it’s well worth taking a look at his post to see how he works without a terminal emulator. Particularly noteworthy is his use of Tramp. Using it, he says, eliminates the need to use SSH.

The first time I read his post, I was unconvinced. I could see his point but I thought, “That’s not for me.” Then I realized that I don’t use a terminal emulator either. I have vterm installed but I can’t remember the last time I used it. I do have an iTerm instance but I use it only to bring up the mbsync log so I can practice using ed. When I need to invoke an extra-Emacs application, I use eshell, which, as Listopadov says, is a shell not a terminal emulator.

Emacs users may or may not embrace his workflow but it’s definitely worth taking at look at them. Who knows, perhaps you’ll find a new way of working.

Posted in General | Tagged , | Leave a comment

Five Shell One Liners

Perhaps I’m just old fashioned and pining for the old days. Or perhaps I’m anticipating the time when I can finally wave my cane at all those pesky kids. Whatever the case, I do believe that avoiding the command line—or worse, disparaging it—is leaving a lot on the table.

Doug McIlroy’s original conception of hooking up programs as if there were a garden hose between them is a powerful and liberating idea and arguably one of the most important Unix innovations. You can see it in action in this video about Unix where Brian Kernighan pipes together some simple programs to build a spell checker or in the famous McIlroy rejoinder to Knuth on writing a word count program.

But you don’t even need the power of pipes to see the usefulness of the shell. Mirco has a short post that demonstrates 5 one line shell invocations to solve various problems. In a sense, they’re all trivial problems but try to imagine a better way of solving them—especially with a GUI program in your toolkit.

As far as I can see, these examples are semispecific to Bash and Linux. For example, the last example of negating a file specification doesn’t appear to work with the zshell (although I’m certain there’s an extension that makes it work) and the date example depends on the version of date you’re using. Still, they demonstrate how you can often use the shell to solve a simple problem quickly and easily.

Posted in General | Tagged , | Leave a comment

Emacs Line Wrapping

Line breaking in Emacs is a complicated thing. By default the line just stops at the window edge and you have to scroll right to see some or all of the truncated part. This is called truncating long lines. That’s probably what you want for the programming modes but a case can be made for just breaking the line at the window edge and wrapping the rest to the next displayed line. Emacs calls this wrapping at the window edge. A downside to this method is that a word can be split in the middle if it straddles the window edge.

You can already see a problem with just those two behaviors. What do we call the two “lines” in the second method? It’s actually a single line but it’s displayed as two. Some of the commands that operate on lines treat it as two lines and some treat it as one so there can be a lot of confusion.

But, of course, there’s more. Visual line mode is like wrapping at the window edge but takes care to break the line at a word boundary. That’s probably what you want for writing prose (as opposed to code). It’s the mode I’m using to write this post.

Finally, there’s a fourth mode, autofill mode, that is like visual line mode but inserts actual line breaks at the places the line is split. That makes what you see on the screen correspond to the actual text file.

As I said above, all of this can be a bit confusing. Emacs Elements has a very nice video that explains the terminology for talking about the lines and demonstrates the four modes. It’s 12 minutes, 21 seconds long so you’ll have to set some time aside but it’s a good way to get a handle on this confusing Emacs aspect.

Posted in General | Tagged | Leave a comment