An Example of Literate Programming

As I’ve mentioned before, I’m ambivalent about literate programming. I love the idea of it and absolutely agree with all its claimed strengths but I’ve never been able to embrace it in practice. The major problem, I think, is that when I’m reading code—and particularly when I’m debugging it—I like to be able to see everything in context and not have related parts scattered throughout the narrative. I don’t think that’s just me waving my cane but perhaps I’m deceiving myself.

One of the common use cases I see for literate programming is in Emacs configuration files. It make’s it easy to explain why you want things to be configured in a particular way and follow the explanation with a code block that implements it. Usually that results in a fairly coarse division of the code and you can see everything relevant at a glance. Even better, using Org-mode means you can fold the sections making it easy to find and open just what you want.

Hsin-Hao Yu has a nice post on his experiments with literate programming. Like me, he thinks that WEB-style literate programming in Knuth’s sense is overkill for his uses. He decided to experiment a bit using Org-mode with his configuration file. So far that sounds like what lots of other folks have done but Yu pushed the idea a little further by using the noweb feature to restructure the code and make the code layout more logical—at least more logical in the literate programming sense.

The example he gives for this is illustrative. He starts with his definition of org-capture-templates that defines 3 templates. Yu says he finds it hard to read and even harder to add another template in the right place. He fixes that by putting each template in a separate code block and using noweb to pull them all into the setq for org-capture-template. That makes it easy to add another template, of course, but he pushes the idea even further by suggesting that the templates could be moved to the section with which they’re related: the journal capture template could be moved to the section that configures his journal, for example.

That last point is where I become ambivalent again. I agree it makes perfect sense and all but I can’t get over the idea the templates should be defined in the same place. Yu’s opinion in this is as good as mine, of course, and as usual Emacs lets us have it our way but if you come down on Yu’s side of the debate, the example shows you how to implement it.

If you have any interest at all in literate programming, take a look at Yu’s post.

Posted in General | Tagged , | Leave a comment

Transient Mark Mode

If you’ve been an Emacs user for a while, you probably know what transient mark mode is and you might even know that its use is—or was—controversial. It used to be disabled by default but in Emacs 23 the default was changed to enabled. I’ve never understood the controversy. Why wouldn’t you want the active region to be highlighted? I started with Emacs 21 and one of the first things I did was enable it. In fact, I just checked and it’s still in my init.el. After almost a decade and a half of Emacs use, I still didn’t understand the controversy. Until today.

Wilfred Hughes just tweeted a link to a post by Sean Whitton that explains the transient mark mode controversy and gives some mitigations. There are two problems with transient mark mode:

  1. If you want to just set the mark (to jump back to it later, for example) you have to type Ctrl+Space Ctrl+Space instead of just Ctrl+Space to set the mark without activating it.
  2. When you use Ctrl+x Ctrl+x to switch the mark and point, it activates the region between them and you have to either precede the sequence with a Ctrl+u or follow it with a Ctrl+g to avoid the highlighting.

The first isn’t much of a problem. Especially for me since I don’t set the mark manually very often. The second is a little more annoying but is hardly a deal breaker. In any event, Whitton gives a bit of Elisp to inactivate the mark after the switch so that the region doesn’t get highlighted.

There are some benefits to transient mark mode other than highlighting the region that you can read about in Whitton’s post. He provides another bit of Elisp the provides those advantages without having to have transient mark mode enabled. He says that he has been running with the second—but not the first—fix enabled and transient mark mode disabled and found that he didn’t mind not seeing the active region highlighted.

That strikes me like living without air conditioning. Sure, you can do it but why? Whitton’s post made me think that I made the right decision in enabling transient mark mode all those years ago but your mileage may vary. Read Whitton’s post and make up your own mind. At least you’ll know what the controversy is about.

Posted in General | Tagged | Leave a comment

Using a Local Emacs From a Remote Host

Michał Nazarewicz has a very interesting post on using Emacs to edit files on a remote system. Your first reaction is likely, “Meh, isn’t that just Tramp?” I know that was mine but Nazarewicz has a specific requirement: he wants to SSH into the remote system, do his work, and, when he wants to edit a file, use emacsclient to connect back to the Emacs server running on his local host. It is, in a sense, the reverse of what you with Tramp: instead of connecting to a remote file from the local Emacs server, you connect to the local server from the remote host.

The point of this, apparently, is to avoid changing to another shell session when you want to edit a (remote) file. Whether you think this is worth the effort probably depends on what you do on the remote host. If you just want to edit a file or two, Tramp is probably fine. If you’re performing lots of other tasks, Nazarewicz’s method may be useful.

The TL;DR is that when you SSH to the remote host, you arrange to forward the (remote) Emacs server port to the local Emacs server port. That way, when you invoke emacsclient on the remote host, it connects to the server on your local machine. It’s a cute trick but the details can be a little fussy. Read Nazarewicz’s post for the details.

Update [2021-02-04 Thu 16:10]: Added link to Nazarewicz’s post.

Posted in General | Leave a comment

Symlink Copying with Dired

Marcin Borkowski (mbork) has a handy tip concerning something I didn’t know about. If you use dired—as you should—for your file operations and you know that you can use C to copy one or more files. By default, the command, dired-do-copy, copies symlinks by creating another symlink as the target.

Most of the time, that’s probably what you want but not always. It turns out you can make an actual copy of the file by specifying the universal argument. See mbork’s post for post for the details.

Posted in General | Tagged | Leave a comment

Kids and Typewriters

I’m not sure why I’m writing about this other than that I find it really annoying and can’t get it out of my mind. It sort of fits into the new Luddites category, which automatically makes it irksome but there’s also the matter of it being completely pointless and stupid.

The “thing” in question is an article over at Lifehacker that urges parents to buy their kids a typewriter. That seems innocent enough until we get to the reasons. For example:

  • You don’t have to walk to the printer to get the results; it’s right there.
  • Kids will learn to accept mistakes that are difficult to correct.
  • Typewriters don’t have screens and that’s good (somehow).
  • “Real” letters are more fun to receive.

All of these so called reasons have trivial rejoinders that are so obvious there’s no point in listing them but there are two points worth mentioning:

  1. Notice how they embrace the New Luddite theme of “the old way is best; new-fangled ideas should be eschewed.”
  2. They are, at base, not serious—just silly, really.

If you substitute rotary phone or abacus for typewriter the arguments make just as much sense. As I’ve said before, I’m perfectly happy for these people to go back to the farm, grow their own food, and carry water up from the well every morning. I just wish they’d leave the rest of us alone to get on with our lives.

Posted in General | Tagged | Leave a comment

Emacs 27.2 Pretest 2 Is Out

Eli Zartetskii announced on the emacs-devel list that the second pretest for Emacs 27.2 is ready. The announcement tells you where to get the tarballs if you prefer that method to using the git repository.

As always, show your thanks to Eli and the other developers by testing the release if you can.

Posted in General | Tagged | Leave a comment

Read Meat Friday: The Editor Wars

Yes, yes. We know it’s not quite true but it feels emotionally right. Or at least, satisfying.

Posted in General | Tagged , | Leave a comment

Reading HTML Emails with Mu4e

Yesterday, in my post about sending HTML emails with mu4e, I noted that being able to send HTML emails is only half the problem; probably the easiest half. The hard part is being able to read a properly rendered email form within mu4e. Eww sometimes works—sort of—but some emails (Amazon is a notable guilty party here) are simply unreadable without a trip to the browser. It’s not that hard to pop up a browser tab and then delete it when you’re done but that’s extra work and violates the stay-in-Emacs rule that many of us try to live by.

If you’re an X user, RichieHHam has a possible answer for you. He has a reddit post that describes how to use XWidgets to read emails from within Emacs. Sadly, if you’re a Mac user like me, this solution is not available to you—at least not easily.

Being a Mac user also means I can’t try this out so I have no idea how well it works. If you’re a Linux user and try it out, leave a comment to let other Irreal readers running Linux know.

Afterword
After I wrote this, I nosed around the Internet a bit and discovered that there are some XWidget solutions for macOS but I have no idea if they would work with RichieHHam’s HTML email setup. Really, the best solution is for Emacs to accurately render HTML natively but that’s not trivial.

Posted in General | Tagged | Leave a comment

Sending HTML Mail With Mu4e

Like all right thinking people, I abhor HTML emails but that’s a ship that sailed long ago and there’s not much choice other than grudging acceptance. The virtuous can, of course, continue to send plain text but sometimes your content or recipient really does need HTML. And truth be told, I often wish I could add some simple formatting like italics or bold.

David Wilson over at the System Crafters YouTube Channel has an excellent video on sending HTML with mu4e. The TL;DR is that you use org-mime to create a multipart email with plain text and HTML versions of your message. That’s pretty nice but the real win is using Org-mode to compose your emails. That lets you use the usual markup for things like bold and italics, add headers and links and all the other nice things that Org offers. Wilson’s video explains how to do all this and a couple of other things as well.

Sadly, this addresses only half the problem. The other side is rendering HTML messages that you receive. You’ve got eww but that often doesn’t work satisfactorily with emails. You can ask mu4e to display a message in your browser but then you’re leaving Emacs.

This is a good video and definitely worth watching. It runs 29 minutes, 12 seconds so you’ll have to schedule some time but if you’re a mu4e user you should definitely spend that time.

Posted in General | Tagged , | Leave a comment

Modernizing Emacs (Again)

I cry out in despair, “For the love of Cthulhu, not again.” And yet my pleas go unanswered. LWN has an article on the latest iteration of “Hey kids! Let’s make Emacs more modern.” that keeps reappearing on the Emacs-devel list like a stubborn rash that won’t go away. The suggestions are mostly the usual silliness like making the default theme be dark mode, and, of course, making CUA mode the default—current users be damned.

I’ve got some objections. One of the complaints is that themes are too hard for n00bs to figure out. I’m not sure what happens these days but when I first started using Emacs I recall being asked if I wanted what we now call a light or dark theme. I chose the light theme and all the other syntax highlighting colors were chosen for me and seemed perfectly fine. Later, when I had a bit more experience and the white background began bothering my eyes, I set background to a light tan and made the cursor red. That’s one line for the background and one for the cursor. Installing the theme of your choice is even easier. If, at that point, I had wanted a more specialized theme, I would have had no problem installing it. Indeed, I did install Solarized for about 38 seconds, which was all it took me to decide I didn’t like it. None of this is very hard.

This crystallizes my main objection to all this. To my mind, if you don’t have the commitment to figure out how to install a theme of your liking—again, a fairly trivial task—then, really, Emacs is probably not for you. Emacs is all about providing you with a highly customized text processing environment. You start with something very basic and mold it to fit your needs. If you’re not willing to learn how to do that, what’s the point?

And really, I think chasing these “new users” is mostly a fool’s errand. The new users who are serious developers will find Emacs or Vim or another editor that meets their needs on their own. The new users who are today’s equivalent of the web site developers of yore never will. They’re all about pushing a button and having a bunch of boiler plate inserted for them. They’ll never adopt Emacs.

Every time I write something like that, I get accused of being mean but I don’t mean to be. In this vein, another suggestion was to package some videos giving n00bs an overview. Here’s what Stefan Monnier, a former lead Emacs maintainer, had to say about that. See? I’m not that mean.

Posted in General | Tagged | Leave a comment