Subword Mode

This should probably be a Red Meat Friday post but I really hate camel case. It’s hard to read, hard to type, and looks ugly. Among it’s many other sins, it has made abominations such as subword mode necessary.

Over at Emacs Elements there is a (very) short video on using subword mode. There’s not much to say. It’s a way of having forward-word skip to each capitalized segment of a camel case word. The video recommends enabling it via a hook function for whatever programming modes you use. You can, of course, toggle it manually by invoking Meta+x subword-mode.

Some people love this mode but—the awfulness of camel case notation aside—I’ve never seen the point of it. Yes, occasionally it’s convenient to have forward-word stop at each subword of a camel case identifier, but most often you want to treat the camel case word for what it is: a single symbol. In those rare cases (heh) where you want to put the cursor on one of the subwords, it’s easy enough to skip to the head of the composite symbol and move the point to the correct spot. Or you could use something easier like jump-char-forward. Regardless, it’s hard to see the utility of subword-mode.

Still, people differ in their needs and if this is something that’s useful for your workflow, Emacs, as usual, has you covered. The video is only two minutes, 25 seconds so you should be able to slip it in easily.

UPDATE [2023-09-01 Fri 12:39]: Mickey writes to tell me that I may have been too harsh on subword mode. What really happens when you invoke it is that the definition of a “word” is changed to encompass the subwords of SomethingLikeThis. That means that not just forward-word but any word-based command can stop and act on the subwords.

That makes it more useful than my original post suggested but I still think that usually you want to treat “SomethingLikeThis” as the single symbol that it is and subword mode is almost always overkill. As a real world, real time example, I misspelled SomethingLikeThis as SomethingLikrThis but rather than toggling on subword-mode and moving back to the error, I simply called jump-char-backward and went right to the error.

Posted in General | Tagged | Leave a comment

Editing In The Dired Buffer With Occur

I ran across this Toot—or whatever Mastodon calls it—in Sacha’s weekly Emacs News:

Even though it’s sort of old news at this point, it’s worth calling attention to. The idea is to use occur to narrow down the files in a Dired listing and then invoke the occur edit function to change the names of those files.

You can do the same thing from within Dired only but I like how the two-step process narrows down the files you’re concerned with and avoids errors. It’s a nice tip and worth taking a look at.

Posted in General | Tagged | Leave a comment

Red Meat Friday: Emacs vs. Vi

It’s a slow Friday here at Irreal so today’s offering barely qualifies as red meat but you may find it amusing. Someone posted this link to A Comparitive Study of VI and EMACS from the perspective of novice and regular users. It’s so old it was published as plain text. I expended a modest amount of effort trying to discover its publication date but couldn’t find anything.

What I find hilarious is that the study concludes Emacs is easier for new users than Vi. I’m guessing that that’s because of Vi’s modality. I don’t think it’s hard to achieve reasonable proficiency in either of them but I’d rank Emacs as slightly harder. Emacs partisans can cite this as further proof that it’s the one-true-editor but I doubt it was particularly dispositive even when it was published.

More in line with Irreal’s “let a thousand flowers bloom” philosophy regarding Emacs and Vi we have this post from TheWoodenPrince that speculates maybe Emacs and Vim can live happily ever after. We have, after all, the common enemy of bling infested hot new editors that we, the cognoscenti, know are inferior to both Vim and Emacs.

So there’s your red meat for the week. Enjoy the weekend and come back Monday ready to address the issues that really matter.

Posted in General | Tagged , | Leave a comment

The Downtown Apocalypse

If you’ve been around Irreal for a while, you know that I’m fascinated with remote work. I don’t understand why anyone wouldn’t embrace it but I realize that some don’t. Regardless, remote work is dug in and here to stay. A recent article in The Guardian notes that buildings in major U.S. cities are empty and business owners are facing a come to Jesus moment. Their employees are not coming back to the office no matter what they say and the smart money is making plans to adapt to the new reality.

Part of the pushback from the office-first folks is that you can’t run major projects without the principals having frequent face-to-face interaction. I’ve seen several posts and articles lately making this claim as if it’s indisputable. The thing is, we have several counter examples. Most of the open source movement is managed and thrives in a completely remote environment.

Since this is Irreal, let’s look at Emacs. The project, in its various guises has always been remote and has thrived that way for over 40 years. I don’t have any statistics but I doubt that more than a handful of Emacs developers have ever met in person. Rather, they debate and argue online. There’s no water cooler but there’s also no prattle about “How ‘bout them Yankees” or “Let me tell you about my date last night.” Sure, there’s some extraneous discussion but mostly it’s on point. Take a look at the Emacs-devel archives to see what I mean.

As much as the control freaks might wish otherwise, the days of everyone in the office all the time is over. Almost all of us are glad.

UPDATE [Added before publication]: CNBC Make It has an interesting article about the return to work movement. The TL;DR is that most executives who decreed workers must return to work now regret that decision and many have had to retract their demands. As with the Guardian article, a large factor is empty office space. It costs, CNBC Make It says, about $16,000 per employee per year for that office space so you can see why companies are loath to let it sit idle.

Posted in General | Tagged , | Leave a comment

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