Emacs As a 2D CLI

Hongchao Liu has an interesting discussion about viewing Emacs as a two dimensional command line interface. He begins by arguing that Emacs does, in fact, adhere to the Unix principal of doing one thing well. That’s very counterintuitive but Liu says that if you view Emacs’ domain as text, then the one thing that it does well is to wrangle text. That’s not a new idea, of course; I wrote about it back in 2017 in connection with a post from ambrevar. Still, it’s a useful way of thinking about Emacs and its environment.

Liu’s other insight is that if you think about the normal Unix command line interface, it’s really about individual programs that have no knowledge of each other communicating through a text stream and they do this in a programming environment that we call the shell. That environment is inherently one dimension because the flow of data between the programs is basically a line of text.

With that in mind, Emacs can be viewed as a two dimensional command line interface. Rather than dealing with a line of text, Emacs deals with a two dimensional array of lines. In this case, the programming environment is Emacs rather than the shell. Liu uses the example of starting with a Magit commit log, jumping to a diff of the commit, and then to the actual source code of the program. As with the Unix pipeline, none of the programs know about each other and simply perform their work on the two dimensional array of lines that they are passed.

It’s an illuminating point of view and provides a neat answer to those who say Emacs is the anti-Unix. Take a look at Liu’s post. I think you’ll find it interesting.

Posted in General | Tagged | Leave a comment

Org Mode for Reproducible Research

Thibault Lestang of Oxford University has a very nice video that makes the case for using Emacs and, in particular, Org-mode for academic research. He’s very interested in reproducible research and his talk is centered around the idea of Org-mode making reproducible research easy and natural.

A significant, recurrent theme of the video is the importance of keeping your document consistent. In this, it reminds me of Mike Hamrick’s video on producing consistent documents with Org-mode. The ability to call a code block dynamically for a value means that you don’t have write hard values for results and this, in turn, helps keep your document consistent as the data or its analysis change.

Lestang gives a demonstration of using Org-mode in this way so it’s a good resource for those interested in finding effective tools for organizing and reporting their research. He admits, in fact, that the video is meant as evangelism for Emacs for those who may not come to it naturally.

The video is 33 minutes long so you’ll need to block out some time but it’s an interesting talk and well worth your while if you’re wondering whether it’s worth the effort to learn Emacs and Org-mode.

Posted in General | Tagged , | Leave a comment

Red Meat Friday: C++

It’s Christmas and it’s Friday so here’s a little gift from the Minions and me:

Posted in General | Tagged , | Leave a comment

This Is Tech Journalism II

A couple of weeks ago I made fun of tech journalism. It was an easy—some might even say a cheap—shot but Gizmodo brings this kind of ridicule on themselves. Sadly, besides the buffoonery, there’s actual malpractice going on.

Cellebrite is an Israeli company offering forensic software to law enforcement agencies. Recently, they published a blog post concerning their ability to extract information from Signal, a secure messaging app. The post was a little over the top and to their credit, Cellebrite replaced the post with a more moderate one.

That, however, did not stop the BBC and other “legitimate news sources” from publishing stories claiming that Cellebrite had cracked Signal’s encryption. Cellebrite’s post didn’t say that and it’s certainly not true. The true story is hardly worth telling. It’s like \(2+2=4\), film at 11. You can read that story at Signal’s Website.

Nobody with any brains takes news organizations specializing in Tech seriously. They are almost always wrong and appear to be more interested in clicks than news. But the BBC and organizations like Forbes, Bloomberg, the New York Times, and the others are supposed to be “real” news sources and yet they propagate the same sorts of nonsense. They shouldn’t wonder that anyone paying attention discounts everything they say.

Posted in General | Tagged | Leave a comment

Finding Pangrams in the NYT Spelling Bee Puzzle

From time to time I find a reference to a New York Times article in my feed. I had to register with the NYT to be able to read them and one side effect of that registration is that every morning I get a short news summary emailed to me. At the end of the summary, they always have the day’s Spelling Bee puzzle. You can read the exact rules at the link but the TL;DR is that you’re given 7 letters and have to make as many words as possible from them, possibly repeating letters. A word that contains all 7 letters is called a pangram and earns extra points.

Working the puzzle is an open ended process because you never know when you’ve found all the words. I don’t have the time for that but I do like to see if I can find the pangram. A quirk of my mental makeup makes me pretty good at it but sometimes I can’t find the answer. Naturally this caused the nerd in me to rise up and I started thinking about how I could automate the search. It turns out to be straightforward and easy so I’ll devote the rest of this post to showing how I did it with Elisp.

The basic idea is to start with a word list and assign each word a key. Then assign a key to the 7 letters in the same way and look for matches. For a word list, I used the dictionary word list that is part of every Unix/Linux distribution. The key is simply the unique letters of the word in alphabetical order. Here’s the Elisp to calculate it:

(defun bee--calc-key (word)
  "Derive a hash key from a word."
  (-> word
      (string-to-list)
      (sort #'<)
      (delete-consecutive-dups)
      concat))

The word is converted to a list of it’s letters, the list is sorted, the duplicate letters are deleted, and the remaining sorted letters are turned back into a string. If you’re not familiar with the thread first macro (->) see my post on threading macros.

Next, we have to read in the word list and massage it a bit:

(defun bee--get-word-list ()
  "Load the dictionary words as a lowercase list."
  (with-temp-buffer
    (insert-file-contents-literally "/usr/share/dict/words")
    (delete-consecutive-dups (mapcar #'downcase
                                     (split-string  (buffer-string))))))

To avoid ambiguities, we convert everything to lower case. This can cause some duplicates (a and A, for example) so we eliminate duplicates.

We do the “matching” with a hash table, of course. The next two functions build the hash table. The bee--build-hash function loops through the (massaged) word list and hashes each word by its key using the bee-hash-item function. The actual hashing is done by bee--hash-item. It retrieves the previous list of words with that key (possibly nil) and conses the new word onto it.

(defun bee--hash-item (word)
  "Add a single word to the hash."
  (let ((key (bee--calc-key word)))
    (puthash key (cons  word (gethash key bee--hash)) bee--hash)))

(setq bee--hash (make-hash-table :test #'equal))

(defun bee--build-hash ()
  "Add each dictionary word to the hash."
  (interactive)
  (mapcar #'bee--hash-item (bee--get-word-list)))

Finally, we ask for the 7 letters, turn them into a key, and query the hash table for matches:

(defun bee-solve (letters)
  "Find all the pangrams for the NYT Spelling Bee."
  (interactive "sLetters: ")
  (when (hash-table-empty-p bee--hash)
    (bee--build-hash))
  (-> letters
      (bee--calc-key)
      (gethash bee--hash)
      print))

Coda

When I first wrote this, I used delete-duplicates instead of delete-consecutive-dups. That makes a huge difference in run time because delete-duplicates doesn’t take advantage of the list being sorted so it has to do a lot of extra work. The original took between half an hour and a hour to run. With delete-consecutive-dups it takes about a second. I could probably eliminate even that latency by preprocessing the word list with something like

tr "A-Z" "a-z" </usr/share/dict/words | uniq

but I didn’t bother.

It would be pretty easy to turn this into a complete solution—finding all words that can be formed using the 7 letters not just the pangrams. All you’d need do is find the subsets of the 7 letters (the subsets of at least length 4 according to the rules) and call bee-solve on each of them. I’ll leave that as an exercise for the interested.

Posted in General | Tagged , | Leave a comment

Mastering Emacs is a Slow But Enjoyable Process

Over at Where parallels cross, Andrea has an interesting post that recounts his slow but enjoyable journey to Emacs mastery. Like many Emacsers, the journey began with his PhD studies. Since then he has learned more Emacs and integrated it into his life.

Andrea was able to reconstruct his journey because he archived all his Org TODO files in which he kept a day-to-day task list. His archives detail the troubles he had installing mu4e when Mozilla stopped supporting Thunderbird as well as other significant Emacs milestones.

Andrea makes a telling point about learning Emacs: it’s often depicted as a long and arduous slog not for any but the most strong. Andrea says, however, that while the journey will be long, there’s no hurry and the trip can be an enjoyable one. I’ve certainly found that to be the case. After almost a decade and a half, my journey is far from complete but I’ve had fun learning new things about Emacs and adopting new packages and processes into my workflow as my needs evolved.

It’s a nice post and worth a read if, like me, you enjoy personal Emacs stories.

Posted in General | Tagged , | Leave a comment

Emacs for the Humanities

Most of you know that I have a longstanding interest in the use of Emacs outside the programming/engineering fields. I’m strictly within those fields, of course, but it’s always seemed to me that Emacs has a lot to offer someone who isn’t: someone in the Liberal Arts or Humanities. And why not? If you are in the humanities, chances are your job involves a lot of writing and Emacs excels in wrangling text.

Despite what you hear folks who don’t know what they’re talking about say, out-of-the-box Emacs is an excellent editor and by adding a few packages to customize it for your typical writing tasks, it arguably becomes the best such editor. I know that I can write in Emacs faster than with any other application and I often get annoyed when I’m, say, texting and can’t edit or spell correct with my usual ease.

I’m not the only one who feels this way. Paul Rankin, a screenwriter and filmmaker from Australia—he’s also the author of fountain-mode, Olivetti, binder, and freeze-it—decided to do something about spreading the word. He pushed for and created a new GNU email list, emacs-humanities, dedicated to discussions of Emacs by or for those in the humanities. In the first post, Rankin lays out why he started the list and how he hopes it will evolve.

This is a great idea and will, I hope, bring the Emacs gospel to those who, while they may not have heard of Emacs, are in desperate need of it.

Posted in General | Tagged | Leave a comment

Emacs 27.1.90 Is Out

Emacs 27.2 is drawing nearer with the release of the first pretest, Emacs 27.1.90. Eli Zaretskii made the announcement on the emacs-devel list. If living a bit on the edge doesn’t bother you, Eli and the rest of the developers would be grateful for your help in testing.

A lot of folks like to download binaries but building Emacs really is simple even on macOS. Download the source and follow the instructions in the INSTALL file. See Eli’s emacs-devel post for where to get the tarball.

Posted in General | Tagged | Leave a comment

Org Spreadsheet Tutorial

Over at DjPj, pjs64 has a nice tutorial on using some of the spreadsheet properties of an Org tables. It’s one of the most powerful aspects of Org tables and I use it all the time. The trouble is, it can be a little difficult to figure out how to enter formulas so pjs64’s tutorial is really handy.

The tutorial considers only the mean function but there are, of course, many others. The problem is not the functions but their syntax and the tutorial covers that very well. One handy shortcut that pjs64 mentions is typing Ctrl+c ? in any field to see what its reference is. The usual Org notation is @row$col but you can also use the traditional spreadsheet notation where the columns are labeled A B C ... and the rows are numbered 1–\(n\) so that @3$2 is also B3.

The tutorial goes on to explain the difference between row and field formulas and how to specify them. It also explains the various ways of editing those formulas once they’ve been entered. Finally, there’s a short section on how to use Emacs Calc to to calculate the field values. To show how flexible this is, pjs64 makes the silly calculation of outputting the \(m^{\text{th}}\) digit of \(\pi\) based on the mean, \(m\), of the other columns.

It’s a useful tutorial and you should take a look if you use Org table even a little.

Posted in General | Tagged , | Leave a comment

The New Luddites Come for Our Spellcheckers

Well, not for our spellcheckers but, even worse, our children’s spellcheckers. It was inevitable, of course. The new Luddites will take aim at anything that makes our lives easier and wasn’t used down on the farm 150 years ago.

Meghan Moravcik Walbert over at Life Hacker is urging us to turn off our children’s spellcheckers. The reason she gives for this advice is the usual psychobabble about not stunting the kids’ writing by forcing them to concentrate on the mechanical aspects such as spelling. In other words, in writing intelligibly.

I’m coming to you not as some spelling prodigy who never suffered from the schizophrenic spelling rules and exceptions that is English but as a terrible speller who even in adulthood had to suffer the indignity of having his children correct his spelling. But my spelling has improved in the last few years and I bet you can guess why.

Yes, of course: spellcheckers. I’ve found that having immediate feedback when I misspelled a word helped me to learn the correct spelling and not make the same mistake next time. And it’s not just me. The very first comment by Litt, who appears to be an even worse speller than me, echoes the same sentiment.

Another comment opines that “Our kids wouldn’t learn from using spell check, they 100% would rely on it — just like they would if we fed them the answer every single time.” That’s just flat out wrong and, really, an insult to our children. They’re not trained puppies with a limited intellect capable of learning only a few tricks. They are in fact at the age where they are the most open to learning. You can allow them to continually misspell words so as not to bruise their egos or whatever the new Luddites are worried about but why let the bad habit set? Provide instantaneous feedback so that they can learn the correct spelling with as little effort as possible.

Posted in General | Tagged | Leave a comment