Browsing In Emacs

Norman Walsh has an interesting post in which he discusses discovering browsing in Emacs. More specifically, he discovered how to follow a link in an Email and have the result displayed in Emacs. He’s using WebKit with Xwidgets so that means more than just using EWW.

In his setup, which judging from the screenshot is on a Mac, typing return on a link in an email renders the link in HTML in the Emacs buffer. He doesn’t say what email client he’s using but with mu4e, which I use, that doesn’t happen. Rather, the link opens in the browser. At first I thought that I must have some sort of configuration item causing the difference but I couldn’t find anything. In any event, it doesn’t matter for mu4e because if it detects you have Xwidgets installed it will automatically include a binding (ax) to render the email in HTML. From there, you can follow any other links by clicking on them.

That’s pretty nice, but it gets better. I also have elfeed-webkit installed so that I can read my elfeed RSS entries in HTML as well. What actually happens is that elfeed-webkit follows the source link in the RSS and renders it in HTML. You can configure it to automatically include or exclude specific sites if you need to.

The takeaway from all this is that it’s possible to render emails, elfeed entries, and various other links in HTML directly in an Emacs buffer. Walsh discovered one aspect of a much larger field of possibilities. Emacs has gotten pretty good at handling HTML within Emacs. There are still a few dark corners but things are getting better and better. I’m looking forward to the day I can finally ditch my browser.

Posted in General | Tagged | Leave a comment

Highlighting Regular Expressions

Charles Choi has another Emacs nugget: how to (persistently) highlight isearch targets. The idea is that you may have a lot of hits for your search and would like to keep them highlighted so that you can examine them in detail. That turns out to be pretty simple. You simply type Meta+s h r and Emacs will exit isearch mode and highlight the text matching the regular expression. You can also highlight the entire line containing the match by typing Meta+s h l.

His post stirred a (very) distant memory so I checked Irreal and discovered that this subject is like the Phoenix: it keeps rising from the ashes. I’ve written about it at least twice, the first time in 2011, and the last time in 2022. If you check those posts, you’ll discover that there are several related commands that highlight objects in similar ways.

Choi’s post is an update to his previous post on using transient for isearch that I also wrote about. He says that although he loves the highlighting commands, he’d never be able to remember them so he added them to his transient menu.

Every time I write about this, I’m firmly convinced that the bindings make perfect sense and I’ll be able to remember them. Alas, Choi is correct. I can’t even remember that the commands exist let alone what their bindings are.

As a final point, it’s worth noting that the commands are actually a bit more general than Choi states. The isearch-highlight-regexp command actually calls highlight-regexp and passes it the current isearch target regexp and highlighting color. Similarly for the whole line variant. Thus you can highlight objects in the buffer without going through isearch. Happily, the same keybindings work in either case so if you can remember them it’s the same whether or not you’re coming from isearch.

Posted in General | Tagged | Leave a comment

A Blast From The Past: Emacs For The CEO

Back in 2015, I wrote about Josh Stella’s wonderful article on A CEO’s Guide to Emacs. Someone just posted a link to Stella’s post so I took the opportunity to reread it. It seems just as apropos now as it did then.

The TL;DR is that Stella began his career as a developer and basically lived in Emacs. He used it for everything. With the passage of time he moved on from his developer role and became a CEO (of Fugue). Like CEOs everywhere, he used a multitude of applications to get his work done. But his life as a developer had taught him to eschew context switching and to value a uniform UI to the applications he needed. On day he realized that what he really wanted was Emacs so he started a small experiment to see if he really could use Emacs in his role as a CEO.

The answer, of course, was an emphatic yes and he devotes part of his post explaining why. The rest of the post is a quick introduction to Emacs and how to set it up. His purpose was to bootstrap other CEOs into the Emacs world. He was pretty realistic about this undertaking and stated up front that if you’ve never done any coding or other technical work, Emacs probably isn’t for you. But if you have, Emacs can open a world of opportunity.

Some of his recommendations are a bit outdated (2015, remember) but it has aged well. It’s definitely worth a read even if you read it back when he first published it.

Posted in General | Tagged | Leave a comment

Query Replace Regexp

Susam Pal has a nice reminder on using query-replace-regexp. Most Emacs users know about the command and its binding Ctrl+Meta+% but Pal’s post mentions some less known features that can be very useful.

The first—and simplest—is using \& in the replacement string. It expands to whatever was matched by the regular expression and is often useful.

The second feature is that you can call a function to compute the replacement string. You indicate such a function by beginning the replacement string with \, followed by the appropriate s-expr. The example that Pal gives is \,(upcase \&) which upper cases whatever the regular expression matched.

The final item involves matched substrings. Most Emacs users are familiar with the idea of matched substrings and the corresponding \n notation in the replacement string that expands to the nth matched substring. Sometimes, though, it’s convenient to capture the nth substring as a number. To do that you simply use the notation \#n. This is mostly useful when you are calculating the replacement string. For example, you could add 1 to the third matched substring with \,(+ 1 \#3). Pal has a couple of more robust examples in his post.

All this is, in a sense, old news but Pal’s post serves as a very useful reminder of some of the corner cases in query-replace-regexp that can occasionally save the day. Pal has a real, but simple, example of its use in his post so head on over and read it.

Of course, all this applies to the other regexp search and replace functions as well so it’s definitely worth knowing.

Posted in General | Tagged | Leave a comment

Boeing Again

I was reading this PBS story on the recent Alaskan Airlines incident in which a door panel blew off in midair and it tickled a distant memory of a post I wrote about Boeing before. A simple search of Irreal revealed two posts [1, 2] from 2019 that discussed the far more serious incidents that resulted in significant loss of lives.

Read the posts. They stand up pretty well, I think. The TL;DR is that Boeing, which had been the aircraft industry leader for as long as there has been an aircraft industry, was always an engineering centered company. Basically, the engineers ran the company. That is, they were until some meddling by politicians pressured them to merge with McDonnell Douglas, which in turn led to the capture of the company by the suits. These were guys with the very necessary knowledge of things like finance and marketing but who knew little about aviation. Rather than concentrating on what they knew best, the suits started making engineering decisions. I needn’t tell you the results.

Boeing, apparently, learned nothing from their last fiasco. The evidence isn’t all in yet but Alaskan Airlines and other airlines have discovered loose bolts on the door plug that probably caused the incident.

This is what happens when “professional managers” with no engineering expertise think they should make engineering decisions. Read that second post from 2019 and notice the arrogance of their CEO and his smug description of “the Hollywood model” for dealing with engineers.

This principal has equal application to our own industry. When people with no engineering experience start making all the decisions, the end of the company is foretold. I’ve seen it firsthand and I’m sure many of you have too.

Posted in General | Tagged | Leave a comment

Removing Diacritics From A String

Jeremy Friesen has another interesting post. This time it’s about removing diacritics from a string. His problem is that he uses the same string for the title of a post as well as the name of the file containing the post but when a title contains diacritics, he doesn’t want those diacritics to appear in the file name.

To solve that problem he wrote some Elisp to replace each character having a diacritic with the corresponding character without the diacritic. For example, ç would be replaced with c. His code works fine but strikes me as being unlispy even though it’s written in Elisp.

Here, as an exercise, is my version of his code. First we need to generate the mapping between the characters with diacritics to those without. Friesen’s code produces CONS cells with the characters as strings: ("ç" . "c") for example. Since we will be replacing characters, it makes sense to keep the mappings as characters rather than strings. Here’s code to replace his code to produce the mapping jf/diacritics-to-non-diacritics-map.

(defvar jf/diacritics-to-non-diacritics-map
  (map 'list (lambda (a b) (cons a b))
       "ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽža"
       "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz"))

That seems to me to be much simpler than Friesen’s solution. There’s no nasty indexing into a list: map handles the whole thing.

His code to actually replace the diacritics is reasonably Lispy and his use of reduce is clever. It would never have occurred to me. Here’s what I came up with:

(defun jf/remove-diacritics-from (string)
  "Remove the diacritics from STRING."
  (map 'string (lambda (c) (or (cdr (assoc c jf/diacritics-to-non-diacritics-map)) c)) string))

If nothing else, my code has the advantage of parsimony.

Regardless of what code you prefer, Friesen’s idea is a useful one. Why have diacritics in a file name that only serve to make it harder to type?

Posted in General | Tagged | Leave a comment

Elisp Specifics

Lots of Emacs users find Elisp intimidating. There are at least two aspects to this. First of all, it’s a Lisp. That means that everything looks different and, yes, there are a lot of parentheses. But this is only an apparent problem. The truth is that Lisp is syntactically simple and very easy to learn. The difficulty is learning its run-time library. Every Lisp has a large number of functions but even then it’s pretty easy to learn enough to start using Lisp.

The second problem is that Elisp—which is, after all, short for Emacs Lisp—is specialized for the Emacs environment. That means that it has lots of features that other Lisps don’t need such as buffer local variables. Even programmers familiar with other Lisps can find themselves at sea with Elisp.

Over at Positron’s Emacs Channel, there’s a very nice video, Elisp Idiosyncarsies, that explores some of the peculiarities of Emacs Lisp such as the aforementioned buffer local variables. The video is fast paced but mentions most of the Elisp specific things you need to know to use Elisp effectively. Of course, mastering those idiosyncrasies is going to take a bit more than watching a video but the video gives you an idea where the problems lay.

The video is just short of 17 minutes so you’ll need to schedule some time but if you want to understand Elisp—especially if you’re coming from some other Lisp—it’s a worthwhile introduction.

Posted in General | Tagged , | Leave a comment

MacAdie’s Frequent Org Commands

Eric MacAdie has an update to his previous post on his frequent Emacs commands. This post takes a look at his frequent Org mode commands.

As with Emacs proper, MacAdie has an idiosyncratic method of dealing with Org. Rather than use the key chord shortcuts, he does most things with the command names. It seemed to me that his discussion was the first time I’d ever seen the name of some of those commands.

The process seems to work for him so, of course, I have no objection to it. It’s just another way you can work with Emacs in a way that’s most comfortable to you.

The post itself is a useful introduction to Org. It’s often said that you shouldn’t try to learn all of Org out of the box. Rather, start by learning how to do a couple of things that are immediately useful to you. That’s pretty much the way MacAdie approached learning Org.

One nice thing about his post is that he discusses how to handle recurring events. You can specify that an event should appear in your agenda repeatedly every day/week/month/year but the control is actually a bit finer than that. Take a look at his post or the Org manual for the details.

My other takeaway from his post is that I’d much rather learn the key chord shortcuts than try to remember the actual commands.

Posted in General | Tagged , | Leave a comment

Avoiding Large Archive Files

Over at Free Range Bits, Peter Jones has a nice solution to the problem of large Org mode archive files. The idea of an archive file is that you can move a retired subtree of a file to an archive so that the original file doesn’t grow too large. Of course, this means that eventually the archive file will also grow large bringing the usual performance problems.

Jones’ idea is to save an archived subtree to the day’s journal file. In a sense this is the sweet spot. Yes, you’ll have many files holding the archived subtrees instead of one but those files exist anyway and since there’s a new one everyday, they never get very large.

Th mechanics of Jones’ solution is specific to his particular configuration, which uses the Org-roam journaling functionality. In particular, that functionality use a separate file for each day’s journal entries but any journaling system that uses separate daily files will work just as well. For that matter, any information store that uses daily (or weekly, monthly, or other short period) files is also a candidate but journal files seems especially appropriate.

Jones has a simple function that does the archiving for him by using the Org-roam functionality. It would be easy to roll your own depending on your specific setup. The important part is how to tie it into the Org archiving system, which Jones shows in his implementation.

If you use Org mode archiving, you should definitely take a look at Jones’ post. It has some good ideas.

Posted in General | Tagged , | Leave a comment

An Example Of A Emacs Keyboard Macro

Jeremy Friesen has an interesting example of using an Emacs keyboard macro. What makes it interesting is that the macro deals with three files, switching between them as needed. The problem he was solving, as I understand it, was to add certain metadata to two versions of a series of files. The third file held links to the entries in the other files.

There are two takeaways from the post for me. The first, most obviously, is using a keyboard macro to capture a routine but error prone process so it can be performed easily and without error. The macro is actually straightforward even though it is dealing with three files.

The second takeaway is a bit more controversial. This process is needed because Friesen publishes his blog with Hugo but writes his posts with Org mode. After writing them in Org he exports the Org file to markdown with Ox-Hugo and uses the markdown file for the actual publishing.

This, it seems to me, is a process begging for some refactoring. Believe me, I understand why he hasn’t done so. Long time readers will remember the many times I finally got around to fixing some overly complicated process in my own workflow and wondered in print why it took me so long.

At the very least, I would automate the Org mode → Hugo publishable file pipeline and keep only the Org file. A better solution is to find a publishing workflow that accepts Org files to begin with. I vaguely recall that someone (Mike Zamansky?) discovered a way to use Org files directly with Hugo. Even in the likely event that I’m misremembering, there are certainly other static site generators that accept Org files.

I’m confident that Friesen will eventually optimize this process just as I eventually get around to optimizing mine. In the mean time, his post is a good example of using keyboard macros to automate a tedious and error prone process.

UPDATE [2024-01-08 Mon 11:20]: Added link to Friesen’s post.

Posted in General | Tagged , | Leave a comment