Zamansky: Learning Elisp #12

Mike Zamansky just published the latest video in his Learning Elisp series. This is the second video is his project to insert emojis into a buffer by replacing keywords with the corresponding emoji. In his previous post, Zamansky showed how to write a function to replace the keywords with the appropriate emojis. This video considers how to make the substitution happen automatically.

Experienced Elispers won’t be surprised that the vehicle Zamansky used for this was hook functions. In particular, he used the after-change-functions hook. The functions in his hook get called every time the buffer changes. That means that it gets called whenever a character is inserted. The rest is easy.

Every time a character is typed, Zamansky’s function is called by the hook. The first thing it does is check if the character is a space. If it’s not, the function simply returns. If it is, the function checks for a keyword—delimited with colons—and if found replaces the keyword with its emoji. The function is essentially the same as that from the previous video except for the checking if the current character is a space.

The thing that strikes me is how easy all this is. The function itself is short and simple and automating it is simply a matter of calling add-hook. I can’t imagine how one would do this in another editor, if you could do it at all.

The video is 13 minutes, 46 seconds so you’ll probably have to schedule some time. If you aren’t familiar with hook functions, this video is a good introduction. As usual, the video is worth your time.

Posted in General | Tagged , | Leave a comment

An Occur Video

Occur is, I think, an underappreciated command. At first glance, it seems sort of like grep except it works on buffers rather than files. You give it a regular expression and it opens a new buffer that lists the matches. So far, just like grep but each of those listed matches is actually a link to the line it matches.

Just this capability is very useful. I use it when I’m entering items from my monthly bank statement into my tax file. The tax file is an Org file with a headline or subheadline for each category of items I’ll need for my tax return. I run Occur with the regular expression "^\\*+ ", which lists all the headers of the tax file in an Occur buffer. That makes it easy to jump directly to the correct place in the tax file for each relevant item in my bank statement.

But wait; there’s more. You can also make the Occur buffer editable and every change you make there will be reflected back into the original buffer. As with the similar grep buffer capability, this is obviously a powerful feature.

All of this and more is discussed in the recent Emacs Elements video, All you need to know about the Emacs OCCUR command in 4 minutes. Occur is a simple but powerful tool. All you need to do is add is a little bit of imagination to enhance your workflow. A nice example of this is the comment from the reddit post for the video.

If you’re not already familiar with Occur, the video is a nice introduction. The video is only four minutes, ten seconds so it should be easy to fit it.

Posted in General | Tagged | Leave a comment

Vimari

Back in August, I wrote about my quest to minimize mouse usage as much as possible. That’s easy in Emacs where my mouse usage is essentially zero. It’s a bit harder when navigating between apps and performing various system duties such as emptying the trash. For that, I’ve discovered that in macOS, Alfred is the ideal solution.

It can mostly eliminate the need to use the mouse except when in Safari. Even with Safari, it can go a long way. For example, I can simply type the first letter or two of a site I want to visit and Alfred will open the browser and take me to that site. It’s almost entirely eliminated my clicking on bookmarks and the favorites bar.

In the post, I lamented the lack of a good solution for dealing with the browser. In the comments, nitin suggested vimium. It was exactly what I wanted but, sadly, it only worked with Firefox and Chrome. Since I’m a Safari user, I was bitterly disappointed but J Tevq popped in to tell me about vimari. It’s a port of vimium to Safari that’s available in the Mac App store.

I really love vimari. Now my mouse usage is minimal even when I’m dealing with Safari. As the name suggests, it uses Vim’s keybindings for navigation. That may seem strange for a guy who’s all in on Emacs, but the single keys for navigation and following links is a win and hasn’t bothered me at all.

If you’re a Chrome or Firefox user, even on Linux, don’t despair. You can use vimium, which is even more full featured. Neither extension completely does away with the occasional need for a mouse but they go a long way. If, like me, you like to keep your fingers on the home row, take a look at whichever of them is appropriate for your setup.

Posted in General | Tagged , | Leave a comment

Customizing Emacs Menus

As I’ve mentioned before, I’m not a big fan of Emacs menus. That’s mostly because I’m much faster if I can stick to the keyboard and, of course, my general desire to avoid the mouse when I can. Still, I admit that often the menus are handy when I want to execute some obscure command for which I don’t remember the name.

Others, of course disagree. One of those people is Charles Choi who has previously schooled me on the the proper way to configure Emacs. Choi likes to use the menus but he’s not always thrilled with their content. In a recent post, he take a look at the Tools menu and what’s wrong with it.

The post isn’t so much about what’s wrong with the Tools menu as it is about how to change it to better serve your workflow. You don’t have to modify the Emacs source for the menu. You can simply specify that you want to delete an item, add a new command, or insert a separator line. There are commands to do this to an existing menu so it’s easy to configure menus to your liking.

Choi insists that using menus lowers the cognitive load of memorizing commands and there’s no doubt that’s true but I’m of the mind that, at least for commands you use more than once a month, it pays to spend the mental cycles to memorize them and keep your fingers on the keyboard.

This is another one of those questions where there can be reasonable disagreements. In the end, it doesn’t matter much which side you come down on as long as it works for you.

Posted in General | Tagged | Leave a comment

Open Xcode From Emacs At The Same Line

Álvaro Ramírez has a nice post on opening a file in the macOS Xcode editor from Emacs. There’s nothing unusual about that, of course, but Ramírez’s wrinkle is that he wants Xcode to open at the same line the Emacs point is on.

It’s reasonable to ask why a devoted Emacser like Ramírez would want to open Xcode at all. The answer is that he’s more pragmatic than I am. I consider leaving Emacs a fail; something that I should try to find a fix for. Ramírez, as I say, is more pragmatic. Although he much prefers working in Emacs, he’s willing to use other tools if they’re more appropriate. Although he mostly uses Emacs for his iOS development, there are certain situations—debugging, for instance—where he feels Xcode is a better solution.

He’s long used Bozhidar Batsov’s crux to open the file he’s working on in Emacs in the Xcode editor. The problem was that it opened at the top of the file rather than at the line he was looking at in Emacs. It turns out, though, that you can call Xcode from the command line and specify the line to open the file at.

Ramírez, of course, used his dwim-shell-command framework to implement this but it would be trivial to adopt to plain Elisp if you’re not a dwim-shell-command user. You should also check out the comments in the reddit post about the method. There are some other useful ways of integrating Emacs and Xcode workflows.

Posted in General | Tagged , | Leave a comment

Elisp Links

In order to be a really proficient Emacs user, you’re going to have to learn at least a little bit of Elisp. As I’ve said before, Elisp is at once both easy and hard to learn. Like all Lisps, there’s not much syntax or dark corners to know. That’s simple. The hard part is the huge run time library. There are hundreds of functions performing all sorts of actions. Even after 15 years, I still don’t know all of them.

Over at Emacs Elements there’s a new video titled Great links to help you learn Emacs Lisp. The video starts off by saying that unlike many other languages you’re going to have to learn Elisp by yourself. That’s true, I guess, but no more true than for any other language. There are plenty of resources for learning Elisp—indeed, that’s the point of the video—probably not as many for learning, say, Python but still plenty.

One of the commenters complained that there was no point in having a video; all that’s really required, he says, is the list of links. I disagree with that. The video discusses each link in the list and why it’s worthwhile spending your time on. In any event, the list is here. As you can see, there are lots of way to learn Elisp but like everything else you have make the effort. I don’t know of any other way of learning anything but learning it yourself.

Posted in General | Tagged , | Leave a comment

Crafted Emacs v2

Michael Ashley wrote to tell me that System Crafters has released version 2 of their Crafted Emacs configuration. Irreal readers will be familiar with System Crafters from David Wilson’s System Crafters video series that I’ve written about many times.

It turns out, though, that they also produce the Crafted Emacs configuration, which can be described as a sort of Emacs starter kit with the emphasis on starter. Their idea is to provide a simple but effective Emacs configuration that can serve as a starting point for users to build their own bespoke configurations.

The base configuration is designed to provide reasonable defaults that result in a usable Emacs. They add a few packages to that base configuration but mostly leave the development of the configuration to the user. They believe that the end configuration should be uniquely the user’s and that Crafted Emacs is merely a jumping off point.

If you’re like me and already have a highly customized configuration, it’s still worthwhile taking a look at the repository to see the defaults they chose and some of their implementation strategies. For example, I learned that you can specify priorities for your ELPA repositories so that you get your packages from your preferred repositories, whatever they are. I was also impressed that they used customize-set-variable instead of setq for defcustom values.

If nothing else, you should take a look at their README to see what the project is about and their philosophy. It’s comprehensive but worth a few minutes of your time. I see lots of people wanting to migrate off, say, Spacemacs or Doom and develop their own configuration. Crafted Emacs is an excellent way of getting started.

Posted in General | Tagged | Leave a comment

Customizing Emacs Journal

Rob Streeting has a very interesting post on building the ideal Emacs journal. He was an Org-roam user but discovered that he never seemed to add links to the data he needed later. He began building the ideal journaling system in his head but discovered that org-journal did almost everything he wanted.

His original plan was to modify the source code to mold org-journal to fit his workflow but he soon realized that all he had to do was write a wrapper function around org-journal-new-entry. It was almost like advising the function except that he called his wrapper function directly rather than org-journal-new-entry to add a new entry.

He had four types of entries he wanted to make:

  • Tasks
  • Notes
  • Meetings
  • Breaks

His wrapper code takes care of clocking him into and out of events when he adds a new entry. It also insists that his cursor be on a TODO task when he chooses a Task event. That automatically creates a link from the journal entry back to the TODO and clocks him into the TODO task.

He includes the code for his wrapper function at the end of his post so you can see how he did it. It’s quite clear and easy to follow and could easily serve as a go-by for your own custom org-journal. He’s added some tweaks since but he provides a pointer his Github repository so you can his latest version.

I really like his system and am half tempted to replace my own system with something similar. I have a journal file but it’s more general and doesn’t use org-journal so it would be a major effort to migrate. Regardless, it’s a good post with some nice ideas so take a look.

Posted in General | Tagged | Leave a comment

Exploratory Data Analysis With AWK

This post is about Brian Kernighan and AWK, two things always worth hearing about. All of you, I’m sure, know that after retiring from Bell Labs, Kernighan took a professorship at his Alma Mater, Princeton. Since he’s been there, Kernighan has often offered courses in Computer Science aimed at students in the Humanities, such as Computers in our World.

Last Spring he taught a course in the Humanities department, Literature as Data, that considered using computational techniques for answering questions in literature research. The usual vehicle for this sort of thing is Python and the Pandas library but Kernighan and his co-instructor decided to emphasize AWK and how it can be used in exploratory data analysis.

After the class was over, Kernighan wrote a short essay describing the class and their experience with it. He gives examples of many of the questions they explored by running AWK against a database of sonnets and their authors. The database is in CSV format and perfect for exploring with AWK. Some of the results were surprising. For example, although sonnets are supposed to be exactly 14 lines long, some—even some by Shakespeare—have more or less lines. One even had 123 lines. Who were the poets who broke the rules? AWK makes it easy to explore the question.

Kernighan’s essay has more examples of questions they were able to explore by querying the database with AWK. The essay links to the database they used so you can play with it yourself if you’re inclined. It’s an interesting essay and a short read so well worth spending a couple of minutes on.

Posted in General | Tagged , | Leave a comment

PlantUML and Org-mode

AbstProcDo, like me, is a terrible artist. Sometimes, though, we need to add a diagram to our documentation, report, or Blog post. I usually use Graphviz or, when I’m in Troff mode, Pic for this. But these aren’t the only possibilities. Another that I keep meaning to try is PlantUML. Despite its name, it’s a pretty flexible drawing program—at least for the types of diagrams that I need to draw.

AbstProcDo has a short reddit post that very succinctly demonstrates using PlantUML with Org Babel. It’s by no means a complete exegesis on using PlantUML but it does give a flavor of using it with Org mode and showcases two very different types of diagrams that you can produce with it.

I like that the markup language is intuitive and probably easy to remember. Take a look at the second diagram and the markup that it generated. It would be a lot harder to generate that in Pic or even Graphviz. Don’t get me wrong, they’re both great applications that I’ve used many, many times over the years but I don’t use them everyday and I always have to refresh my memory on their use when I do.

If you occasionally have to produce line drawings in your work, PlantUML is definitely worth a look.

Afterward

After writing this post, I discovered a second reddit post by AbstProcDo that describes making Gantt-like charts with PlantUML. You can see an example of its actual use in Org Babel blocks here by clicking on the Raw button.

Posted in General | Tagged , | Leave a comment