Using Hook Functions

Arialdo Martini has a nice post on how to configure and use Emacs hook functions. Most Emacs users have a general idea about hook functions but Martini goes into more detail, especially as concerns their use in major modes. The TL;DR is that when a major mode starts, it calls a series of functions called “hook functions”.

That may seem a bit esoteric and something that only very advanced users would want to do but Martini gives some everyday uses that make sense for any Emacs user. His post is a reasonably detailed explanation of how to use hook functions and is well worth reading. He includes information how to handle conflicts where more than one one mode in a major mode hierarchy add the same function.

One thing that Martini covers that I didn’t know about is how to walk the major mode hierarchy to find out what modes the current mode is derived from. You probably won’t ever need to do this but it is interesting and points to how to investigate problems with conflicting hook functions.

The post is apparently Martini’s interpretation of some lessons he took from Protesilaos Stavrou and the usual Prot excellence shines through. As I say, it’s well worth taking a look at the post to get a better idea of what’s going on with hook functions.

Posted in General | Tagged | Leave a comment

Happy 51st Birthday To Dark Side Of The Moon

It’s that time again. Every year on this day, Irreal suspends our normal blathering to celebrate the release of the best album of all time: Pink Floyd’s Dark Side of the Moon. There are rumors that the actual release date was March 1, 1973, but Irreal has always celebrated it on March 10th and sees no reason to change that tradition now.

Every year I provide a link to one of the songs from the album in the hope of introducing others to their extraordinary music. This year, I’m going to change things up a bit and feature a song from their 1987 album A Momentary Lapse of Reason. That song, On the Turning Away, is not my favorite Pink Floyd song but this video of them performing it is my favorite Pink Floyd video.

Here it is:

I like it because it showcases the unique talents of each of the band members. It begins with Rick Wright doing the keyboard introduction. You don’t often see extended shots of him playing. At 3:37 you see Nick Mason showing what a mondo drummer he really is. Then, of course, there’s David Gilmour whose virtuosity needs no comment from Irreal.

The best part of the video is the second half, which is entirely instrumental. I find it really powerful and always seem out of breath when it ends. On of my favorite parts of the second half is the under appreciated backup singers Machan Taylor, Durga MacBroom, and Rachel Fury. They’re always great but they really shine in this video. Sadly, the official released version didn’t include these clips but thanks to Obi Wan Kenobi we can enjoy them whenever we like. Watch the video. I hope you enjoy it as much as I do.

Posted in General | Tagged | Leave a comment

Essential Functions

If you’re an Emacs n00b—and despite the ankle biters claiming Emacs is dead, there are a lot of them—İsmail Efe Top has a post that you may find useful. The point of the post is to list some functions that Top finds essential for his work with Emacs.

If you’ve got any experience at all with Emacs, the list will seem unsurprising, obvious even. The list is:

  • view-echo-area-messages (bound to Ctrl+h e) that he uses to see ephemeral echo area messages. All the command does is display the ∗Messages∗ buffer but the binding is a useful shortcut.
  • describe-function and describe-variable. I think it’s safe to say that not a day goes by that I don’t use at least one of them. I’d guess they’re my most used aspect of the Help system.
  • ispell (for spelling correction). I use ispell in conjunction with flyspell to get immediate feedback on spelling errors and typos. Others—like Top, apparently—like to do the spell checking all at once after the writing, or some portion of it, is complete.
  • org-insert-structure-template (bound to Ctrl+c Ctrl+,) is another everyday function that those writing in Org mode simply couldn’t live without.
  • Finally, Top offers up his own version of a function to look up the word at point in Google.

As I say, all this is pretty elementary but if you’re just starting out it’s some really useful information.

Posted in General | Tagged | Leave a comment

A Defense of RSS

As most of you know, I’m a big fan of RSS and use it as my main way of discovering and reading content. It has plenty of detractors but the majority of those are people who are upset that RSS makes it hard to monetize and track content. RSS is perfect for those who just want access to quality content without a bunch of sketchy ads and tracking cookies.

Over at pcloadletter there’s a nice post that says RSS is still pretty great. It’s a spirited defense of RSS but takes an even handed look at the protocol’s good and bad points.

One of the criticisms of RSS that he considers fair is that it doesn’t allow content discovery. That hasn’t been my experience. I discover new content by subscribing to, for example, Hacker News and various subreddits covering areas I’m interested in. To be sure, there’s a bunch of noise but it’s easily ignored and I find new blogs and other resources that are worth following.

Another fair criticism is that RSS can’t render all types of content faithfully. That’s definitely not an issue for me because I use elfeed-webkit to automatically follow RSS entries to their source. Even if you’re using an inferior RSS reader, the point of RSS is to give you a summary of new content and provide a link to the source if you find it interesting.

The pcloadletter post also does a good job of covering what makes RSS a great protocol. Despite what Google and others with an axe to grind tell you, it’s an excellent—for some of us, the best—way of following and reading high value content.

Posted in General | Tagged | Leave a comment

Unified Context Switching

James Dyer has a really interesting post on how he used a bit of Elisp to solve one of his workflow problems. He’d recently abandoned his use of save=desktop in favor of recentf. His reasons for switching don’t really matter—although you can read them in his post—but after opting for recentf he wanted a way to switch to contexts other than files. He wanted to be able to switch to a recent file, a buffer, a bookmark, or a new theme.

All that’s possible out of the box, of course, but Dyer didn’t want to worry about separate keybindings for each of them; he wanted a unified selection method. It took a surprising small amount of Elisp to get this done. A single binding invokes a completing read with all the files, buffers, bookmarks, and themes as possibilities.

Dyer shows the code in his post. It’s amazingly straightforward. The only complicated thing is that he uses some of the more esoteric capabilities of completing read, many of which I didn’t know about.

Even if you’re not interested in building a unified context switching mechanism such as his, his code is worth studying for what it reveals about the features of completing read. It’s a lot more capable than you probably think. As usual, with Dyer’s post, it’s short and won’t take you long to read.

Posted in General | Tagged | Leave a comment

Executing All Babel Buffers

Over at the Emacs subreddit, justrajdeep asks an interesting question: If you have several Babel source blocks in an Org document, is there any way to execute all the blocks and get their data with a single command.

I often have this problem when I have a document with two or more Babel blocks and want to export it. On export, every to block will ask me if I want to execute it. It’s not a huge problem but it is a bit annoying. My go to solution is to set org-confirm-babel-evaluate to nil temporally. After a while, I wrote a function to handle this automatically.

Karthink to the rescue. There’s a command, org-babel-execute-buffer, to execute every Babel buffer in an Org file. If you run it, every Babel buffer in the Org file is executed. Unfortunately, it still asks for confirmation before executing each block.

That’s easily fixed with a bit of Elisp. Here’s some code I whipped up in less than a minute:

(defun jcs-execute-all-buffers ()
  (interactive)
  (let ((org-confirm-babel-evaluate nil))
    (org-babel-execute-buffer)))

That code will execute all Babel buffers in the file without asking for confirmation. If you just want an easy way of executing all the blocks at one time and don’t mind authorizing each execution, then org-babel-execute-buffer is all you need. If you don’t want to have to okay each block, a bit of Elisp such as the above is all you need.

Posted in General | Tagged , | Leave a comment

How Google Is Trying To Kill RSS

Irreal readers know that I’m a big fan of RSS and use it as my primary means of discovering interesting content. Happily, despite the efforts of the content aggregators in their never ending crusade to wall in and control all of the Internet’s content, RSS lives on and may, according to some, even be experiencing a comeback.

The worst culprit in the anti-RSS campaign is, of course, Google. It’s not hard to understand why. It’s crucial that access to content passes through Google so they can track and monetize it. RSS makes this difficult so Google used it to capture user bases and then killed their support for it. This includes much more than their infamous sunsetting of Google Reader.

The Open RSS organization has a post from last August that describes How Google has helped destroy RSS adoption. As I said above, it’s much more than just abandoning Google Reader. You can get all the details at the link. Google, it seems, has fully embraced Microsoft’s Embrace, Extent, and Extinguish tactics with regards to RSS.

In one sense, I’m insulated from all this because my RSS solution—the excellent Elfeed— is self contained and doesn’t depend on Google in any way. On the other hand, any RSS reader depends on sites providing an RSS feed. By convincing users that RSS is dead, Google has persuaded content providers not to bother providing an RSS feed.

It’s just another item in the long and sordid list of crimes Google has committed in their total abandonment of their early motto of “Don’t Be Evil”.

Posted in General | Tagged | Leave a comment

Handling Comments When Joining Lines

Tony Zorman has an interesting post on joining lines in the presence of comments. If you’re like me, your first reaction is apt to be, “why should I care about this?” After a second’s thought, though, I realized that joining lines is something I occasionally have to do when I start writing an Irreal post in the wrong directory where visual-line-mode does not get set. Once I realize my mistake, I want to move the text to the proper directory and join the lines in each paragraph.

It turns out, of course, that there’s an Emacs command for that: join-line. I’ve always solved the problem by setting the line length to a large value and reformatting the buffer. Using join-line is a much better solution.

For me, that’s the end of the story but Zorman wants to use join-line in programming buffers and it turns out that join-line doesn’t care about or do anything special for comments. That means that

;; Several comments
;; in a row
;; like this

gets concatenated into a single line, which is definitely not what you want.

The majority of Zorman’s post details his solution to this. For comments that start with a single character, the solution is easy. A simple advice-add does the trick. For languages like Lisp, though the solution is harder because the convention is to start whole line comments with two or more ; characters.

For that case, Zorman has to modify the source code of the function directly. The final solution covers all the cases that Zorman cares about and you may find it useful too. Take a look at his post for the details.

Posted in General | Tagged | Leave a comment

Running Magit In Full Screen Redux

Life goes on and things change. Over 10 years ago, I wrote about a hack to run Magit in full screen mode. The hack—apparently from Magnar Sveen originally—was pretty simple. Here it is:

(eval-after-load 'magit
  '(progn
     (defadvice magit-status (around magit-fullscreen activate)
       (window-configuration-to-register :magit-fullscreen)
       ad-do-it
       (delete-other-windows))

     (defadvice magit-mode-quit-window (after magit-restore-screen activate)
       (jump-to-register :magit-fullscreen))))

You can tell it’s old because it uses the now deprecated defadvice.

I just read a post from Jeremy Friesen that does the same thing but in a more modern way. It takes advantage of some variables specifically provided for this type of thing. Take a look at Friesen’s post for the details. The TL;DR is that it’s even shorter than my version and probably protected from going out of date. It’s a nice solution.

On the other hand, my solution is, in a sense, universally applicable. You can, as I have, use it, mutatis mutandis, in a variety of situations. I use it, for example, to run eshell in full screen mode. Once you understand how it works, it’s easy to apply to any situation where you want to run something in full screen, even if the function doesn’t provide a special mechanism for it.

Regardless, if you’re lookng for a way to fun Magit in full screen (actually, in full window) mode, take a look at Friesen’s post for any easy way of doing so. It’s a good post and it’s short so it will take no time at all to read.

Posted in General | Tagged | Leave a comment

Buffer Specific Commands

Remember the other day when I said I almost always learn something new from Bozhidar Batsov’s posts? I just ran across another example. Batsov informs us that as of Emacs 29, there’s a new command called execute-extended-command-for-buffer (bound to Meta+X) that’s like execute-extented-command (bound to Meta+x) except that the candidate commands are limited to those that make sense for the current buffer. That means commands specific to the current major mode, enabled minor mode, and commands bound to the local key map.

This is useful for those (almost everybody?) who have some sort of completion mechanism in place for the minibuffer. It’s especially useful for those who, like me, sometimes can’t remember the exact name of the command they want to run and depend on the completion mechanism to find it for them.

Meta+X is marginally harder to type than Meta+x but not enough to discourage its use. I suppose that if you find yourself using it all the time, it might make sense to switch the bindings but I doubt that’s necessary for most users.

Thanks again to Batsov for letting us know about this command.

Posted in General | Tagged | Leave a comment