Simple Extensions in Emacs

Robert Johnson has a useful post on Everyday editor extensions in Emacs. Most Emacs n00bs and even many seasoned Emacers assume Elisp is too obscure and hard for “normal” users so they avoid it. Of course, that’s not true at all. As Johnson shows, it’s pretty easy to get started making simple extensions without having to know much about Elisp.

He demonstrates this by making a very simple Emacs function that simply opens the browser at some fixed site—github/spacemacs in his case. From there, he adds the ability to enter parameters, first by having the user enter them, then by using thing-at-point, and finally by using a prompt if thing-at-point fails.

At that point Johnson has a useful function that anyone could customize for their own workflow. Next he considers calling a shell command rather than the browser and having the results put in an Emacs buffer. That’s great, of course, because you can stay in Emacs and don’t have to switch out to the browser.

All of this uses only a minuscule fraction of the Elisp language, of course, but still manages to produce useful extensions. The important, unstated, advantage, though, is that once you get comfortable with this tiny portion of Elisp, it’s much easier to move on to the rest of the language. Developing even a minimal working knowledge of Elisp will open up a whole new dimension of Emacs to you.

Posted in General | Tagged | Leave a comment

Worst Practices

Although you may not have heard anything from Mike Zamansky lately, he’s still blogging—mostly about teaching—and maintaining an active presence on the Web. He just retired from Hunter so perhaps he’ll find time to enlighten us with a Using Emacs video or two.

In the meantime, he has an interesting post on the worst practices video channel. We’re always being inundated with videos pushing this or that best practice but Brett Slatkin has turned that on its head and presents us with a series of “worst practices” videos. That’s not as silly as it seems. For example, one video features Leah Culvert confessing that she often debugs with print statements. But wait. We all do that sometimes and it’s often, or at least occasionally, appropriate.

That’s the point. All of these Worst Practices are sometimes the right thing™. As Zamansky says, there are no silver bullets; no universal best practices that always apply. Yes, most often a debugger is the proper tool to use but sometimes a simple print statement or two does the same job more quickly and easily.

There are currently eight videos on the channel and they’re all things that

  1. are universally considered worst practices
  2. we all do occasionally.

The thing about the videos is how quotidian they are. All of these so called worst practices are things we all sometimes do and are probably better off for. In any event, the videos are entertaining and worth a few minutes of your time. They’re all about 5 minutes long so it’s easy to fit one or two in when you have an idle moment.

Posted in General | Tagged | Leave a comment

Warp Refactoring With Emacs

Ashton Wiersdorf has a very interesting post on refactoring in Emacs. His problem is a simple one: we wants to replace all occurrences of set_XXX_config! (where XXX varies) to config_XXX! for all files in a directory. He uses several packages to support this but the only one really necessary is wgrep, which make a search results buffer writable and saves the changes to it back to the original files.

His strategy is to

  1. grep for the appropriate regex,
  2. put the search results in a separate buffer
  3. make the buffer writable with wgrep
  4. use something like replace-regexp to change the identifiers
  5. save the results back to the original files

If you’ve been around Irreal for a while, this probably seems familiar. In abo-abo’s original post, he used rgrep so he didn’t need to worry about getting the results into another buffer but my process uses counsel-rg so I need a Ctrl+c Ctrl+o to move the results from the minibuffer to a separate buffer. After that, things are mostly the same. The nice thing is that Ivy handles all this for me and I don’t need any other packages besides wgrep.

This is a great way to refactor. The process, Wiersdorf says, is better than trying to do it from within an IDE using some sort of language server because it finds and changes all occurrences of the target identifiers including those in, say, documentation files that a language server is not going to find. It’s my favorite way of solving this problem. After you try it, it will probably become yours too.

Posted in General | Tagged | Leave a comment

Org Remark

If you’re the type of person who likes to annotate files but keep your notes external to the file itself, you may be interested in nobiot’s org-remark. There are a couple of videos [1, 2] that show how it works and some of the features. There’s also a user manual that describes its features and how to use them in detail.

The TL;DR is that you simply select some text and org-remark highlights it and opens a separate window in which you can make notes. You can also open existing notes corresponding to an already highlighted area. There are different colored “pens” available for highlighting text and you can define others if you need them.

All of this is demonstrated in the videos and explained in the users manual so take a look if you’re interested. I have no need for this capability but lots of people do. If you’re one of them, take at look org-remark. It’s available from the GNU ELPA repository or, if you’re adventurous, the GNU-devel ELPA repository for the development releases.

Posted in General | Tagged , | Leave a comment

PSA: Comment Notifications

I just discovered that, once again, Disqus has stopped sending me notifications when someone comments on an Irreal post. This happened before. For several months I got no notifications. Then, suddenly, mysteriously they started up again. I’m hoping it won’t be a matter of months this time.

In the meantime, I manually checked the last 4 months of posts so if anything you commented on requires a response, it should be there now. What I did last time and will do this time is check the last 20 posts for comments everyday.

I’m sorry that those of you who made a comment and expected a response and didn’t get it had to wait so long. I usually check for comments only once a day so it may be a day or two before you get any response.

Posted in Administrivia | Leave a comment

The Emacs Help System

Over at the Emacs Elements Channel there’s another useful video up. This time it’s about the Emacs Help system. The majority of experienced Emacs users will already be familiar with most of the material but if you’re a learn-as-you-go user, there may be some information new to you.

The first thing is that Ctrl+h Ctrl+h will show you a list of all the help commands. If you’re like me, you know this but always forget it when you’re trying to remember a help command. There are a lot more commands then the ones you use everyday so it’s worth your while to type Ctrl+h Ctrl+h to see what’s available.

For example, I’d completely forgotten about Ctrl+H w to discover the shortcut for a given command. My usual procedure is to bring up the documentation for the command and get the information there but I’m going to try to remember to use Ctrl+h w instead.

Another thing that I learned from the video is the difference between scrolling up and down with Space and Delete versus the <PgUp> and <PgDn> keys. I’ll let you watch the video to see what that difference is.

The video is 14 minutes 52 seconds long so it shouldn’t be too hard to find time but you may have to plan ahead.

Posted in General | Tagged | Leave a comment

PSA: Elisp Has Builtin Threading Macros

I’ve written about Clojure’s threading macros and their implementation in Elisp before [1, 2, 3, 4, 5]. I like them but almost always use the traditional composition of functions instead. That’s probably because being a mathematician it seems natural to me. Still, the threading macros are easier to read and understand.

Most people who care about such things know about Magnar Sveen’s implementation of these macros in his Dash library. They have the advantage of using the same names, ->, ->>, etc. as clojure. Of course, you have to install Dash to use them. That’s not much of a problem because so many packages use Dash that it’s probably already installed.

But what if you don’t want the dependency? It turns out that Elisp has the most important of these macros built in and has since at least Emacs 25. The first, thread-first corresponds to -> and the second, thread-last, corresponds to ->>. They live in the sub-x.el file if you want to check out there definition.

Ruslan Bekenev has a page that explains all this and even gives a short explanation of how to use the macros. If you’re interested in the threading macros, take a look at his post.

Posted in General | Tagged | Leave a comment

Elfeed-webkit Update

The other day I wrote about installing elfeed-webkit to render my RSS feed as proper HTML. I was pretty impressed with it when I first tried it and now I’m even more of a fan. Before elfeed-webkit, I spent a lot of time switching between Elfeed and Safari so that I could read interesting posts that came up in the feed. It doesn’t seem like it would take that much time but since the change, my RSS workflow seems faster and easier.

A secondary advantage is that Emacs has more functionality now that I have XWidgets enabled. At first I wondered if I could get eww to do a better job rendering sites by using Webkit. That turned out to be a bust but I did discover xwidget-webkit-broswse-url that will render a site in decent HTML but it’s not a proper Browser so it’s pretty much restricted to viewing a specific URL. You can follow links and control videos but there are no bookmarks, content filtering, or other Browser amenities. Still, it does help keep me in Emacs and a lot of times I just want to visit a page from Emacs and it works perfectly for that.

In my original post, I noted a couple of problems. The first was the possibility of being inundated with ads because of the lack of content filtering. That’s basically a nonissue for the sites I read although occasionally a feed item will send me off to a “commercial” site that does have a lot of intrusive pop-up adds but it doesn’t happen often.

The second problem was that I couldn’t get t to toggle elfeed-webkit on and off. I thought maybe something else was grabbing the t binding to I changed it to w but that didn’t work either. I solved that by binding a global key to toggle elfeed-webkit and that worked fine (but see below).

Finally, I recently upgraded my email client mu/mu4e and a helper function I wrote to display the post in eww stopped working. While investigating that, I discovered that mu4e will display an email with webkit, which is what I really want so I’m now using that instead of eww.

While investigating the email issue I discovered that the XWidget library does indeed capture the t key as well as the w key. The t doesn’t appear to do anything useful as its definition

(define-key map "t" (lambda () (interactive) (message "o"))) ;FIXME: ?!?

shows. I don’t know how it was working for Grabo; perhaps he’s using the Emacs 29 pretest and it has removed the useless binding. In any event, I simple changed my toggle key to x and now it works perfectly.

That leaves only one small problem. One of the sites I follow, Daring Fireball, has the unusual property that its RSS URL is not the site itself but the site it’s linking to. That means that I miss the Daring Fireball commentary and go straight to the linked site. I’m considering adding code to implement a tag that inhibits rather than enables elfeed-webkit. In the meantime, I’m simply toggling elfeed-webkit off when I get to a Daring Fireball post.

All in all, I’m really happy with elfeed-webkit and recommend it wholeheartedly.

Posted in General | Tagged | Leave a comment

Org Blk URI

Just a quickie. I stumbled across a post from Andrea that describes his package Org Blk URI. It’s pretty simple: it’s just a way of extracting the content at a URL into an Org source block.

That’s handy for capturing Web content that is apt to be ephemeral. The example Andrea gives is a job ad and, of course, we’ve all run across Web pages that might not remain available but that we’d like to retain. This package is a nice way of capturing them into an Org file that we control.

I haven’t installed yet but it seems like a handy tool to have.

Posted in General | Tagged , | Leave a comment

PDF at 30

PDF. It’s a ubiquitous standard that seems like it’s always been here. How else would you prepare a document that could be printed on virtually any printer or displayed on any screen in the best possible resolution?

But, it turns out, PDF is only 30 years old and even after its introduction, it took a long time to gain traction. When Rich Stevens published the first edition of Unix Network Programming in 1990, he hand carried the Troff output on a series of floppy disks to a typesetting service that printed camera ready copy for his publisher. Things got better. When I published my first book—also written with Troff—I simply emailed the PostScript files to the (same) publisher. By the time I completed my second book, the publisher said, “Just send us a PDF file.” Now PDF is the universal file format for producing human readable print quality output.

The incomparable Professor David Brailsford on Computerphile remembers the early days of PDF and how it completely changed his career. Even he, he says, underestimated how long it would take PDF to gain traction. Part of what moved things along was the introduction of laser printers that, although they didn’t provide the resolution of a traditional typesetter, were good enough.

Soon, of course, they were more than good enough, equaled the resolution of the old guard typesetters, and replaced them. These days, even industrial printers are laser based and all input comes to them as PDF. The ’P’ stands for “Portable” after all and it has more than lived up to its promise.

Posted in General | Tagged | Leave a comment