Understanding Hi-line-mode

Tony Aldon wondered how hi-line-mode worked so he looked into it. He was so enchanted with what he found that he decided to share it on reddit. That might not sound too interesting but hi-line-mode depends on two Emacs features, post-command-hook and overlays, that are interesting in their own right. Once you understand them, understanding hi-line-mode is trivial.

The post-command-hook variable, as its name suggests, contains a list of functions to run after every command. Since virtually everything Emacs does—including inserting characters into a buffer—is through a command, the hook gets run every time Emacs does something. In particular, hi-line-mode can be called after every command to update the current line’s highlighting.

The other important aspect of hi-line-mode is the overlay. This is pretty simple and allows you to, among other things, change the text face of a region in the buffer. In the case of hi-line-mode, it changes the background color of the current line to whatever color you’ve chosen.

Once you grok hooks and overlays, it’s easy to understand how hi-line-mode works. Aldon’s post is useful not because it explains how hi-line-mode works but because it explains post-command-hook and overlays. Those are things you can use in your own Elisp code.

Posted in General | Tagged | Leave a comment

Reading RSS With Elfeed

Irreal regulars know that I’m a huge fan of Christopher Wellons’ Elfeed. It’s an Emacs-based RSS reader that allows you to manage and read your RSS feeds from within Emacs. If you’re already an Emacs user, there’s no reason not to be using it.

Ramces Red has a post that explains how and why to use elfeed. Ramces covers the installation and configuration of Elfeed. Other than specifying which feeds you want to follow, you can get away with no configuration at all but Elfeed allows extensive customization. There’s also a thorough and flexible tagging mechanism that you can use to sort posts according to interest.

To me, the most useful thing Elfeed brings to RSS is the ability to store the feeds forever. They all go into a database that is searchable by date and content. Even years later, you can search and find an entry and as long as the original post is still online, you can revisit it.

The one thing that his post doesn’t mention is that you can maintain your list of feeds in Org-mode. To do that you need to load elfeed-org. After that, it’s easy to add or delete entries from your feed even if you aren’t an Elisp expert.

I can’t recommend Elfeed enough. Take a look at Ramces’ post to see why.

Posted in General | Tagged | Leave a comment

Setting latexpreview on Document Startup

NOTE:
Once again, WordPress is refusing to publish the embedded tweet. I don’t think this is Twitter’s fault because it renders perfectly on my local machine; it’s just when I try to push it to WordPress that it fails. I’ve put a link to the tweet instead of the embedded copy.


Eric Fraga offers a tip that although it’s documented, I didn’t know about:

There’s a bit of context missing from the Twitter preview. Manning originally asked how to render LaTeX previews in a Org buffer. Fraga answered that by explaining the Ctrl+c Ctrl+x Ctrl+l key sequence and Manning asked if there was some way of invoking the rendering automatically. Click on the tweet to see the entire thread.

If you use LaTeX a lot in Org documents and like to see it rendered correctly, Fraga’s tip is really useful.

Posted in General | Tagged , | Leave a comment

Red Meat Friday: Forget Linux, Just Use Emacs

An enduring trope in the Emacs community is the notion that Emacs isn’t really an editor, it’s an operating system. We always say we’re joking but sometimes it’s hard to tell. The idea is not completely unfounded. After all, there’s a huge list of things you can do from within Emacs that aren’t really about editing.

It turns out that some people take the idea very seriously indeed. HollywoodKizzle asks on reddit if he should stop learning Linux and just concentrate on Emacs. The advice he received was actually pretty reasonable. There were two takes. The first was to follow his passion and concentrate on Emacs. Opportunities to learn more Linux would inevitably present themselves as time went on.

The other advice was to learn both in tandem. As I’ve said many times, I love staying in Emacs as much as I can but I still find I need to step outside its boundaries occasionally. Of course, as a Linux user, HollywoodKizzle could use EXWM and always stay in Emacs. Even without EXWM, one can invoke a shell and get access to the underlying OS so it always pays to be familiar with as much of the hosting OS as possible.

In any event, the Red Meat Friday message for you Linux heads is to be on guard because Emacs is coming for you.

Posted in General | Tagged , | Leave a comment

Derek Sivers on Plain Text

A recurring theme at Irreal is the virtue of using plain text wherever you can. To my mind, using a proprietary format makes you complicit in the data loss that will inevitably occur sooner or later.

Derek Sivers agrees and has his own post on why you should write plain text files. He begins by saying that he writes down virtually everything important in his life and that he refers to that writing often. Naturally preserving those writings and making sure that they remain available is a priority. A large part of that for Sivers, as for me, is writing all that material as plain text.

Sivers mentions the usual issues of portability and freedom from the vicissitudes of commercial software vendors and the realities of their business. He also mentions the less familiar advantages of plain text such as the ability to convert it into other formats. Even if you’re required to deliver or share a document in something like a DOC file, it’s a simple matter to convert plain text to that format, all the more so if you’re writing in something like Org markup.

The other little-mentioned problem is software that requires an Internet connection to operate. I’ve written before—although I can’t find the post—about a law firm that couldn’t complete legal documents before the filing deadline because their document preparation system, which required an Internet connection, was unavailable due a problem at the vendor’s end. The horror stories write themselves.

Siver’s post is short and worth a read. You can probably read it in a couple of minutes so give it a look.

Update [2022-03-03 Thu 13:44]:
Here’s a couple of examples of people being unable to do their work because their “word processing” software was offline. I misremembered the anecdote about the lawyer: that turned out to be a hypothetical but the point stands.

Posted in General | Tagged | Leave a comment

How To Use Tags

In response to my post Renaming Tags, Karl Voit pointed me to his recent post on How To Use Tags. He said that his system could solve many of the problems I experience with using tags. It’s a long post with lots of good advice but the heart of it are 8 rules he uses for choosing tags. It’s definitely worth taking a look at those rules if you use tags.

The two rules that would most help me are:

  1. Use as few tags as possible
  2. By convention, tags are plural

My major problem is #1. Rather than deciding on a specific set of tags, I tend to make them up as I go along. All of my tagging is happening in an Org Mode context so I get a list for the first tag but I’m on my own for any subsequent tags so I can’t see what I’ve used before. Voit’s tagging system is more general and acts at the file level so his tools have a way of handling this problem.

After dealing with grocery/groceries for a while I (sort of) settled on a rule of using the singular form but I didn’t make it a hard rule. A lot of my problems would disappear if I strictly enforced this rule.

Even if I religiously followed Voit’s suggestions, I would still find myself needing to bulk change tags so I’m grateful for Sagar’s post. Still, if you’re a tag user, you can make your life a lot easier by reading and following the advice in Voit’s post.

Posted in General | Tagged | Leave a comment

Using Paredit’s Slurp and Barf

I’ve been using paredit for 11 or 12 years. I don’t use nearly all its features but I still wouldn’t want to live without it. As I discovered early on, the real secret of paredit is understanding slurp and barf. Without them you can’t edit your file effectively.

Susam Pal has a short post about mnemonics for remembering the shortcuts for paredit’s slurp and barf. Some developers, he says, confuse the shortcuts for snarfing for those for slurping. Pal provides the mnemonics that he used to remember them. I never had that problem. To me, the braces suggest pointing out so Ctrl+} and Ctrl+{ are clearly for barfing.

Actually, I don’t find his mnemonics very helpful but your mileage may vary. His post also gives examples of using slurp and barf so you may find that helpful if you’re not familiar with paredit. One thing for sure, if you’re writing in any of the Lisps, learning paredit is definitely worthwhile.

Posted in General | Tagged | Leave a comment

Podcasts with Elfeed and EMMS

Arne Babenhauserheide has an interesting post on how he listens to podcasts in Emacs using Elfeed and EMMS. It’s a perfect workflow: the podcast episodes are collected from RSS and listed with Elfeed and those he wants to listen to are queued by simply typing A next to the entry in Elfeed. That queues up the entry in EMMS. Babenhauserheide has a step-by-step guide to the workflow in the post.

There’s a tiny bit of configuration to do but it’s just a few lines. Best of all, everything happens from within Emacs and you can do other work while you’re listening if you like.

I don’t generally listen to podcasts but if I did, I’d certainly try this method out. The nice thing about it is that it’s simple to set up and try out. If you decide you don’t like it, it’s easy to back out the changes. Of course, you’ll want Elfeed regardless because it’s the absolute best RSS reader. I don’t use EMMS because

  1. I’m too lazy to set it up
  2. I don’t usually listen to music while I’m working so I just depend on iTunes. (See #1.)

If you’re an Emacs user who listens to podcasts, be sure to take a look at Babenhauserheide’s post. The section on Elfeed/EMMS is short and will take less than a minute to read.

Posted in General | Tagged | Leave a comment

Renaming Tags

Ravi Sagar has a quick video that shows you how to bulk-rename tags in an Org file. If you don’t use tags in your Org files, this probably seems like something you’d hardly ever want to do. Indeed, even Sabar doesn’t seem to understand its real use. But if you do use tags regularly, it’s extraordinarily helpful.

I have several Org files—such as my journal and blog queue—that have one or more tags for every entry. If you’re a real person, you probably get confused when specifying tags. Is it grocery or groceries? Or maybe you get confused about capitalization. My tags are (supposed to be) lower case but sometimes habit takes over and I automatically capitalize a tag that also happens to be a proper name. In any event, I often find myself needing to change several instances of a tag in a file.

Sagar shows a snippet of code that allows you to do just that. You specify the name of the tag you want to change and the name you want to change it to and the code takes care of it for you. The code is from Stack Excahnge and is here. Again, if you don’t use tags you’re probably saying, “Meh, who cares” but if you do, you can immediately see the usefulness of the code.

Posted in General | Tagged , | Leave a comment

Scheme as a Prototyping Language

The other day I saw a link to this short essay on using Scheme as a prototyping language by Jonathan Sobel. The TL;DR is that Sobel was taking an Algorithms class and was assigned a project to implement the fast multiplication algorithm with part of the grade based on fast it ran.

Most of Sobel’s classmates started writing in C. A few of them went directly to assembly language. They spent a lot of time debugging their highly optimized C and assembly code. Sobel pursued a different track; he started writing in Scheme. He began with a naive implementation of the algorithm and iteratively refined it.

Scheme is ideal for this. The language allows one to make correctness-preserving transformations to the code that eliminates function calls and allowed the caching of execution context. Once Sobel had his Scheme implementation optimized, he translated the code into C.

The results were impressive. Sobel’s implementation was the second fastest in the class, beaten only by an implementation written predominantly in assembly language. Sobel says that if he’d known a bit more about Scheme, his implementation would have come in first.

For almost all projects, I find writing in some sort of Lisp gets the job quickly, more accurately, and with a result efficient enough for a final product. In those rare cases where more speed is needed, Sobel’s strategy of writing in a Lisp, debugging and optimizing the program, and finally translating into C is a good strategy.

Posted in Programming | Tagged , | Leave a comment