Zamansky: Learning Elisp #8

Mike Zamansky has published the latest video in his Learning Elisp series, Learning Elisp 8. It’s the second video about building a function to generate function header comments. This video continues the discussion of regular expressions by considering the rx macro and the related xr package.

The rx macro allows you to write a regular expression with a more functional notation. The xr package is the inverse of rx: it translates a regular expression in normal notation to the corresponding rx notation.

Some feel the rx notation is easier to use and understand than the traditional regular expression notation. In fact, Pay08 in the reddit discussion of Learning Elisp 7 complained that Zamansky didn’t mention rx, which he considers a must for dealing with regular expressions. I’ve never been able to warm up to using the rx macro and agree with Zamansky that it’s probably not worth learning because it applies only when writing Elisp and not to any of the other languages or utilities that have regular expressions. Zamansky suggests that the xr package may be useful for understanding regular expressions written in traditional notation but I don’t find the rx notation any easier to digest; your mileage may vary.

Finally, Zamansky considers the format function, which, as he says, is pretty much the same of C’s printf. With this video, Zamansky has discussed everything he needs to begin building his function header function.

The video is just short of 20 minutes so plan accordingly. It’s a nice introduction to the rx macro and related xr package so you should take a look at it if you aren’t already familiar with them. Don’t let my and Zamansky’s skepticism sway you; you may like them.

Posted in General | Tagged | Leave a comment

A Tip On Reverting A Buffer

James Dyer has a quick tip that may be interest you. The issue is reverting buffers. There are several ways of doing this. One is to simply call find-alternate-file (Ctrl+x Ctrl+v). That’s what I always did but there’s the more specific revert-buffer (Super+u) that handles a few edge cases.

The problem with revert-buffer is that it asks for confirmation. If you’re calling it interactively you probably don’t want the confirmation. Dyer’s tip is to use revert-buffer-quick instead. It’s like revert-buffer but (usually) doesn’t ask for confirmation. Take a look at the online documentation to get the details.

Here’s another tip, this time from Irreal. If, like me, you usually call revert buffer for particular files or for a particular directory, you can set revert-without-query to inhibit the confirmation query for those files or directories.

In a sense, this is all small potatoes. Whether you need to confirm your intentions or not doesn’t matter much in the end but the thing about Emacs is that it does all it can to reduce friction in your workflow. It’s also a case study in why your mastery of Emacs is never complete. Both revert-buffer-quick and revert-wthout-query are obscure features that are hard to discover on your own but they’re there to help you even if they’re hard to find.

Posted in General | Tagged | Leave a comment

Development Tips Using Emacs

Isa Mert Gurbuz has an interesting post on some of the editing workflow he’s developed over the years for working with Emacs. The bulk of the post demonstrates some of the glue code he’s developed for working with various packages.

He starts with executing code in a buffer. You might want to execute the last s-expression, a defun that the cursor is in, a region, or even an entire buffer. You can do all that but each of them has a separate command. Gurbuz’s solution is to write a DWIM function that does the right thing depending on context. Nothing too unusual about that but he’s applied a bit of abstraction. The context remains the same for many languages other than Elisp but the particular functions vary. His idea is that his DWIM function doesn’t call any of these functions but returns a function that does. That way, he can supply the appropriate functions to call to his DWIM metafunction and get the actual function to call in return. He binds that directly to a key shortcuts so there’s no reason to even name the resulting function.

Next he considers eros as a way of showing an enhanced view of an expression, again in a DWIM way depending on context. He uses the same trick and metafunction as above to get a function appropriate to the language he’s using.

After that, he considers some functions from other languages like redshank from Common Lisp and clojure-thread-* from clojure-mode. Finally he considers various other supplementary functions and how he integrates them into his workflow to handle things like indentation and formatting. It’s a nice post with some good ideas. Definitely worth a few minutes to read.

Posted in General | Tagged | Leave a comment

Transient As A Hydra

Most every Magit user is, I’m sure, aware that the Magit menuing system has been refactored into a separate library, transient, that is available for anyone to use. I’m dimly aware that some Elisp projects—although I couldn’t name one off the top of my head—are already taking advantage of it. I just stumbled across a case of transient being leveraged in an individual user’s configuration.

Tory Anderson is using transient as a replacement for hydras. Emacs hydras are a package by abo-abo that provides a straightforward way to configure menuing systems in Elisp. They’re easy to set up with a simple description in your Elisp. You can take a look at Anderson’s post to see the code for one of his hydra replacements. I have a hydra that does essentially the same thing and the code looks almost identical.

To me, the interesting thing about Anderson’s post is not a particular hydra replacement nor the particular problem he’s solving but the idea of using transient instead of a hydra. I don’t see any advantage to using transient instead of a hydra and even Anderson says his efforts to replace hydras with transient are mainly a proof of concept. Still, it’s an interesting idea and shows how easy it is to take advantage of the transient library. Anderson has another post on transient and hydras if you’re interested in the idea. That post notes that the transient documentation is available in the Emacs help system as long as Magit is installed.

Posted in General | Tagged | Leave a comment

Emphasize Org Text With The Mouse

Here’s a short tip for those of you who are mouseketeers as well as Emacs users. As regular readers know, I eschew the mouse as much as I can but others disagree. It is, after all, a matter of taste so either preference is fine.

If you do like using the mouse, Ken Huang has a tip to share that you may find useful. He likes to emphasize his Org text (by putting it in bold) but he got tired of having to surround the text with a *. His solution was to advise mouse-set-region so that the highlighted text was automatically surrounded by the appropriate markup.

I do pretty much the same thing by using org-emphasize (bound to Ctrl+c Ctrl+x Ctrl+f) without using the mouse and it allows me to choose the markup.

Huang’s post is just another example of how Emacs lets you customize your workflow to what’s most appropriate to you. If you want to specify the markup for the marked text, it would be easy to call a function to specify the markup character rather than defaulting to *. You may or may not want his customization but it gives you an idea of how to adapt Emacs to your workflow.

Posted in General | Tagged , | Leave a comment

Red Meat Friday: Why Vim?

This is Irreal rising in defense of Vim. That may seem strange for an Emacs-centric blog but I’ve always said Vim and Emacs are the two best editors and which one you choose depends on whether you want a lightweight, very fast editor or a Lisp Machine-like environment that provides an entire operating environment. I like them both and have spent many years with each of them.

What I don’t like are those who have never put in the effort to master either editor spouting off about how they’re old technology and only fools and graybeards use them instead of the ever-so-great, bling bedecked, hot editor of the day.

As a case in point, nabeelalihashmi over at the programming reddit asks if there’s any reason to use Vim (or Neovim) other than to look cool. Let’s give nabeelalihashmi the benefit of the doubt and take his question as a serious one (if you follow the link, he does have a poll on possible reasons). Even with that concession, note that the question stems from unacknowledged ignorance. If he’d bothered to learn Vim at a nontrivial level (or even watched a few videos) he’d know the answer. People who do know Vim well may still choose to use VSCode or whatever but at least their decision is an informed one and they can probably easily explain the reasons for their choice.

You can see all three types of users in the comments. There are those who use Vim and explain why they use it in preference to other editors. There are those who don’t use Vim and explain why it doesn’t work for them. Then there are the ignorant who think that those who use Vim do so because they’re foolish or deluded. That third set offers no reasons for their opinions. How can they? They know nothing about the matter.

Posted in General | Tagged , , | Leave a comment

Zamansky: Learning Elisp #7

Mike Zamansky has posted the seventh episode of his Learning Elisp video series. In the last set of videos, he showed how to code a Rot13 function in Elisp. This video begins a new project: automatically producing function header comments. The idea is to parse a defun declaration and produce a comment listing the function name, its return value, and its parameters. After its generation, the cursor is left in a position for the programmer to provide more commentary on the various objects.

This video is an introduction to the problem and the main mechanism used to parse the function definition: regular expressions. The subject of regular expression is already difficult enough for most implementations such as the quasi-standard Perl regular expressions or even the Unix egrep regular expressions but Emacs regular expressions seem especially difficult.

The hardest part of Emacs regular expressions is understanding when and what special characters need to be escaped and even how many escape characters are needed. The problem is exacerbated because the rules are different if Emacs thinks it’s reading a string or a regular expression. Everyone hates them but despite several suggestions to improve them, they remain the same.

Zamansky spends most of this video explaining elementary Emacs regular expressions and how they can be used to identify complex patterns of text and perhaps replace them with something else. One example he shows is how to change a date in the mm/dd/yy or mm/dd/yyyy format to the dd-mm-yy or dd-mm-yyyy format.

It’s a nice introduction and makes the whole subject seem a little less intimidating. The video is a bit long—for Zamansky videos—at 29 minutes, 11 seconds so you’ll need to schedule time but it’s worth a look especially if you’re new to regular expressions.

Posted in General | Tagged | Leave a comment

Writing Prose In Emacs

Charles Choi has another great post; this time it’s on Tuning Emacs to Write Prose in Org and Markdown. The post is about how he configures Emacs for writing prose. I agree with roughly half his suggestions but this is a matter of taste and neither his nor my preferences are correct. They’re merely preferences and you should choose whatever works best for you.

His first suggestion is to use proportional fonts for prose. It’s easier, he says, to read and makes writing less distracting. I write all my posts and other prose in fixed width fonts but I’m willing to be convinced. It’s easy to add a binding to toggle a buffer between fixed and proportional fonts and I’ve done that so I can try writing with proportional fonts. You need merely toggle variable-pitch-mode to try this out for yourself. If you don’t like it, just toggle it back. If you become a convert add a hook as Choi recommends. I’m writing this post with variable-pitch-mode toggled on to see how I like it.

His second suggestion is to hide markup (things like surrounding text with stars to make it bold). I disagree with this. To me it seems to hide information. Of course I’ve been using one markup or another for over a quarter of a century so perhaps I’m just used to seeing it. Regardless, Emacs let’s you have it either way.

His next suggestion is to use flyspell, which I completely agree with. I was a bit confused by his suggestion to use company-mode to suggest alternate spellings. That’s built in for me and bound to Ctrl+;. Perhaps that’s because I use aspell rather than osx-dictionary.

Next he suggests using dabbrev-expand to complete the current word based on previous words in the buffer. I do this too but use hippie-expand, which basically tries to complete the word in all possible ways.

Choi suggests leveraging the menu system for various operations. I strongly disagree with this. One of my goals is to eliminate mouse actions completely. That’s easy in Emacs but recently I’ve been experimenting with ways to eliminate its use in the rest of my macOS interactions. I’ll write more about that later.

Finally, Choi suggest using visual-line-mode and some sort of word counting facility. I started using visual-line-mode to avoid hard line wraps in WordPress but like it and have started using it for all my (prose) writing. For line counting, I use the excellent wc-mode to give me a running count of words.

Choi also strongly suggests using Avy. Long time Irreal readers know that I’m completely on board with that.

This is a good post with lots of good ideas. You may agree or disagree with a particular suggestion but Choi is upfront with admitting these are his preferences and yours my differ. If you use Emacs for writing things other than code, you’ll want to check out this post.

Posted in General | Tagged , | Leave a comment

The Emacs Mark

I just stumbled across an Emacs Elements video from 9 months ago. It’s about the Emacs mark and how to use it. There are lots of videos about this and Irreal has commented on some of them but it’s one of those subjects that I, at least, have a hard time internalizing so it bears repeating for some of us.

One nice feature of the video is the use of visible-mark to display the placement of the two most recent marks. That helps a bit with the exposition.

The video starts with ways to set the mark and exchange it with the point. Most Emacsers know the basics of that but may not know that you can set an inactivated mark with Ctrl+Space Ctrl+Space. That’s useful if you want to set the mark but not specify a region.

Similary, Ctrl+x Ctrl+x activates the mark when it’s swapped with the point so the region between them is highlighted. If you don’t want that, simple specify Ctrl+u Ctrl+x Ctrl+x instead.

Next, the video considers ways to mark various objects: word, sentence, paragraph, buffer, function, s-expression, or page. These are useful for deleting, copying, or moving text.

Finally, the video considers ways of using the mark for navigation. You can set the mark at a particular location and return to it later by popping the mark with Ctrl+u Ctrl+Space. This is made more useful by the fact that Emacs sets the mark automatically for many large movement commands.

The video is 13 minutes, 26 seconds so you’ll need to schedule some time but not too much. If you’re like me and have a hard time internalizing these commands, it’s worth your time to watch it.

Posted in General | Tagged | Leave a comment

Plainorg Pricing

I’ve written about Álvaro Ramírez and his Emacs projects many times. He’s produced some impressive Emacs apps that many of us take advantage of. Like me, Ramírez is an Apple user and he has also written some iOS apps that that are similarly worthwhile. One of those is his wonderful *scratch* app that provides a sort of Emacs *scratch* buffer on an iOS device. My first thought was “why would I want this?” but I bought it on a whim and shortly thereafter life intervened to validate my choice. I’ve been a fan ever since.

Ramírez also has an iOS app, plainorg, that provides some elementary interaction with Emacs Org files. I haven’t installed it mostly out of inertia and dithering about whether I should choose it or one of the other iOS apps that offers to bring Org to my iPhone. Despite my indecision, plainrorg has been well received and users—in the way of users everywhere—are demanding new features.

That, of course, requires significant effort and Ramírez is wondering the what’s the best way to pay for that effort. Take a look at his reddit post to get an idea on what he sees as possible solutions. He considers a single one-time fee, a subscription plan, and several other ways.

In general, I prefer to pay for a lifetime license up front even if the cost is larger than a few years of a subscription. One commenter suggests a hybrid scheme where you can either subscribe or pay up front once and for all. One thing I don’t like is a one-time fee that devolves into a subscription plan. I view that as a bate and switch scheme and it always puts me off. Several of my important apps have done this and it always annoys me and starts me looking for alternatives.

In any event, if you fall into the intersection of Emacs and iOS users, vote in Ramírez’s poll to help him decide what to do.

Posted in General | Tagged , | Leave a comment