Running Asynchronous Processes in Eshell

Nacho Barrientos has an interesting video in which he explains how to run an eshell process in the background. Barrientos illustrates this with the sleep command. Normally, if you enter

sleep 4

in Eshell, Emacs will hang until sleep completes in 4 seconds. Barrientos’ idea is to use the Emacs compile mechanism to run the command in the background. The output is redirected to the *compile* buffer and the Eshell prompt returns immediately.

That’s a nice way of starting a long running process from Eshell and being able to continue working in Emacs. He also has a way of burying the *compile* buffer and getting a message when the process completes.

There’s not a lot of code needed to implement this. You can see the relevant function in Barrientos’ init.el. If you use Eshell regularly and sometimes want to invoke long-running processes, it’s worth taking a look at this video. The run time is only 4 minutes, 21 seconds so it should be easy to fit it in

UPDATE [2021-12-31 Fri 13:03]: In the comments, Niklas Eklund writes that he has a package that does the same sort of thing. You can read his post about it here. Elkund’s package works with any shell so it may be a worthwhile addition to your configuration.

Posted in General | Tagged | Leave a comment

The Sam Editor

I’ve used most of the traditional editors. By “traditional” I mean editors like ed, ex, vi/vim, Emacs, Acme, and even—back in the day—brief. One editor I’ve never tried is Sam. Sam, like Acme, was written by Rob Pike so if you know anything at all about the Unix milieu it’s entitled to automatic respect.

You don’t have to take my word for it. It’s reportedly the editor of choice for Ken Thompson, Brian Kernighan, Doug McIlroy, Bjarne Stroustrup, and others. That’s a lot of world class programmers voting for Sam.

If you want to get a flavor of what working with Sam is like, Matthew D. Miller has a post that recounts his experiences with it. Miller is not really a Sam user but he wanted to see what it was like. You can read the post to get his impressions but the thing that stands out to me is how mouse-centric it is. That’s not surprising because Pike is a believer in the superiority of the mouse over the keyboard for speed and efficiency.

We Emacsers (and Vi users for that matter) are having none of that and will forever forswear the mouse in favor of the keyboard but there’s room for everyone. You can even use the mouse with Emacs and Vim if you like.

Regardless, if you’ve ever wondered what using Sam was like, take a look at Miller’s post to get a feeling for it. If it sounds good to you, download it and try it out. You can always come back to the one true editor.

Posted in General | Tagged | Leave a comment

Exporting Math to Word or LibreOffice

Any of you with an even fleeting familiarity with Irreal know that we are not fans of Word and its evil siblings. Still, even though our official position is that Word—in all its incarnations—is the spawn of the Devil, we recognize some folks have no choice but to use it, at least for the final document and, in the ecumenical spirit, Irreal is here to pass on some helpful information.

Over at Emacs Notes there’s a post from last year that has some advice for people exporting math from Org-mode to LibreOffice or Word. It turns out that neither do very well with LaTeX markup even if it’s converted to, say, MathML first. The problem appears to be that LibreOffice doesn’t do a good job of importing MathML. The other possibility is to convert the math to a PNG but then the results are not editable.

The correct way, according to the post, is to use Starmath markup instead. It’s native to LibreOffice and renders well. If you often export mathematical content from Org to LibreOffice, you should take a look at the post to see how use Starmath. There are a couple problems with this solution. The major disadvantage is that you lose document portability. If you use Starmath markup you can no longer export to HTML or LaTeX. Still, if you absolutely must provide ODT format documents but want to write in a sane environment, this tip may be a help.

AFTERWORD

Just as I was getting ready to publish this, I noticed that there was a follow-on post from Emacs Notes on how to mix Starmath and LaTeX in the same Org file. Actually, the post is a bit more general and shows how to conditionally include content depending on what exporter you’re using. A great addition to the previous post.

Posted in General | Tagged , | Leave a comment

Red Meat Friday: The Oxford Comma

There’s a particularly odious type of reprobate who refuses to use the Oxford comma. A subset of the type can claim ignorance as a mitigating factor but, sadly, the majority of the transgressors do so with full knowledge and understanding of their offense.

The rightness of the Oxford comma could hardly be more clear: it prevents ambiguity1. Here’s an example of a fictitious book dedication from the Wikipedia article on the Oxford comma:

1. To my parents, Ayn Rand and God.
2. To my parents, Ayn Rand, and God.

The first, without the Oxford comma, implies that the author’s parents are Ayn Rand and God. The second makes clear what the author is trying to say. That’s an amusing example—especially if you know anything about Ayn Rand—but failure to respect the Oxford comma has real world consequences as shown in the famous O’Connor v. Oakhurst Dairy case.

The TL;DR of the case was that Oakhurst Dairy lost a $10,000,000 suit from their drivers over whether or not they owed the drivers overtime. Oakhurst relied on a Maine statute that specified overtime was not owed to those engaged in the “The canning, processing, preserving, freezing, drying, marketing, storing, packing for shipment or distribution of: (1) Agricultural produce; (2) Meat and fish products; and (3) Perishable foods.” Notice the lack of the Oxford comma. The court held that since the drivers were not involved in the packing of goods for “shipment or distribution” they were not exempt and Oakhurst owed them overtime.

It’s pretty clear that the legislators did intend the drivers to be exempt but wrote the legislation sloppily. It turns out that it’s not really their fault because the Maine Legislative Drafting Manual said the Oxford comma should not be used. And so Oakhurst Dairy paid the price for the sins of the Oxford-comma-eschewing legislative guidelines. In any event, this is what happens when you don’t respect the Oxford comma.

Footnotes:

1

Yes, I’m aware of the counter examples but, really, they’re contrived.

Posted in General | Tagged , , | Leave a comment

Emacs TIL

Junji Zhi has a newish (since September) blog that he calls Emacs TIL. As the name suggests, it’s a collection of small tips that Zhi learned on any particular day. The tips are all short—one or two minute reads—and easy to digest.

Many of his discoveries will be familiar to experienced Emacs users but, to me at least, some were new. It doesn’t really matter because they’re so short that you don’t have to spend much time with them. If you’re interested in the opportunity to discover short Emacs tips, it’s worthwhile subscribing to his feed. It’s not a high volume blog so you won’t be overwhelmed.

Posted in General | Tagged | Leave a comment

Exporting Environments From Org-mode

This is a followup to yesterday’s post on Nicolas P. Rougier’s notebook-mode. When I was going through the code trying to understand how everything worked I noticed that the Org source code had a #+begin_sidefig / #+end_sidefig environment that mapped to a <div class="sidefig" id="org08c8fb0"> element in the HTML. The definition of that division was provided by the CSS of course, but I wondered where the mapping came from. My first thought was that it must have been implemented in a package that the code required but I couldn’t figure out what package it was or how it was being included.

It turns out that you can use begin_xxx / end_xxx for any value of xxx and Org will do the right thing. If you export the Org file to HTML it will be mapped into a <div> that you can define in a CSS file (or in the Org file, for that matter). If you export it to PDF (via LaTeX) it will be mapped into a \begin{xxx} / \end{xxx} environment that, once again, you can define however you like.

Many of you are probably already aware of this but it’s a revelation to me. It means that you can produce arbitrarily beautiful output directly from Org-mode. Doubtless something similar happens if you export to docx but Irreal has no interest such matters.

If you’re exporting to HTML, you can provide environment definitions in a CSS file. If you’re exporting to to PDF, you can define the definitions in a LaTeX package definition or directly in the Org file. It’s another example of how Org-mode allows you to generate arbitrarily complex output.

Posted in General | Tagged , | Leave a comment

A Beautiful Example of Literate Programming In Org-mode

Look at this!

Despite my protestations of being all-digital / all-day, I’m a sucker for this type of thing. It’s just so beautiful and well done that it’s easy to forget that it was made with Org-mode. Happily. Rougier has a GitHub repository with the Org file and CSS for the example. There’s also a larger rendering of the finished product.

As is clear from the repository, the example is not so much about literate programming as it is about implementing a package he calls notebook-mode. It is still a work in progress but looks really promising. You can see how the example was done by taking a look at notebook.org in the repository.

I love examples like this. They show that it’s possible to build beautiful, interactive documents fairly simply with Org-mode. It will be interesting to see if Rougier expands the PDF export to make it looks as nice as the HTML. In the meantime, kudos to Rougier for implementing and sharing this with us.

Posted in General | Tagged , | Leave a comment

Input Methods

Mickey Petersen has another great post up at Mastering Emacs. In the post, Mickey notes that Emacs 29 is going to have first class support for emoji. I don’t use emoji much so I don’t care but Mickey’s post was still very interesting to me because he shows how to implement essentially the same functionality using an input method.

Input methods are a way of temporarily switching to a specialized keyboard so that you can enter special symbols or diacritical marks. I use the TeX input method all the time when I’m writing blog posts and find it an easy and convenient way of dealing with LaTeX symbols in a non-TeX buffer. Until I read Mickey’s post, I didn’t know much about input methods other than that the TeX method allowed me to enter LaTeX commands.

It turns out that it’s easy to implement an input method as Mickey shows by using it to make a simple emoji mode. He implements only four emoji but it’s easy to add as many as you like. The TL;DR is that you use quail-define-package to define the mode and quail-define-rules to establish the mappings between the key sequences and the symbols you want to insert.

The method is more powerful than I’ve described as you can see by reading the documentation but it’s simple in the simple case and worth knowing about in case you have need of such a facility.

Posted in General | Tagged | Leave a comment

Attaching Files to an Org Tree from Dired

Daniel Gopar offers up this gem on attaching Dired files to an Org-mode tree:

As explained in the documentation, you can attach the file under point in the Dired buffer and calling org-attach-dired-to-subtree or you can mark multiple files and call org-attach-dired-to-subtree to attach them all. The file or files get attached at the subtree the point is on in the Org buffer.

Posted in General | Tagged , | Leave a comment

What Could Go Wrong?

I feel like that guy in a toga and long white beard parading around with a “Repent” sign. I know I have as much chance of changing any minds as the repent guy does but I can’t help myself. If you’re using Google Drive, cut it out right now. If you don’t you’ll be sorry.

Google is, proudly no doubt, announcing a plan to scan Google Drive documents for objectional material and restrict or delete any they find. If, as you read the announcement, it seems reasonable to you, there are some questions you should be asking: First, what, exactly, constitutes “abuse” or violation of the “terms of service”? Is it possible that this would include having content that Google considers “misinformation”? If so, that’s a bit worrisome because, as one example, Google spent a whole year censoring as misinformation any content suggesting that COVID-19 had its genesis in a lab leak until, suddenly, that was an approved idea after all.

Let’s say you’re a recognized researcher with impeccable credentials in some scientific discipline. Do you really want a 25 year old liberal arts major judging the truth or value of your content? Because that’s exactly what you’re going to get if you try to share your research with Google documents.

Second, notice how proactive the plan is. It’s not merely, “If someone complains about some document, we will investigate and…”, it’s “we’re going to go looking for things to censor.” Is this an organization you want to entrust important work to? If this doesn’t bother and worry you then you’re beyond my or anyone else’s help.

You can expect to hear (even more) stories about serious, levelheaded people having their documents locked or deleted for some imagined affront against the commonweal. The chances are that if you wait 6 months, the censored content will be conventional wisdom.

Don’t do this to yourself. Find another way of sharing your documents.

Posted in General | Tagged | Leave a comment