Downcasing Every Occurrence of a Word in a Buffer

Marcin Borkowski (mbork) has an instructive post based on a question in the emacs-humanities mailing list. The question that Borkowski addresses is how to replace every occurrence of a word in a buffer with its downcased version without typing the word twice. Borkowski solves this problem by writing a bit of Elisp.

In a sense, his solution is silly—as even he admits—because there are pretty easy ways of doing this with built-in commands as a couple of the respondents replied. Still, Borkowski’s solution serves as a nice example of writing a bit of Elisp to solve a simple problem.

As usual, Borkowski shows us the scaffolding. By that I mean that he doesn’t just show us a solution but the steps—and missteps—he took arriving at it. That’s why it’s an instructive post. The main thing you learn from the post is how to search through a buffer for a given regex and replace it with something else. That’s basically the interactive query-replace-regexp but you’re not supposed to call that directly from Elisp for various reasons.

Borkowski gives us the template for this sort of operation and makes it obvious how to change the operation on the target or add other steps. It’s a nice post and worth reading even if you’re already conversant with Elisp.

Posted in General | Tagged | Leave a comment

Emacs Eye Candy

Because Álvaro Ramírez has been building so many useful packages and applications lately, I’ve been writing about him a lot. I’ve always thought his Emacs theme looked nice despite the fact that it’s a dark theme. The minions, of course, are tut tutting about this and demanding that the heathens be cast out but I’m more sanguine.

Although I still much prefer a light theme, it’s nonetheless true that his theme has good contrast and is readable unlike many dark themes. Now you can see this for yourself. Ramírez has posted My Emacs eye candy, which describes his Emacs theme and its configuration.

He uses the Material theme but has made many custom tweaks to it. If you must use a dark theme and don’t mind constant hectoring from the minions, his example is a good one to follow. He uses the JetBrains Mono typeface. It’s nice looking and distinguishes between zero and oh; ell, one, and eye; and comma and period. I’ve been using the inconsolata font for at least 15 years and have been very happy with it but either is a good choice.

He has many other small customizations including the execrable (sorry) Nyan Cat, tweaks to the minibuffer, the Welcome screen, and a few others. Again, if you’re looking for a nice Emacs configuration using a dark theme, Ramírez’s is a good place to start. Or you could abandon the dark side and come back to truth, light, and goodness.

Posted in General | Tagged | Leave a comment

Indexing Your Init File

James Dyer has a useful short post on indexing his init.el file. His scheme is simple. His init.el is broken into sections each of which starts with

;;
;; -> Section-name
;;

Then he used occur to generate the actual index. Rather than call occur each time with the need to provide the regex, he wrote a 4-line function that does it for him. He doesn’t say whether he bound it to a key sequence but that, of course, is trivial.

One of the commenters suggested using imenu. That’s would have the advantage of having the results show up in the echo area rather than a separate buffer but it’s not clear that that’s the right thing. You might want to visit more than one section, in which case having a (semi) persistent index is a win.

Regardless, using imenu instead would be an easy change, especially if you’re using counsel-imenu. For simplicity, though, it would be hard to beat Dyer’s short function using occur. The nice thing is that with either solution you don’t need to install anything (other than a short function): everything you need is already there.

Posted in General | Tagged | Leave a comment

The Dictionary Package

Bozhidar Batsov over at Emacs Redux has a nice post on looking up words in a dictionary with Emacs. The post is about the dictionary.el package that’s built into Emacs as of version 28. Dictionary is a package for talking to a dictionary server and provides a way to look up words in any of several dictionaries.

In Batsov’s case he only interested in being able to lookup the word at point so he’s bound dictionary-lookup-definition to Ctrl+c l to easily look up a word but the package can do a lot more as a glance at its GitHub page shows.

I prefer to use abo-abo’s define-word package for routine word lookups because it lists the results in the echo area rather than opening another buffer. I do use dictionary.el, though, for access to Webster’s 1913 dictionary. It’s really convenient because you don’t have to install anything to use it.

As Batsov explains, you can have local a local dictionary server and dictionaries or you can use the online dict.org. Since I virtually always have connectivity1, I just use dict.org but the choice is up to you. You can also use any other dictionary server—local or remote—that you have access to.

If you use Emacs for more than just editing code, the ability to quickly and easily look up the definition of a word is a real benefit. And, as I said, it’s already there waiting to be used.

Footnotes:

1

Yesterday notwithstanding.

Posted in General | Tagged | Leave a comment

Outage

Sorry folks. The Irreal International Headquarters and its neighbors have been without Internet access all day. It just came partially back so I’ve decided to push today’s post to tomorrow and get this notice out while I still can.

Posted in Administrivia | Leave a comment

A Clean Writing Environment

Dhavan Vaidya has an interesting post on a clean writing environment. It’s his idea of the ideal writing milieu. What strikes me about his post is that his idea of the best writing setup is completely different from mine. About the only thing we agree on is that it’s Emacs based.

For example, Vaidya is very concerned about what his text looks like while’s he writing it. I care very much what the final product looks like but have no real interest in what it looks like while I’m writing it. I’m happy with plain, monospaced text and don’t bother hiding the Org markup. I don’t worry about fonts or any other WYSIWYG features. That’s probably because before I used Org mode, I wrote everything using troff and got used to writing in a monospaced font and mixing in markup. As Andrew Tannenbaum said about why he used Troff,

I don’t have any need to see what the output will look like. I am quite convinced that troff will follow my instructions dutifully.

The disparity in Vaidya’s and my preferred work flows is actually good because it shows, once again, how flexible Emacs is. No matter what writing environment you prefer, Emacs is able to give it to you. Neither his nor mine is better; they’re just what we, as individuals, prefer. The important thing is that Emacs lets us have it.

Posted in General | Tagged , | Leave a comment

Emacs Progress: Version 29 Pretest

Eli Zaretskii (did I mention he won an FSF award for his contributions to Free Software) writes to tell us that the first pretest for Emacs 29.1 has been released. The final release of Emacs 29.1 is still some time away, of course, but this is good news: it tells us that the process is advancing nicely.

As I always say, thanks so much to Eli and the rest of the developers who work so hard to keep Emacs the best editor in the world. If you run across Eli or any of the others, be sure to buy them a beer. In the meantime, if you don’t mind living on the edge, run the pretest and report any problems you find.

Posted in General | Tagged | Leave a comment

Improving IELM

If you’ve been around Emacs long enough to learn some Elisp, you probably know about IELM, the Inferior Emacs Lisp Mode. It provides an Elisp REPL that is often easier to use than evaluating separate Elisp statements. It’s one of those things that I don’t use all that often but can be very handy when you want to make extended Elisp calculations.

Nicolas Martyanoff also likes IELM but considers it to be too rudimentary so he set out to improve things. There were three things that he wanted to improve:

  1. He wanted to enable Eldoc in the IELM buffer.
  2. He wanted to enable Paredit.
  3. He wanted to enable persistent command history.

The first two were simple, merely a matter of adding a function call to the two appropriate hooks. There was a small wrinkle with the second but it was easily resolved. The third was a little harder and required writing some code and advising the IELM input function. Even so, the total amount of code is minimal and easily added to your init.el.

He also adds a couple of useful keybindings. Take a look at Martyanoff’s post for the details. If you use IELM and would like the usual Lisp amenities, Martyanoff’s changes are a good place to start.

Posted in General | Tagged | Leave a comment

Beating The House At Roulette

This post isn’t strictly within the purview of Irreal but I think it will appeal to the nerd in all of us. Most of you know that a perfect roulette wheel produces completely random results but, of course, no wheel is perfect. No matter how well manufactured, wear and environmental conditions collude to ensure nonrandom behavior and that nonrandomness provides an opportunity for a player to change the odds in their favor.

Years ago, I read The Eudaemonic Pie, an account of an early attempt to smuggle a small, homemade, specialized computer into a casino. The computer’s job was calculate the trajectory of the roulette ball and predict which third of the wheel it would end up in. It turns out that that wasn’t the first attempt at such a thing. Physicist Edward Thorp and Claude Shannon(!) did the same thing in the 1960s but, like the Eudaemons, they had trouble keeping their homegrown computer operating in the less than idea conditions of a casino.

A recent Bloomberg’s Businessweek article picks up the story in 2004 with an account of Niko Tosa and his successful war against the odds at the roulette table. Tosa and his associates would go into a casino, play the roulette wheel, and walk away with a bunch of casino money. The casinos, of course, have no sense of humor at all about this sort of thing and did everything they could to catch Tosa and his colleagues cheating. They even brought in the police who searched them for computers or other devices but could find nothing.

To this day it’s still not known how they did it. The casinos responded by barring Tosa but he still tries to get in—usually unsuccessfully—by wearing disguises. It’s a story that I’m sure will appeal to your innernerd. It’s not just the technical details but the whole idea of a ragtag bunch of guys hacking the man.

Posted in General | Tagged | Leave a comment

Emacs Docs

Ghislain Vieilledent reminds us of a useful Website for Emacs documentation:

Even though I’m familiar with the site, I’ve never used it. That’s because I have all the documentation that it points to already bookmarked and I just automatically go to the appropriate bookmark when I need one of the manuals.

Still, I can understand how some folks would prefer a single site that links to the most used documentation. The site itself, emacsdocs.org, is easy to remember so you probably wouldn’t even need to bookmark it.

I have a set of cascading Doc menus on my Safari Favorites Bar that holds links to all the documentation that I use even occasionally. One of the submenus is for Emacs that contains links to all the Emacs documentation and cheat sheets. That works well for me but if you want a site with links to the most important Emacs related manuals, take a look at emacsdocs.org.

Posted in General | Tagged | Leave a comment