Regexp Replacers

Sandra Snan over at Idiomdrottning has posted a link to some very idiosyncratic functions that seem at first to be useless or even silly but may, on second thought, actually be useful for some applications. The idea is that they’re like replace-regexp but have the regexp predetermined. The functions are:

  • replace-word
  • replace-line
  • replace-paragraph
  • replace-var
  • replace-sentence

and they replace every instance of their target. For example, replace-word will replace every word in the target area with the substitution value. That doesn’t sound very useful but you can use & to substitute the match in the replacement. Snan has some examples in her post.

Again, these are low use functions but certain workflows may find them and the saving of entering a regexp useful.

Posted in General | Tagged | Leave a comment

Eat: A Preliminary Report

I’m running a little experiment. Even though I recently realized that I hardly ever use a terminal emulator, I was intrigued by this shoutout to the eat terminal emulator package. Except for the usual ankle biters, who don’t appear to have even used the package, the comments were all very supportive, some even saying that it significantly enhanced the commenter’s workflow.

I checked the README at the project’s GitHub repository and I was again impressed. It’s pretty speedy considering that it’s implemented in Elisp. It has several modes. One of those modes lets you move around the buffer and use the usual Emacs editing commands. That’s something that’s missing in vterm so it seems an improvement.

Installing eat is a simple one step process using the package manager. After that, you simply invoke it with Meta+x eat to start a terminal.

As I said, I don’t use terminal emulators very much anymore but I am going to try to use it as much as I can. I still have to refer to the README for the keybindings but I’m sure they’ll soon be absorbed into my muscle memory. There is, in any event, a manual (also available in Info) that covers everything. I’ll report back later with my impressions after I gain a bit more experience with it.

Posted in General | Tagged | Leave a comment

The History of Vi, Vim, and Other Vi Clones

Those of you who have been around Irreal for a while know that I never enlisted in the Vi/Emacs wars. Indeed, I have decades of experience with both and hold each in the highest regard. For a long time now, when people say “Vi”, they probably mean “Vim” so the Vi story necessarily includes that of Vim as well.

Gustavo Pezzi has a nice post on the history of Vi and Vim. Most Vi users probably know that Bill Joy extended the ex editor by giving it a “VIsual” mode but far fewer of those users know the history of Vim. It was, in fact, originally written as a port of Vi to the Commodore Amiga and “Vim” originally stood for “Vi IMitation”.

Pezzi’s post also takes a look at STEVIE and Elvis, two other Vi clones. The reason for all the clones was that Vi shared its code with ex, which was, in turn, an extension of ed, the Unix standard editor that was, technically, available only to those with an AT&T license.

Another interesting story is that Steve Kirkendall started writing Elvis after STEVIE crashed causing him to lose several hours of work. That reminded me of the old days when crashes were frequent and one of the editor mantras was “Save early and often.” Happily those days are long gone and not even the gray beards bother saving their files frequently anymore.

If you’re a Vi/Vim user or have any interest in the history of such things, take a look at Pezzi’s post. It’s an interesting trip into the past.

Posted in General | Tagged | Leave a comment

Converting UltiSnips to Yasnippet

I just ran across this reddit post about Ultyas, a utility to convert UltiSnips to YASnippet format. I was about to move on but UltiSnips stirred a distant memory so I searched Irreal and found a couple of posts that talked about it. The TL;DR is that it’s a Vim package that serves the same purpose as Emacs’ YASnippet.

The reason I wrote about it was Gilles Castel’s astounding post in which he describes taking lecture notes live in the classroom using LaTeX. His secret sauce was a series of UltiSnips snippets that expanded into the appropriate LaTeX. At the time I speculated on using his system with Emacs and YASnippet, perhaps with AUCTeX or Org.

Some of Castel’s snippets were complicated and used regular expressions as the key, which YASnippet didn’t support so a 1-to-1 translation wasn’t possible. Still, various Emacs users—Karthink in particular [1, 2]—were able to do the same thing.

If you’re a student in Mathematics or one of the hard sciences or even a professional who has to write a lot of mathematics, being able to get it into your computer as quickly as Castel or Karthink do is a real win. If you’re interested in trying this yourself and you’re an Emacs user you might want to convert Castel’s snippets to YASnippet. If so, you may find the Ultyas utility useful.

Posted in General | Tagged | Leave a comment

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