Emacs Text Sorting

Susam Pal has an excellent post on sorting text in Emacs. Most experienced Emacers have probably seen most of the methods he talks about but unless you use them all the time, it’s easy to forget them. This post is a nice reminder and a useful summary that’s worth saving for future reference.

He starts with the simplest case of merely doing an alphabetical sort of the lines in a region with the sort-lines command. Specifying the universal argument does a reverse sort. This single covers a lot of the cases you actually run across but, of course, there’s more.

If your data is vaguely table-like, you may want to sort the lines based on a particular column. The sort-fields command handles this case for alphabetical columns and the related sort-numeric-fields take care of the case where the data in the column is numeric. That makes sure that 20 sorts before 100. In all these cases, it’s probably easier to call reverse-region after a normal sort if you want a reverse sort.

Next, he considers sorting on multiple adjacent columns with sort-columns. In this case, it make sense to specify the universal argument if you want a reverse sort. From there he moves on to the slightly more general case of using a regular expression to specify the sort key with sort-regexp-fields. There are snares for the unwary with this command so be sure to read his two examples carefully.

Finally, he shows how to export the region to an external sort routine. If you’re familiar with the Unix sort command this can sometimes be easier than trying to remember the specific Emacs commands.

As I say, this is a really nice post and well worth your attention.

Posted in General | Tagged | Leave a comment

Mickey On What’s New In Emacs 29.1

Many—probably most—of you have upgraded to Emacs 29.1 by now. If you’re like me you have a basic idea of what’s changed but don’t wait to read the NEWS file before installing the update. Who can blame us? It’s long and detailed and much of it concerns things we don’t use and know nothing about.

My usual procedure is to install the update and then read Mickey’s article on what’s new. The odd thing is that the article, which he publishes for every major update, is always just an exegesis of the NEWS file but his commentary and helpful explanation of what some of the more esoteric changes mean makes reading it easier and less onerous than reading the plain NEWS file.

Even so, I find it hard to read through the whole thing it just one sitting. There’s just so much to absorb. None-the-less it’s very worthwhile taking the time to read it. If you’re like me, much of it won’t affect you much but buried in all those changes are some items that will very much affect you and that you definitely will want to know about. Often they’re small changes that you might not read about in the technical press or other online commentary but that are important to your workflow. If you don’t spend the effort to read through the NEWS file, you might never learn about them. Fortunately, Mickey’s articles make it a bit easier to do that.

Posted in General | Tagged | Leave a comment

Red Meat Friday: Learning The Emacs Way

It’s easy to be annoyed at N00bs who complain that it’s sooo hard to configure Emacs into a state useful for working with X. Sometimes, a new user will, like domsch1988, try and fail repeatedly to bend Emacs into a useful tool for their workflow. Domsch1988, to his credit, kept at it and finally succeeded. The secret, he says, is to accept Emacs for what it is and not try to make it into whatever editor you’re used to.

Domsch1988 finally realized this after several attempt to use Emacs. He tried Spacemacs, he tried Doom, and he tried vanilla Emacs but it just wouldn’t take. Finally, he realized that the problem was that he was trying to make Emacs into VSCode or Neovim rather than embrace the Emacs way of doing things. Once he accepted that, he started with a plain Emacs and only added packages when he needed a missing functionality. No more explorer sidebar just because VSCode has one. He discovered that projectile-find-file was enough and had the benefit of not wasting screen real estate.

His main problem was that Magit was slow but that was because he was on Windows, which for various reasons explained in the comments makes Magit slow. A couple of commenters noted that the built-in VC subsystem is fast on Windows and a good alternative.

Domsch1988 showed that a lot of the complaints about Emacs being hard to use really boils down to trying the keep the habits from previous editors, not Emacs. It’s a good post and worth a couple of minutes to read.

Posted in General | Tagged , | Leave a comment

Sqlite Mode

There was a time when I had a rudimentary proficiency with SQL. I could make updates and rudimentary queries but those days are gone. I haven’t had the need to interact with an SQL database for several years so what facility I had with them has evaporated.

Fortunately, as always, Emacs has my back. The new Emacs 29 has a builtin sqlite mode that can read SQLite databases, list the tables, the rows of a given table, and even delete a row of one of those tables. Álvaro Ramírez has a short post that demonstrates these elementary facilities.

Of course, being Ramírez, he decided to extend those facilities. His changes, for the time being, are fairly minimal. He added the ability to tab (forward and backward) through the fields and the ability to edit the row fields themselves. A second post demonstrates these new abilities. The code, Ramírez says, is still a little hacky but seems to work well.

Sqlite mode, especially with Ramírez’s additions is perfect for someone like me who’s rusty on the mechanics of dealing with SQL databases. It doesn’t, of course, replace a thorough knowledge of SQL but it does give us SQL duffers the ability to perform elementary operations on an SQLite database.

Given that more and more applications—including Emacs—are integrating SQLite, this is a boon for those of us who like to live in Emacs. Take a look at Ramírez’s videos to see what’s possible.

Posted in General | Tagged | Leave a comment

An Example of Mode Line Customization

The other day I wrote about Protesilaos Stavrou’s video on customization the Emacs mode line. James Dyer saw the video too was inspired to make his own customizations. There’s nothing unusual about that, of course, but I was struck by how easy it was for him to build his own minimal mode line.

Dyer has distilled the complicated information from Prot’s video into a sort of minimal effective use case. His mode line is very simple and shows the buffer name only for the active window. I’m not sure why you’d want that but it nicely illustrates the method Prot uses to eliminate nonessential information for windows without focus.

If you’re interested in customizing your mode line, Dyer’s post serves as an excellent go-by. You can start with his code and tweak it until you have something that works for you. If you liked Prot’s video but were putting off doing your own customization because it seemed too complicated, take a look at Dyer’s post. It may help you get going.

Posted in General | Tagged | Leave a comment

Zamansky: Learning Elisp #6

Mike Zamansky has posted the 6th episode of his Learning Elisp video series. Again, he has split the content into two videos (9 minutes, 4 seconds and 11 minutes, 22 seconds) so as not to have a single overly long video. The subject is the conclusion of his discussion of implementing a Rot13 function.

The first video discusses the use of the interactive declaration to provide an optional argument for a function. He uses it to introduce an (optional) argument for the amount to rotate the text. He shows how to test if the argument was specified and to use the default of 13 otherwise.

The interactive declaration’s interaction with optional arguments is surprisingly rich. You can specify all sort of expected inputs such as numbers, symbols, directories, strings, file names, and many other possibilities. Zamansky mentions of few of these before settling on the appropriate choice.

He wants, of course, to input a number but for various reasons that he explains, he settles on the P. I have a small quibble with this part of the video. Zamansky says that Ctrl and a single digit will set the argument to 0-9, while Meta and any number of digits will set the argument to whatever number you input. On my system, Ctrl and Meta both support the any number of digits: indeed, they both call digit-argument. As far as I can see, there’s nothing special in my init=el mandating this behavior so you may want to check what happens on your system.

In the second video, he extends rot13 to support rotating regions. The main thing here is to detect if a region is active. Zamansky does this by checking if the mark is active. That’s okay but the recommended way is to use use-region-p, which checks the mark but also makes sure transient-mark-mode is set and checks for a few edge cases.

Similarly, he use (mark) and (point) to delimit the beginning and end of the region. The better way is to use (region-beginning) and (region-end) because, for example, (region-beginning) will use the lesser of the values of the mark and point and similarly for (region-end).

The choice of Rot13 was a good one because its (incremental) definition demonstrates several important aspects of Elisp and its run time library. After these 6 episodes, the Elisp n00b should be in a position to start experimenting productively with Elisp.

Posted in General | Tagged | Leave a comment

What’s New in Emacs 30

Emacs 29.1 was just released and most of us are still exploring it’s new features. But time and tide wait for no man and neither, apparently, does Emacs so of course work is already underway on Emacs 30. It seems silly to be talking about Emacs 30 already but it’s always good to know what’s coming and maybe even contribute to the new release in some way.

Emacs Elements has risen to the challenge with a video on what’s new in Emacs 30. Based on the video, Emacs 30 will not be the huge update that Emacs 29 was but, of course, it’s still early days and there’s plenty of time to add important new features.

The video is only 8 minutes so it should be easy to fit in. Here’s a list of the new features covered by Emacs Elements:

  • X selection requests are faster
  • write-region-inhibit-fsync defaults to t.
  • New options for remote files.
  • yes-or-no-prompt configurable
  • New face for display-time-date-and-time.
  • New icons for general use.
  • The tool bar can be put at the bottom of of the frame.
  • cl-print improved.
  • Ability to right align mode line elements.
  • Emacs supports input methods performing string conversion on X.
  • New Command: kill-matching-buffers-no-ask.
  • New flexibility in displaying grep results.
  • Eshell aliases can be loaded interactively.
  • In eshell, rgrep is builtin.
  • New command to indent docstrings or comments in functions.
  • New customization options for dictionary-search.
  • New Modus themes.
  • New/Changed byte-compilation warnings.

Take a look at the video for more details on these changes.

Posted in General | Tagged | Leave a comment

How To Contribute To Emacs Core

Emacs 29 has just been released and as I always do, I thanked the developers who worked so hard to bring it to us. Eli Zaretskii and a handful of others do much of the heavy lifting but there are many contributors who produce only a few—maybe even one or two—contributions per release.

Many of these folks simply had an idea that they wanted implemented or found an obscure bug and fixed it. They are people just like you and me who had an itch and scratched it. Even folks who aren’t proficient in Elisp can still help with, say, documentation.

The problem is that contributing to Emacs is an arcane process and can be daunting to a first time contributor. Happily, Protesilaos Stavrou (prot) has come to the rescue with a video on contributing to Emacs core.

The worst part, if you’re an engineer who hates paperwork and bureaucracy, is assigning your copyright. You’ve got this wonderful patch that you’d like to see installed and they tell you need to fill out a form assigning the copyright to the FSF. It wouldn’t be so bad if you could just fill it out and send it in but you have to wait for the FSF’s reply with an agreement for you to (digitally) sign and then wait again for their reply with your contributor number or whatever they call it. In my case that took at least two or three weeks.

Prot doesn’t spend much time on the agreement. Rather he focuses on the mechanical aspects of generating and submitting your change. It’s really useful information for the first time contributor and can save you a lot of time instead of trying to figure it out yourself.

The video is 21 minutes, 42 seconds so you’ll need to schedule some time. If you’re new to the process, you’ll find it time well spent.

Posted in General | Tagged | Leave a comment

Emacs As A Window Manager

I just ran across a post from the estimable Howard Abrams on using Emacs as a window manager. There are two dates on the post, 2015-01-12 and 2023-01-11, so I’m not sure of its birthdate but either way the post seems applicable today.

Abrams starts by noting that when he takes on a new job the first thing that happens is that they give him a work lap top. Naturally, he doesn’t want to add his personal data and configuration to his work machine. At the same time, he often needs to make personal notes and perform other non-work-related tasks during the day. The easiest answer is to carry two machines but who wants that? His solution is to install a virtual machine on his work laptop for his personal use.

He wanted a simple environment that mostly runs Emacs so he installed a server version of Ubuntu. He still wanted a graphical interface so he also installed xinit. The surprise is that the only thing he put in his .xinitrc file was

exec emacs

That effectively makes Emacs his window manager. He added a simple directive to his init.el to make Emacs open full screen so it was almost like booting into Emacs. Of course, he discovered he needed a few other applications but those turned out to be simple to add. Take a look at his post for the details.

Posted in General | Tagged | Leave a comment

REPL Driven Programming

I’ve written many times about what I call “exploratory” or “interactive” programming. The idea is you build your program from the bottom up, trying out expressions, building them into larger and larger units until you have a whole program. For me, the quintessential example of this is Kris Jenkins’ video on writing an Emacs Spotify client in 16 minutes. If you haven’t seen it or you’re the least bit confused about what I mean when I talk about exploratory programming, be sure to take a look. You won’t, I promise you, regret the 16 minutes you spend on it.

The other day, I saw a citation, I don’t remember where, for Mikel Evins’ post On repl-driven programming. By “REPL driven programming” he means what I call exploratory programming. His post was in response to someone asking how Python or Ruby REPLs are different from those in Lisp or Smalltalk and why Lisp’s and Smalltalk’s versions are better.

The TL;DR is that with Python, etc. you can do some things in the REPL but with Lisp and Smalltalk you can do everything. That means, in particular, that you can build and simultaneously debug your program right from the REPL as Jenkins demonstrates in his video. Notice that Jenkins never really “types in” his program. He just builds it up in the REPL1.

Evins’ discussion is mainly centered around Common Lisp and he goes on to describe how a run time error in Common Lisp drops you into “breakloop”, which is a parallel REPL in which the context of the running application is available. That means that you examine and fix the code and resume the computation where it left off. If you want to know what’s so great about the Lisp REPL, take a look.

Footnotes:

1

Jenkins isn’t technically using the REPL. He’s typing expressions into his buffer and then executing them with Ctrl+x Ctrl+e, which is essentially the same thing.

Posted in General | Tagged , | Leave a comment