Inlining Images in Org-mode

Bytedude has a short, simple post on how to inline images in Org-mode files. An ankle biter could—and in the comments, did—make a couple of immediate observations:

  1. That’s really simple to do
  2. It’s covered in the manual

Since Irreal doesn’t countenance ankle biters, I’ll merely note that while those two observations are true, I still see a lot of questions about this so it’s worthwhile providing a simple explanation of the process.

If you’ve every wanted to display images in an Org file, take a look at Bytedude’s post. It’s so simple there’s no reason not to.

Posted in General | Tagged , | Leave a comment

111 Programmer Fonts

One thing that we programmers tend to obsess about is our code font. They’re mostly the same, of course, but there are a few characteristics that matter to individual programmers and there’s also the general appearance of the font.

For me, the important thing is a clear distinction between the letter o and the number 0, and the letter l and the number 1. I want the distinction to be immediately apparent. If the distinction is that the zero is skinnier than the letter o, I don’t want to use that font. Similarly for l and 1. I don’t want to think about it—the distinction should be immediately clear just by looking.

Equally important but more subtle is the appearance of the font. I use Inconsolata. I originally chose it because back in the old days it was one of the antialiased fonts and just looked much better than the others. These days, of course, most fonts are antialiased but I’ve stuck with Inconsolata mostly because of inertia: it’s good enough.

Still, every time I see a post about a new font, I have to take a look. Recently, I saw a pointer to a site that has screen shots of 111 programmer fonts. It’s a great way of exploring new fonts. On the left there’s a scrollable list of fonts. When you click on one of them, the corresponding font is displayed on the right. It’s a great way of exploring the fonts available. If you’re looking for a new font, this is a good resource. Even if you’re not looking for a new font, take a look. It will give you an idea of what’s available and may impel you to change.

Posted in General | Tagged | Leave a comment

Presentations With Org-present

David Wilson over at System Crafters has an informative video on how he does the slides for his popular video series. The short answer is that he uses org-present. With org-present you can take an ordinary Org file and have each top level header be a slide. As you’d expect, though, the results are elementary and don’t look particularly nice. Most of Wilson’s video focuses on the tweaks he makes to turn that elementary display into the pleasant and refined presentation slides that you see in his videos.

He starts by centering the text and increasing its size. That alone makes a big difference but the real improvement comes from making appropriate font changes. That means making most of the slide’s text render in a proportional font but keeping things like code in a mono faced font. Add in a little color and an appropriate theme and you’re almost there.

Finally, he adds a few touches to smooth out the look of the slides. The results are very pleasing and you only have to do the setup once. After that, just write the Org file and invoke org-present.

Wilson’s video is 29 minutes so you’ll need to schedule some time but if you you’re giving presentations, it’s well worth the time. He supplies a link to the configuration he discusses so there’s no need to try to copy it as you watch.

Posted in General | Tagged , | Leave a comment

More Examples of DWIM Shell Commands

The other day I wrote about Álvaro Ramírez’s DWIM Shell Commands package. The TL;DR is that it’s a template framework for executing shell commands from within Emacs when the shell command has tricky syntax or hard to remember options.

Since writing the package, Ramírez has been revisiting some of his custom Elisp functions that call shell commands and refactoring them to use his new package. The first example is password protecting one or more PDFs. This example is noteworthy for how much shorter it is using the framework than it was originally. As Ramírez says, the fact that it’s so short and easy to write a custom function for invoking a shell utility means that he’ll do it more often and therefore streamline his workflow.

The second example involves converting a png file to a series of icns files. This example is distinguished by the fact that it’s more like a script than a single invocation of some utility.

You could, of course, do all this with a shell script or some custom Elisp but using the DWIM-shell-command package makes it easy because it does a lot of the work for you. If you find yourself invoking utilities via the shell command from Emacs, you should definitely take a look at Ramírez’s package.

Posted in General | Tagged | Leave a comment

A Quick Introduction to Awk

These days, my main hammer is Emacs and most tasks can be made to look like nails. Throughout my career, though, one of my go to tools was awk. It’s perfect for processing text files with its implied do loop that processes each line, its builtin pattern matching, and its wide selection of functions to work on text elements.

The definitive documentation is The AWK Programming Language book but that’s hard to find now and expensive when you can. Fortunately, awk is fairly easy to understand and the GNU Awk User’s Guide provides detailed documentation.

Yang Zhou has a very nice post that serves as a quick introduction to awk by demonstrating the common awk program patterns. It doesn’t begin to cover the richness of the language but it’s excellent for getting you started. If you’re not already familiar with awk, take a couple of minutes to read Zhou’s post. It’s a nice peak at a very useful scripting language and may inspire you to learn more about it. You might find it a powerful tool that can do all sorts of text jobs easily. And, of course, it’s available everywhere. You can even get the source for the original awk that should compile in most C environments.

Posted in General | Tagged | Leave a comment

Git Delta with Magit

I rarely use any of the diff utilities these days and when I do it’s mostly Ediff to resolve merge conflicts. That probably means I’m working too hard but I’ve always been that way: I just never think of using diff unless I’m really in trouble.

Most other folks are more reasonable and use some sort of diff regularly. A common use case is checking the differences between two versions of a file stored in a Git repository. Magit, of course, has that built in—several options, in fact—but Kaushal Modi really likes the syntax highlighted diff he gets with the command line tool delta.

Of course, Modi wants to stay in Emacs and use Magit. Fortunately, Dan Davison, the author of delta has a package, magit-delta, that allows it to work with Magit. Installation is pretty easy. Just install delta from your favorite package manager (it’s called git-delta in most package managers) and then install magit-delta by adding it to your init.el.

There is, apparently, an issue with displaying line numbers with git-delta (an issue has been raised) but it’s easy to work around that. Take a look at Modi’s post to see screen shots of both the normal delta and the magit-delta output. If you like what you see, just install delta and magit-delta and give them a try. It’s easy to turn it off if you decide you don’t like it.

UPDATE [2022-07-10 Sun 13:09]: Added link to Modi’s post.

Posted in General | Tagged | Leave a comment

DWIM Shell Commands

Álvaro Ramírez is relentless in chasing down ways to eliminate friction from his workflow. One day it occurred to him that invoking shell commands was an area with plenty of opportunities for workflow optimization. A particular problem was that many of the commands he used frequently, such as ffmpeg and convert have a lot of arguments and flags that are hard to remember.

Ramírez’s solution was a write tiny bits of Elisp that would invoke the desired commands without having to remember all the details. To make this work, he first defined a general template framework that allowed specifying what the command should look like with parameters for the file path and parts of the file name.

Because it’s DWIM, the framework does the right thing depending on the context. If you’re in a Dired buffer, the command will operate on all the marked files. If you’re in a file buffer, the command will operate on the associated file. Similarly, how the output of the command is shown depends on the context in which it was invoked. Take a look at Ramírez’s post for the details.

You can check out the framework code, dwim-shell-command.el, to see how things work but the examples in the post are really all you need. Once the framework is in place, adding new DWIM commands is simple. The post has several examples.

If you’re the type of Emacs user who’s always looking for ways to sand down the rough spots in your workflow, take a look at Ramírez’s post. As Ramírez says, if your needs are different, it’s easy to adjust things to suit your requirements.

Posted in General | Tagged | Leave a comment

Emacs As A Terminal Multiplexer

Torstein Krause Johansen runs Emacs in terminl mode on Linux. He likes to have several terminal sessions and switch between them. Previously, he used tmux to multiplex those terminal sessions onto a single screen but then tmux started crashing on him and he didn’t have the time or inclination to track down the problem.

Instead, he realized that he could do everything he wanted from within Emacs. That had the advantage of using the same key bindings that he was already using in Emacs and, less importantly, he didn’t have to worry about keeping the Emacs and tmux color schemes in sync. To accomplish that, he use vterm, multi-vterm, the built-in Emacs shell command, and a bit of custom Elisp, that he calls spawn-shell that allows him to create shells in named buffers the way he would in tmux.

Johansen has a video that explains how he does all this using just the packages and code above. It’s a really nice set up for those who like to run Emacs in terminal mode, of course, but even if you’re running Emacs in GUI mode, you can use the same strategy to provide multiple named shells all running from within Emacs. That’s pretty much what I do and it works well for me.

The video is short, only 5 and a quarter minutes so you can watch it pretty much any time you like. The slides are available but probably not too useful unless you want to copy the spawn-shell code. Definitely worth a few minutes of your time.

Posted in General | Tagged | Leave a comment

Additional Emphasis Markers in Org Mode

I really love the Org-mode markup language. It allows me to compose just about any document that I would actually want to write. That means that I can typeset bold, italics, underline, monofont, and even strikethrough. But some people have more imagination or are just weirder and want more ways of emphasizing text.

What additional ways would you want? The Emacs Notes blog has an answer. I can’t imagine myself ever wanting to typeset something like that example but as the post makes clear, the method is pretty general and allows you to specify emphasis markers that will use whatever font you like, in whatever color, weight, and size you desire.

The TL;DR is that you just need to load org-extra-emphasis.el and configure what you want the extra markers to produce. The blog post covers this in detail so take a look if you’re interested in this capability.

As I said, it’s highly unlikely I’d ever need this facility but it serves as a wonderful example of the extreme extensibility—or perhaps meta-extensibility in this case—of Emacs. In any event, if you need a bit more markup for Org mode, take a look at this post to see how to get it.

Posted in Programming | Tagged , | Leave a comment

A Regular Expression Conundrum

Here’s a little quiz to test your regex-fu. Suppose you want to match any of the strings

  • ab,cd
  • ab-cd
  • ab.cd

Someone proposes the regex ab[,-.]cd but you object that that’s incorrect because the - will be treated as specifying the range of characters between , and .. Oddly, the regex does match all three strings. Why is that?

See Paul Boyd’s post for the answer.

UPDATE [2022-07-05 Tue 14:04]:

I should have said that the regex matches all three strings and only those strings.

Posted in General | Tagged | Leave a comment