Elisp Specifics

Lots of Emacs users find Elisp intimidating. There are at least two aspects to this. First of all, it’s a Lisp. That means that everything looks different and, yes, there are a lot of parentheses. But this is only an apparent problem. The truth is that Lisp is syntactically simple and very easy to learn. The difficulty is learning its run-time library. Every Lisp has a large number of functions but even then it’s pretty easy to learn enough to start using Lisp.

The second problem is that Elisp—which is, after all, short for Emacs Lisp—is specialized for the Emacs environment. That means that it has lots of features that other Lisps don’t need such as buffer local variables. Even programmers familiar with other Lisps can find themselves at sea with Elisp.

Over at Positron’s Emacs Channel, there’s a very nice video, Elisp Idiosyncarsies, that explores some of the peculiarities of Emacs Lisp such as the aforementioned buffer local variables. The video is fast paced but mentions most of the Elisp specific things you need to know to use Elisp effectively. Of course, mastering those idiosyncrasies is going to take a bit more than watching a video but the video gives you an idea where the problems lay.

The video is just short of 17 minutes so you’ll need to schedule some time but if you want to understand Elisp—especially if you’re coming from some other Lisp—it’s a worthwhile introduction.

Posted in General | Tagged , | Leave a comment

MacAdie’s Frequent Org Commands

Eric MacAdie has an update to his previous post on his frequent Emacs commands. This post takes a look at his frequent Org mode commands.

As with Emacs proper, MacAdie has an idiosyncratic method of dealing with Org. Rather than use the key chord shortcuts, he does most things with the command names. It seemed to me that his discussion was the first time I’d ever seen the name of some of those commands.

The process seems to work for him so, of course, I have no objection to it. It’s just another way you can work with Emacs in a way that’s most comfortable to you.

The post itself is a useful introduction to Org. It’s often said that you shouldn’t try to learn all of Org out of the box. Rather, start by learning how to do a couple of things that are immediately useful to you. That’s pretty much the way MacAdie approached learning Org.

One nice thing about his post is that he discusses how to handle recurring events. You can specify that an event should appear in your agenda repeatedly every day/week/month/year but the control is actually a bit finer than that. Take a look at his post or the Org manual for the details.

My other takeaway from his post is that I’d much rather learn the key chord shortcuts than try to remember the actual commands.

Posted in General | Tagged , | Leave a comment

Avoiding Large Archive Files

Over at Free Range Bits, Peter Jones has a nice solution to the problem of large Org mode archive files. The idea of an archive file is that you can move a retired subtree of a file to an archive so that the original file doesn’t grow too large. Of course, this means that eventually the archive file will also grow large bringing the usual performance problems.

Jones’ idea is to save an archived subtree to the day’s journal file. In a sense this is the sweet spot. Yes, you’ll have many files holding the archived subtrees instead of one but those files exist anyway and since there’s a new one everyday, they never get very large.

Th mechanics of Jones’ solution is specific to his particular configuration, which uses the Org-roam journaling functionality. In particular, that functionality use a separate file for each day’s journal entries but any journaling system that uses separate daily files will work just as well. For that matter, any information store that uses daily (or weekly, monthly, or other short period) files is also a candidate but journal files seems especially appropriate.

Jones has a simple function that does the archiving for him by using the Org-roam functionality. It would be easy to roll your own depending on your specific setup. The important part is how to tie it into the Org archiving system, which Jones shows in his implementation.

If you use Org mode archiving, you should definitely take a look at Jones’ post. It has some good ideas.

Posted in General | Tagged , | Leave a comment

An Example Of A Emacs Keyboard Macro

Jeremy Friesen has an interesting example of using an Emacs keyboard macro. What makes it interesting is that the macro deals with three files, switching between them as needed. The problem he was solving, as I understand it, was to add certain metadata to two versions of a series of files. The third file held links to the entries in the other files.

There are two takeaways from the post for me. The first, most obviously, is using a keyboard macro to capture a routine but error prone process so it can be performed easily and without error. The macro is actually straightforward even though it is dealing with three files.

The second takeaway is a bit more controversial. This process is needed because Friesen publishes his blog with Hugo but writes his posts with Org mode. After writing them in Org he exports the Org file to markdown with Ox-Hugo and uses the markdown file for the actual publishing.

This, it seems to me, is a process begging for some refactoring. Believe me, I understand why he hasn’t done so. Long time readers will remember the many times I finally got around to fixing some overly complicated process in my own workflow and wondered in print why it took me so long.

At the very least, I would automate the Org mode → Hugo publishable file pipeline and keep only the Org file. A better solution is to find a publishing workflow that accepts Org files to begin with. I vaguely recall that someone (Mike Zamansky?) discovered a way to use Org files directly with Hugo. Even in the likely event that I’m misremembering, there are certainly other static site generators that accept Org files.

I’m confident that Friesen will eventually optimize this process just as I eventually get around to optimizing mine. In the mean time, his post is a good example of using keyboard macros to automate a tedious and error prone process.

UPDATE [2024-01-08 Mon 11:20]: Added link to Friesen’s post.

Posted in General | Tagged , | Leave a comment

Extracting Text From An Emacs Buffer

Rajasegar Chandran has an interesting and useful post on how to extract text from an Emacs buffer. You wouldn’t think there’s a lot to know but there are at least two wrinkles. First you might not want the whole buffer and second you (probably) don’t want to include the text properties.

Text properties are things like font faces that allow Emacs to display text as “rich text”. They’re really useful but if you want to work on just the underlying text, they can get in the way so, of course, Emacs gives you a way to omit them.

To deal with all this there are four functions that cover most of what you’d want to do.

buffer-substring
Extract a substring including its text properties from the buffer.
buffer-substring-no-properties
Like buffer-substring but strips the text properties.
buffer-string
Extract the entire buffer as a string. The text properties are included.
thing-at-point
Return the object that the point is on.

Most of these are self explanatory but thing-at-point is a bit richer. You can specify the type of object you want to extract such as a symbol, list, url, filename, email address, or many other object types. It’s sister function bounds-of-thing-at-point returns the start and end of the object. It’s really useful if you want to extract, say, a URL from the buffer.

These function are more useful than you might think. My init.el has several instances of buffer-substring-no-properties and thing-at-point just for my personal configuration. If you’re not familiar with them, take a look at Chandran’s post.

Posted in General | Tagged | Leave a comment

MacAdie’s Go To Emacs Commands

Eric MacAdie is probably familiar to many Irreal readers from his reports on the EmacsATX meetings. His latest post recounts his history with Emacs and includes a list of the Emacs commands that he got by with for most of his more than twenty years of using it.

Like a lot of Emacs users, he started out using only a tiny bit of Emacs’ power. It even sounds from his post as if he started Emacs every time he wanted to edit a file and then exited afterwards. Of course, judging from all the complaints one sees about Emacs startup time, folks are still doing this.

After his auspicious beginning with Emacs he changed jobs and became a Java developer. With that came a period of apostasy in which he defected to jEdit. Happily, he returned to the one true editor and is now active in the Emacs community.

The list of commands that he depended on for many years are pretty much what you’d expect. There’s the standard navigation commands, some window manipulation commands, and the simple search commands.

One thing that struck me is that he uses the Esc key method for Meta. In the old days some keyboards didn’t have an Alt key to serve as Meta so they used the Esc convention. Those days are long over but some people—even experienced Emacers like Mike Zamansky—still prefer it.

In any event, the post serves as another quick introduction to Emacs along with some reasons why you might want to try it out.

Posted in General | Tagged | Leave a comment

One Last Time With Marking The Active Window

I thought I was finished writing about marking the active Emacs window so that it stands out. It all started with my post on James Dyer’s method of placing a red line on the left hand fringe. I liked his solution but thought that simply coloring the mode line would be better.

Ignacio Paz Posse left a comment to that post showing that it was actually very easy to do. I immediately tried his solution and thought it was perfect. Since then, three new things have happened or come to light.

  1. Sacha Chua also implemented Posse’s solution. She chose a light blue (bg-blue-subtle) that looks nice but doesn’t stand out enough for my taste.
  2. I changed the color I was using from dark goldenrod to goldenrod. It still stands out but isn’t quite as dark and doesn’t swallow the non-black foreground colors as much. I also changed the attribute from mode-line to mode-line-active. I think I understand why just mode-line works but it’s nice to be precise when you can be.
  3. Dyer rewrote his code to fix a conflict with visual-fill-column-mode. That was easy so if you like the idea of marking the active window with a left red fringe. his post explaining the fix is here.

In any event, there’s no reason to live with the hard-to-discern gray/light-gray default. As far as I’m concerned, something more distinguishable should be the default but I can only imagine the uproar that would result if that default were changed.

Posted in General | Tagged | Leave a comment

A Paean To Emacs

Mario Jason Braganza over at Janusworx has what amounts to a love letter to Emacs. Three and a half years ago, he started using Emacs. His post is a list of “If you had told me then”. Some of them, such as using Emacs as his primary editor nearly everywhere, are obvious and conventional and could be said of any editor that a user has committed to.

Others, such as Emacs is not an editor but more like a whole computer with an editor bolted on, is much more specific to Emacs. He also notes that Emacs is not just for writing but can be used for tasks not related to writing such as using Org mode to organize his life and keeping what he calls his “commonplace book”.

He lists other, more complicated tasks as well but the point is the same: if you told him three and a half years ago that he would be doing these things with Emacs, he would have thought you were crazy. He ends his post with a wish for three and half more decades of the delights of Emacs.

Posted in General | Tagged | Leave a comment

Org Mode Island?

I ran across this post from Jeremy Friesen that was in response to another post by Jack Baty. The TL;DR is that Baty has been doing more and more of his writing in Org mode and this somehow makes him feel lonely as if he were trapped on an (org mode) island.

This got Friesen thinking about his own Org mode use and the bulk of his post is an explanation of how and why he uses Org for his writing. His conclusion is much like mine: all his writing starts out in Org mode and is exported to other formats or applications as needed.

I didn’t understand exactly what Baty was complaining about. It seems to me that using Org is the opposite of being on an island. Yes, you write in a single language—much as most people speak primarily in a single language—but you can export that writing to virtually any format you need. It’s more like being in a big city where you can get anything you want than being on an isolated island.

In response to Friesen’s post, Baty wrote a follow-up post in which he clarified what he meant by feeling isolated in Org mode. As far as I can tell, what it means is that it makes him feel trapped in Emacs because you can’t really use Org effectively anywhere else. Again, I don’t understand. If you don’t like Emacs, that makes a kind of sense but Baty says he loves Emacs. So what’s the problem?

My problem is actually the opposite. Every time I have to write something somewhere besides Emacs/Org-mode, I feel like I’m stranded in a strange land where nothing works as it should.

Posted in General | Tagged , | Leave a comment

Marking The Active Window Redux

Just the other day I wrote about James Dyer’s solution for marking the active window so that it’s immediately obvious which window has focus. In that post, I said that although Dyer’s solution was a good one, I thought that simply having the background color of the active window’s mode line something other than a slightly different shade of gray would work just as well and suit me better.

Ignacio Paz Posse to the rescue. In a comment to the post, he says that changing the background color of the mode line is exactly what he does and added a snippet of code to do just that. Since this is Emacs and since I was, of course, reading the email notification of his comment in it, I simple put the cursor at the end of the code snippet, typed Ctrl+x Ctrl+e, and just like that my active window’s mode line was dark goldenrod and stood out from the other windows.

The background color of my windows are a light tan (oldlace) so goldenrod was, serendipitously, just perfect. The code

(set-face-attribute 'mode-line nil
:foreground "black" :background "dark goldenrod" :box '(:line-width 1 :color "black"))

is simplicity itself. Because of Prot’s video, I assumed that even a simple change like that would be tricky but happily it’s straightforward. In any event, if you want a mode line that sticks out more than the standard dark gray, this is how to do it. You can adjust the color to fit your color scheme.

One more point worth mentioning is how easy it was to test this. As I said, I simply evaluated the code in the email and the changes took place immediately. That’s one of Emacs’ secret powers: if it’s Elisp and it’s in a buffer, you can execute it and see the results immediately without worrying about copying or other applications.

Posted in General | Tagged | Leave a comment