Surround.el

That didn’t take long. After yesterday’s post on adapting Bozhidar Batsov’s delete-surrounding-pair function to handle Org markup, Batsov is back with a post on surround.el, a port of surround.vim from Michael Kleehammer. The point of delete-surrounding-pair was to (sort of) emulate Vim’s surround plugin. Now with support.el, there’s no longer a need for delete-surrounding-pair.

Surround does everything delete-surrounding-pair did and a lot more. You can delete surrounding pairs, add pairs, change pairs, mark or kill the content between the pairs, or even kill the text and the surrounding pair. It really is a splendid package and I’ve already added it to my configuration and deleted my adaption of delete-surrounding-pair.

Surround will check if the pair you’re operating on has different opening and closing characters and do the right thing automatically. The other nice thing is that there aren’t a lot of key sequences to remember. Once you pick a prefix that you’ll remember the (single) action keys are mnemonic and easy to remember. In any event, which-key pops up a reminder.

I installed it with the recommended prefix of Meta+ but keep wanting to invoke it with Hyper+ so I’ll probably change it but, regardless, I’m already enjoying using it.

Take a look at Batsov’s post or the Github repository for all the details. Batsov’s post has some recommendations on when you should use it and Kleehammer’s repository has information on shortcuts and auto mode, which you should read. This is a really useful package and I recommend that everyone take a look at it.

Posted in General | Tagged | Leave a comment

Delete Org Markup Pairs

The other day I wrote about Bozhidar Batsov’s post on deleting paired delimiters in Emacs and mentioned that he included a bit of Elisp that—sort of—duplicated the behavior of Vim’s surround.vim. The idea is that if you are in a delimited expression and invoke the function, it will ask what delimiter you want to delete and will delete the closest enclosing pair. That obviously has some shortcomings such as not recognizing if one of the delimiters is in, say, a string. Still it’s handy code that does the right thing in most cases.

The code was interesting but I thought I didn’t need it because delete-pair already handled all the cases I was concerned with. As I was writing about Batsov’s post, I had something like =some text= and realized that I didn’t want it displayed in monospace after all. Since delete-pair was on my mind, I tried it but of course it didn’t work because = isn’t a delimiter that delete-pair recognizes so I deleted them by hand.

Later, I realized that I could simply add the Org markup pairs I was interested in to Batsov’s code so I did that and added it to my init.el. It worked perfectly and now I have an easy way of deleting Org markup .

It’s worth noting that Org mode gives you a way to do the opposite too: if you highlight some text and call org-empasize (Ctrl+c Ctrl+x Ctrl+f) it will add the Org markup you choose to the highlighted text.

Note

After I wrote this post, I found out about surround.el. More about that tomorrow.

Posted in General | Tagged , | Leave a comment

Non Programmer Use Of Emacs

A recurrent theme here at Irreal is that Emacs is for everyone, not just programmers. Every time I find an example of this I try to write about it. It’s a point that Protesilaos Stavrou made in his recent FOSS @ Oxford talk.

Now, in a lovely piece of serendipity, we have Randy Ridenour providing a real world example. Ridenour is a Philosophy professor and, as he himself says, is by no means a programmer. Still, as Prot suggested, he has learned enough to automate some of his Emacs tasks. He started by copying other people’s code but tried to understand what it did.

Now he needs to convert quiz questions from one format to another for the learning management system that his university uses—see his post for the details. This amounts to running a series of regular expression replacements, which he did by hand for a while. Then he realized—as I always find myself doing—that he could just write a bit of Elisp to automate the process.

Ridenour isn’t a programmer and he isn’t a young turk who grew up with all this technology. He’s old enough to have a married daughter so while he may or may not qualify for the Irreal Geezer Club, he is obviously well along in his career. And yet he finds it easy to learn enough Elisp to reduce the friction in his workflow. His colleagues are probably still grumbling about how hard it is to deal with the quizzes but he’s turned all those problems over to Emacs.

Posted in General | Tagged | Leave a comment

Why You Should Use use-short-answers

A perennial problem for Emacs users are the yes/no prompts that require answering “yes” or “no” instead of just “y” or “n”. The usual solution—adopted by almost everyone—is to alias yes-or-no-p to y-or-n-p. Sometime around Emacs 28 or 29 the new variable use-short-answers was introduced as another way of solving the problem.

The last time I wrote about solving the yes-or-no-p problem, I said,

I’ve had my original aliasing code for at least 17 years and see no reason to change it. When use-short-answers was first introduced, I thought I should adopt it but I never did and as far as I can see, it doesn’t make any difference.

That statement was wrong in two ways. First, as related by Bozhidar Batsov, the alias trick doesn’t always work with native compilation because the call to yes-or-no-p may have been compiled before the alias is made. For that reason, use-short-answers is the better solution because it always work.

The second way it was wrong is that when I went to add use-short-answers to my init.el, I discovered that I had already done so, probably back in Emacs 29.

Posted in General | Tagged | Leave a comment

Removing Paired Delimiters In Emacs

Bozhidar Batsov has a nice post on delete-pair. It’s almost a case of the Baader-Meinhoff Phenomenon. Five months ago—before I wrote about it—I’d never heard of delete-pair and now it’s popping up on Batsov’s blog. Batsov, himself, doesn’t remember hearing about it before either.

For those who came in late, delete-pair does just what it says on the tin: delete the delimiter at point and its matching closing sibling. It’s actually quite flexible and usable in surprising ways as you can see from the_cecep’s original post that inspired mine.

The delete-pair command came to Batsov’s attention because it interacted poorly with his Neocaml package. That turned out to be because delete-pair makes assumptions that might not hold for languages with unusual syntax.

Batsov’s post is mostly a summary of what he found from researching the deletions of pairs in Emacs. For Lisp languages, all you need is paredit which has multiple ways of removing a delimiter pair. Probably the easiest is paredit-splice-sexp.

There’s also smartparens that also has several ways of removing a delimiter pair and has the advantage of working in all languages, not just Lisps. Batsov finds it too heavyweight for his needs but lots of folks swear by it.

Finally, there’s the builtin electric-pair-mode, which keeps delimiters balanced, pairs nicely with delete-pair, and is probably all most people need.

Take a look at Batsov’s post for more details and for a bit of Elisp that recreates Vim’s vim-surround. I was glad to see his post because I was right on the verge of forgetting delete-pair even though I’ve assigned it a keyboard shortcut.

Posted in General | Tagged | Leave a comment

Prot’s Video From His FOSS @ Oxford Talk

Just a quick post today to note that Protesilaos Stavrou (Prot) has published the video from his FOSS @ Oxford talk that I wrote about yesterday. Actually, he says that it’s a modified version of that talk so I don’t know if a video of the actual talk will appear or not.

In any event, the video tracked very well with the transcript that I wrote about in yesterday’s post. The video is a little easier to follow because you can see the changes to the text that he makes during his talk. If you’re the type of person that gets more out of a video than reading a transcript, be sure to take a look. The video is fairly long at 42 minutes, 40 seconds long so you’ll have to put some time aside for it but it’s definitely worth your while.

Posted in General | Tagged | Leave a comment

Prot On Emacs At FLOSS @ Oxford

Protesilaos Stavrou (Prot) recently gave a talk to the FOSS @ Oxford event on the power of Emacs and why he uses it. The video for the talk is not yet available but he does have the transcript that he used for delivering the presentation.

It was a nice talk that explained why Prot believes Emacs is a tool that everyone using a computer should be familiar with and make use of. The TL;DR is that Emacs is extensible and can integrate all the (text-based) tasks you need to perform on your computer. If, as a trivial example, you develop a color and font style that is pleasing to you, you need only implement it once: Emacs will use it for whatever tasks you like. Non trivially, you can arrange for various tasks to communicate with each other and share information if they need to.

Prot stresses a point that Irreal has often made: You don’t have to be a programmer to make good use of Emacs. Writers, teachers, liberal arts academics, and many others can and do leverage Emacs to make their work easier. Of course, if you know a bit of Elisp it’s even better because you can extend Emacs to do whatever you need. Prot himself is not a programmer but he taught himself Elisp and is now a significant contributor to Emacs.

The takeaway from Prot’s talk is that Emacs is all about freedom. Freedom to make whatever changes you like, freedom to explore the source code and see how Emacs does things, and freedom to share with others and learn from them.

Take a look at the transcript or wait for the video if you prefer visual presentations. In either case, it’s well worth your time.

Posted in General | Tagged | Leave a comment

Code Formatting With Emacs

Code formatters. Many people swear by them and always run their code through a formatter before checking it in. I’ve never seen the need for them. I have strong feelings about code format and I always write my code to that format: no need for a separate formatter. At the same time, I recognize that others have strong feelings about their preferred format so I never want to reformat someone else’s code.

There are, in every organization, control freaks who think it critically important that everyone’s code look the same. I’ve never accepted that premise and have ignored formatting guidelines. Somehow, I’ve always managed to get away with that minor recalcitrance.

Still, some people appear to like code formatters and for those people, Bozhidar Batsov has an interesting post on code formatters and how to use them in Emacs. It turns out that there’s a plethora of formatters with slightly different behavior to choose from

Happily the Lisp languages—which I use almost exclusively these days—don’t really need one since for a Lisp, code formatting is really just a matter of indentation, which Emacs handles on its own. Other languages need more work.

One of the problems with code formatters run from within Emacs is that they can freeze Emacs while they run. This is the case of formatters that run before the file is saved. There are formatters that run after the save by asynchronously reading the saved file, reformatting it, and writing it back to disk. This has the small defect that an unformatted file exists on disk for a short while.

Batsov’s post covers reformatters implementing both methods. Some of them allow extensive configuration of the reformatting rules. Others enforce a fixed format. Take a look at Batsov’s post for a really good rundown of all the possibilities.

Posted in General | Tagged | Leave a comment

Displaying Attached Image Files

Over at The Art of Not Asking Why, JTR has a nice post on attaching an image file to an Org file and displaying it inline. He begins by reviewing how to display an image file inline in an Org file and how to attach any file to an Org file. Most experienced Org users are familiar with all this. I used them just the other day to attach a delivery receipt for my tax papers to my accountant.

It’s the second half of his post that’s interesting. It turns out that when you attach a file to an Org file, the link to the attached file is added to org-stored-links just as if you had run org-store-link (bound to Ctrl+c l by default). That means you can insert the image in line by simply running org-insert-link (bound to Ctrl+c Ctrl+l by default) as usual.

Take a look at JTR’s post for all the details. If you often attach image files to an Org file and want to display them inline as well, this workflow is easy and efficient.

Posted in General | Tagged , | Leave a comment

Happy 53rd Birthday To Dark Side Of The Moon

As I do every year on this day, I want to wish Happy Birthday to Dark Side of the Moon, the best album of all time by the best rock band of all time, Pink Floyd. Of course, you’re free to disagree. I absolutely support your right to be wrong.

I used to feature a track from Dark Side of the Moon with each yearly post but I’ve run out of songs from that album so I’ve moved on to tracks from other Albums that I really like. This year’s track is Lost for Words from a rehearsal for the Pulse tour. If the video doesn’t appear on your screen, click on “Watch video on YouTube”.

I like this video for two reasons. First, you don’t usually see Gilmour playing a straight guitar but he brings the same amazing technique to it that he uses on his electric guitar. Second, these guys don’t mess around. Even though it’s a rehearsal for a song they’ve probably played hundreds of times, they treat it just like a live show complete with their signature light show.

I hope you enjoy the video as much as I do. In the meantime, join me in wishing a happy 53rd birthday to an iconic and enduring album.

Posted in General | Tagged | Leave a comment