More Batteries

Karthik Chikmagalur is back with another post in his Batteries Included with Emacs series. This post, More Batteries Included with Emacs, is the second and last of his posts on little known features of vanilla Emacs. His first post in the series lists commands some of which I knew about and use or some useful ones that I didn’t know about.

Many of the commands in his latest post are ones that I didn’t know about and probably wouldn’t want to use. For example, I have no interest at all in controlling Emacs with gestures. Who even knew you could do such a thing? When I’m in Emacs, which is most of the time, I stay away from the mouse entirely. Still, some may find it useful so take a look.

I also have no interest in having a speedbar although I know it’s a popular feature for many. I theoretically like the idea of the regular expression builder but hardly ever use it.

Chikmagalur lists several commands that sort of function like ido and Ivy but I’m a confirmed Ivy/Swapper/Counsel user so these hold no interest for me. If you’re trying to limit the number of packages you have installed, you may find their functionality useful as they do provide some completions—even fuzzy completions—that make invoking commands much easier.

He also reminded me of the extended rectangle commands that are part of the CUA mode. I used to use them all the time but fell out of the habit for some reason. Chikmagalur notes that they don’t play well with undo-tree so perhaps that’s why.

Chikmagalur’s post once again puts the lie to the often heard complaint that Emacs is unusable out-of-the-box. As he shows, there’s a lot of functionality there that even experienced users are not aware of. You should definitely take a look at both posts.

Posted in General | Tagged | Leave a comment

Unlimited Storage for Life

Irreal often posts about the absolute necessity to keep your data under your control. If you commit it to some “Internet service,” sooner or later it will become unavailable. The Stay Sassy blog has a very interesting post on why that is. The post considers unlimited storage and why it’s a Ponzi scheme.

The idea is simple. It costs money to provide that storage and the costs go on forever. Just as with the traditional Ponzi scheme, everything works just fine as long as the service offering the unlimited storage is growing. Stay Sassy says that’s because the services generally make their money when a new user adds their data. As an account ages, there is less new data from that user and therefore less income. As long as there are new users, everything is fine because they pay for the previous users’ storage.

But in the way of Ponzi schemes everywhere, the service eventually runs out of people wanting their service and everything comes tumbling down. At that point, they have to end the “free unlimited storage.”

Stay Sassy says that these services should offer to let users pay for additional storage as a way of keeping things going and, of course, being honest with their users. I know that I always prefer to pay for a service if I can for exactly these reasons. Free services are great but if you want them to stick around you better be willing to pay for them.

Posted in General | Tagged , | Leave a comment

Sorting with Regular Expressions

Tory Anderson has a nice use case for the sort-regexp-fields command. When I first saw his post I thought sort-regexp-fields was another new find for me. But on checking, I discovered that I had used in back in 2011 in an attempted solution to one of Xah Lee’s EmacsGolf challenges. Lee’s post has since disappeared but you can see the problem at the above link. Apparently sort-regexp-fields is one of those commands that I don’t use very often and tend to forget.

That’s too bad because, as Anderson shows, it can be very useful. It’s not even hard to use. You just need to remember that it exists. The basic idea is that you give the command two regular expressions. The first specifies the record—a line or paragraph, say—and the second matches the key in the record. Then the command sorts the records lexigraphically based on the key. That’s all there is to it. Simple but powerful.

Posted in General | Tagged | Leave a comment

Bozhidar Batsov’s Favorite Packages

We all have our favorite Emacs packages. I’ve written about mine a few times (1, 2, 3). A few packages make almost everyone’s list. There’s Magit and Org-mode, of course. Many people say at least one of those is the reason that they use Emacs. Another common favorite is which-key. If you’re not using it, you should be.

Bozhidar Batsov has his own favorites list. He limited himself to five packages but even so his list and mine have significant overlap. He also has an “Honorable Mentions” list that provides even more overlap.

Our biggest disagreement is on the Swiper/Counsel package. Oddly, he likes Ivy but uses Swiper and Counsel so seldom that he’s switched Ivy out for Selectrum, a lighter weight Ivy-like package that doesn’t include the Swiper and Counsel functionality. Outside of Org-mode, the Ivy/Swiper/Counsel package is my most important. I use it hundreds of times a day and my workflow absolutely depends on it.

Of course, that’s the fun of these lists: you get to see what other people think is important and maybe learn about a useful package you weren’t using. In any event, it’s always worthwhile listening to what Batsov thinks is important so take a look at his post if you haven’t already.

Posted in General | Tagged | Leave a comment

Threading Macros in Elisp

As I’ve mentioned in some recent posts, Mike Zamansky is making his annual pilgrimage to the Advent of Code Website to try his hand at the problems. This year—so far, at least—he’s been using Clojure to solve the problems.

I was really impressed by one of the Clojure features that he used in his solutions: the threading macros. I’m not a Clojure user but I can still experiment with the threading macros in Elisp thanks to Magnar Sveen’s excellent Dash library.

There are several threading macros, including some anaphoric forms, but the most useful, I think, are thread first (->) and thread last (->>). The others are a bit more complicated and seem more like party tricks to me.

They are, I think, particularly useful when doing interactive/exploratory programming. It’s easy to build up a calculation a part at a time by adding a new command to the bottom of the list. Still, it’s only slightly easier than adding the new command to the front of the sexpr. Where they really make things easier is in reading the finished code.

To see that, let’s examine a case of the thread first macro. Suppose we are given a list of integers and want to find the 3 largest, ignoring duplicates. One easy way of doing that is the sexpr

(last (delete-duplicates (sort '(3 1 7 5 3 4 2 1 4 7) #'<)) 3)

It’s a little confusing to read this ab initio or even to come back to it after a day or two. You have to read from the inside out and one of the arguments to the first operator in the sexpr (last) is at the end. Here’s the same calculation using ->.

(-> '(3 1 7 5 3 4 2 1 4 7)
    (sort #'<)
    (delete-duplicates)
    (last 3))
(4 5 7)

Notice how much easier it is to see what’s happening. Even if you don’t understand the -> macro, you can easily tell what the invocation does. You should check the docstring for the edge cases but basically what happens is that second argument of -> is used as the first argument of the third argument of ->. The result is used recursively as the second argument of the next invocation of -> and so on.

Here’s the results of a single expansion of ->.

(last
 (->
  (->
   '(3 1 7 5 3 4 2 1 4 7)
   (sort #'<))
  (delete-duplicates))
 3)

and here’s the full expansion.

(last
 (delete-duplicates
  (sort
   '(3 1 7 5 3 4 2 1 4 7)
   #'<))
 3)

As you can see, formatting aside it’s exactly what we started with.

The ->> macro is much the same except that the second argument is put at the end of the following sexpr. Again, see the docstring for the edge cases. Here’s a silly example. We multiply the first four positive integers by 5, add the results, and subtract the sum from 500.

(->> '(1 2 3 4)
     (mapcar (lambda (x) (* x 5)))
     (reduce #'+)
     (- 500))
450

Again, notice how easy it is to follow the action by reading from top to bottom.

As before, here’s the result of a single expansion of ->>

(- 500
   (->>
    (->>
     '(1 2 3 4)
     (mapcar
      (lambda
        (x)
        (* x 5))))
    (reduce #'+)))

and of the full expansion

(- 500
   (reduce #'+
           (mapcar
            #'(lambda
                (x)
                (* x 5))
            '(1 2 3 4))))

Obviously, you can get along just fine without the threading macros and some purists abhor them but I kind of like them. If you write Elisp, give them a try and see what you think.

Posted in General, Programming | Tagged , | Leave a comment

This Is Tech Journalism

Even casual readers know that Irreal holds a generally dim view of journalists. But this isn’t another post about their bias and ignorance of their subject matter. This is a post about silliness masquerading as serious journalism. It’s about writing stories that sound like a bunch of 8th grade boys giggling about a photograph of a woman in a bikini. Well, actually that last is probably unfair to 8th grade boys who are generally more mature and serious than this Gizmodo article.

As you probably know, Apple just announced the AirPods Max, a pricey, over-the-ears set of earphones. A reasonable argument can be made that they’re way too expensive but that’s not what the Gizmodo article was about. Rather, they chose to devote the article to the earphone’s case. The case is soft, which, I suppose, makes them slightly easier to pack and carry around.

The thing is, if you’re one of the sillier of those 8th grade boys the case may remind you of a bra. So if you’re a Gizmodo journalist, what else can you do but write a story entitled “I Thought It Was an Ugly Titty Purse” complete with an even sillier article illustration that looks like it was intended to appeal to those boys.

It’s generally accepted wisdom that the tech press doesn’t like the tech industry but if this represents their level of argument the industry has little to fear. The rest of us can continue cultivating the notion that they have nothing worthwhile to say and that they can be safely ignored with no FOMO.

Posted in General | Tagged , , | Leave a comment

The Social Life of Forests

With a couple of exceptions—like Dawkins’ /The Selfish Gene/—Biology has never held the fascination for me that many other subjects do. Nonetheless, I was drawn to The New York Times Magazine article, The Social Life of Forests. The TL;DR is that the trees in a forest have a way of communicating and even sharing nutrients with each other.

The article starts with the observation that after a forest has been clear cut and replanted, the saplings don’t to as well as expected. After all, they have more space, less competition, and more sunlight so it was surprising then they tended to die more often and generally be less healthy than the trees before the clearcutting. Suzanne Simard, a professor of forest ecology at the University of British Columbia, has a life-long love of forest and trees and set out to discover why this was so. What she discovered was astounding.

The trees in a forest are linked by fibers of fungus in what’s called a mycorrhizal network. These networks pass along chemical danger signals from one tree to the others but even more significantly they help distribute nutrients and carbon among the trees. The flow of these nutrients tend to be towards the trees that need it the most at the moment. It’s typical for the flow to change directions with the seasons as the needs of the trees change.

The article was fascinating for me and probably will be for most other nerds. It really is worth reading if only to discover how strange and counterintuitive the world can be. It’s also an inspiring story of how Simard persevered in the face of rejection of her ideas by the scientific establishment and became recognized as the leading expert in her field.

Posted in General | Tagged | Leave a comment

LaTeX vs. Word Redux

Hey, remember that silly opinion piece masquerading as a scientific paper by Knauff and Nejasmic back in 2014? It claimed that Word was much more efficient than LaTeX for writing papers. I wrote about it more than once (1, 2, 3, 4) at the time. At the risk of beating a dead horse, I just came upon some further (recent) commentary by D. J. Bernstein that seems to me to be on point.

Although he finds the paper weak on many grounds, Bernstein’s main point is that the study uses the wrong metric to measure the two systems’ efficiency. Putting aside the ludicrous notion of “realistic working conditions” used by Knauff and Nejasmic, Bernstein notes that writing the initial version of a paper is only the beginning of the document preparation process. As much or more efforts goes into revision and editing and that’s one of the places where LaTeX shines.

Bernstein begins his post with an anecdote about watching a couple of interns insert a new item into a numbered list. They did this by renumbering the following items by hand. One intern did the work, the other checked his results. That should make any Irreal reader hyperventilate. None of us, I’m sure, would do such a thing. After all, we use decent editors and typesetters that make such things easy. But the story is on point because this is exactly the type of thing that Knauff and Nejasmic ignore in their comparative study of the efficiency of Word and LaTeX.

It’s been over 6 years since I first wrote about this so it’s not too unreasonable to return for one further flogging but I hope that this is the last time that I or anyone else ever hears of this study. Except, perhaps, as a cautionary tale.

Posted in General | Tagged | Leave a comment

Phone Notifications When a Command Completes

Before we get to today’s topic, I want to point you to Mike Zamansky’s latest video on using Clojure for Advent of Code problems. Emacs appears, of course, although it’s not really the point of the video. Even so, I like and am enjoying these videos and if you admire his Emacs videos, you probably will too. Still, I don’t want to keep stepping on his videos so I’ll just note that it’s there and that you should take a look.

Now on to getting a phone notification when a command completes. Over at Medium (I know, I know) c0d3x27 has a post that shows how easy it is to arrange for such notifications using free software that you probably already have. You’ll have to set up a Telegram account and Pip install the Python Ntfy library. The post has step-by-step instructions for setting things up. There’s no real coding so it really is an almost trivial operation.

This is mostly useful for long running commands, of course, but the same idea could be easily modified for other uses. In any event, if you’re looking for a way of being notified by phone when certain events take place, take a look at c0d3x27’s post.

Posted in General | Tagged , | Leave a comment

Zamansky: More Advent of Code and Clojure

If you enjoyed yesterday’s post on Mike Zamansky’s use of Clojure and Cider to solve an Advent of Code problem, he has a couple more offerings that you’ll probably like too. Like his last video, these two consider a current Advent of Code problem and apply Clojure and Cider to their solution.

If you don’t like Clojure, the first post above also considers the Python solution in the text but not the video. I don’t know any Clojure but it’s a Lisp and familiar enough that I had no problem following along. Even if you’re a complete Lisp n00b, Zamansky’s last 3 videos do a good job introducing some of the syntax and concepts.

As with yesterday’s post, these two approach the problems in an interactive or exploratory way. You can watch Zamansky build up the solution piece by piece and even do a bit of debugging when he gets stuck at one point.

I’ve always found the fact that Clojure is hosted on the JVM off-putting because of security and resource hog concerns. Still, I really enjoyed Zamansky’s videos and felt, despite my misgivings, an urge to try it out. Perhaps I will. Clojure is a far better way of dealing with the Java environment than Java itself.

Posted in General | Tagged | Leave a comment