Lisp Runtime Redefinition

One of the things I love most about programming in Elisp is what I (and others) call interactive programming. You can write a little snippet of code—even as small as an expression—and try it out immediately without having to build any special test scaffolding. Working this way, you can incrementally build up to your final code by adding more and more snippets to it and trying things out as you go. This previous post of mine points to two brilliant examples of this. In terms of Emacs itself, you can change one of it’s core functions and have the new version take effect immediately without restarting Emacs or doing anything other than a Ctrl+x Ctrl+e.

I recently stumbled upon an old post by Tibor Simko in which he expands upon that idea by talking about runtime redefinition in Common Lisp. It’s a really great post and helps explain why Lisp languages are so much fun to program in. Even when you get a run-time error, you get dumped into the debugger where you can fix the error and take up the computation exactly where it left off except with the corrected code.

Simko illustrates this and more in his post. Even though it’s almost 15 years old, it’s as relevant and interesting today as when it was first written. If you have any interest at all in Lisp languages, be sure to take a couple of minutes to read it.

Posted in General | Tagged , , | 1 Comment

Magit Rebase Tutorial

Guowei Lv has a very nice two-part tutorial on using Git rebase with Magit. Rebase often seems to cause confusion with n00bs—at least it did with me—so I’m always happy to see more tutorials about it. If you’re a visual learner, Howard Abrams has a nice video on the subject that I wrote about previously. If you prefer to read about a subject at your own pace, you may prefer Lv’s tutorial. If, like me, you like to first see a video to get an overview and then read a tutorial to understand the details, you should first watch Abrams’ video and then read the tutorial.

In the first part, Lv shows how to amend the commit message for a commit other than the last one. Then he moves on to showing how to squash two or more commits into a single one. The need for this happens a lot to me so it’s nice to know how to get everything into a single commit.

On the other hand, sometimes you need to split a commit into two or more parts. He also shows how to do this. Again, this is something that comes up more than you’d expect.

The second tutorial considers how to use rebase to merge branches. My problem with rebasing is that I don’t do it enough to remember the details. I can always go back and watch Abrams’ video to refresh my memory but that seems like overkill. Lv’s tutorial is nice because it serves as a go-by for the common cases and I can just bookmark it and refer to it when I need to.

Posted in General | Tagged , | Leave a comment

Counting Words in Some Buffers Only

It is often, but not always, nice to have a running count of the words in a buffer. Most usually, this is convenient for writers or students who need to keep track of word count in a paper or book. One way of doing that is the excellent wc-mode that I wrote about previously.

I like to keep a running count when I’m writing a blog post but almost never otherwise. I have a key sequence to turn it on and off so it’s easy to enable it for the buffers that I need it in. Still, it got to be a pain to turn it on every time I wrote a post so I added a bit of Elisp to enable it when I open a file in /Users/jcs/org/blog, which is where my blog posts live.

Here’s the code, which as you can see, is merely part of the use-package call.

(use-package wc-mode
  :ensure t
  :init
  (add-hook 'org-mode-hook
            (lambda () (when (and (buffer-file-name)
                                  (string= (file-name-directory (buffer-file-name))
                                           "/Users/jcs/org/blog/"))
                         (wc-mode 1))))
  :bind ("H-=" . wc-mode)
  :config
  (wc-mode nil))

It’s important to add the hook in the :init section, otherwise it won’t work until wc-mode is enabled manually at least once.

This is pretty trivial and I wasn’t going to write about it but I saw a question on reddit asking how to do something similar so I thought my solution might be useful to someone else.

Posted in General | Tagged | 3 Comments

Don’t Say I Didn’t Warn You

As yet another example of why we should always look askance at the government collecting data, I offer the recently revealed debacle of the Swedish government’s loss of control of government and police databases. The databases contain information on almost all Swedish citizens and may also reveal the identities of military and security personnel.

The loss was apparently due to incompetence (see here and here) rather than malevolence but at least two ministers have already resigned and there’s a real possibility the government could fall. In the mean time, the personal information of almost all Swedish citizens is at risk.

This seems outrageous but it’s what always happens when a government is allowed to collect and centralize information: sooner or later it will be abused or the government will lose control of it. Either way, the subject of the data will be the ones to suffer.

Posted in General | Tagged | Leave a comment

Claude Shannon Redux

Recently, I wrote about the IEEE Spectrum’s article on Claude Shannon by Jimmy Soni and Rob Goodman. If you haven’t already read their article, I urge you to do so. Shannon was a fascinating man and a genius virtually unknown outside the tech community.

Over at The Mission, Soni and Goodman have another article that’s also in support of their book on Shannon. This article focuses more on Shannon’s genius and some of the things that the authors learned from their study of him. In particular, they list 12 lessons or strategies that Shannon used to organize his research and focus his genius on the problems he was interested in solving. These included such things as “Time is the soil in which great ideas grow” and “Fancy is easy. Simple is hard.”

The lesson I took away from the article, although it wasn’t explicitly called out, was to husband your time. Shannon would famously throw letters that he didn’t want to deal with into a “procrastination bin” from which they never emerged. He didn’t waste time on anything that didn’t interest him. He didn’t bother trying to sell or argue for his ideas. If someone didn’t believe in them, he ignored that person.

Many or most technical people are not history buffs—I know that’s true of me—but there’s something about Shannon that resonates. Do yourself a favor and read these two articles. I’m certain you’ll be glad you did.

Afterward

Soni and Goodman have a third article that discusses Shannon’s wife, Betty Moore Shannon, whom they describe as his most important collaborator and a topnotch intellect in her own right. If you enjoyed the first two articles on Shannon, you’ll like this one too.

Posted in General | Tagged | 1 Comment

The Pass Password Manager

A recurrent theme here at Irreal is that you really need to be using a password manager. Let it generate a long, unique, random key for each site and protect those keys with a secure master password (generated by, say, diceware).

Andy Moran used to use LastPass but didn’t like that all his data was stored on a remote sever that he didn’t control. There are lots of password managers that don’t have this problem—I use 1password but there are plenty of others. Moran has posted about one of them, the Pass password manager. Pass is open source and tries to adhere to the Unix philosophy. Basically, every password lives in a GPG-encrypted file named for the resource it’s protecting. The files can be manipulated with the usual Unix tools and except for being encrypted are plain text.

Moran’s post walks you through installing and setting the utility up. He also shows some examples of its use. If you’re looking for a good password manager that you control and that you can sync with Git, take a look at Moran’s post. I’m very happy with 1password but if I weren’t or if I become unhappy in the future, I would certainly give Pass a try.

Posted in General | Tagged | Leave a comment

Tuning Your Emacs Configuration for a Fast Load

Gergely Risko has an interesting GitHub repository that explores ways of making your Emacs load time as small as possible. Unless I’m hacking on my configuration, I rarely start Emacs except at boot time so the two or three seconds of startup time doesn’t bother me much. But if you simply must get your startup time to an absolute minimum, take a look at Risko’s strategy.

The TL;DR is that he avoids package-initialize and uses use-package in its place. The real problem with that solution is getting the load paths for the packages. In the video on use-package, John Wiegley and Sacha Chua discuss that problem. Wiegley avoids it by not using the package system. Most of use would rather not take that option and Risko has a method of loading the paths that runs when init.el isn’t compiled and adds them to the init.elc image so that the overhead is mostly avoided.

Most of us, I’m sure, don’t load Emacs very much. We either have a long running instance or start the server and use emacsclient so unless you have a use case like Wiegley’s that requires frequent restarts of Emacs, you may not want to bother with Risko’s solution. If minimizing your Emacs load time is another video game for you, take a look at the repository to see if his ideas might help.

Posted in General | Tagged | 6 Comments

Configuring Notmuch and Offlineimap for Emacs

As most of you are doubtless sick of hearing by now, I’ve settled very happily on mu/mu4e to handle my email from within Emacs. It’s not the only possibility, of course, and many other Emacers prefer using notmuch, which is similar to mu but with a robust tagging system.

For those of you in the notmuch camp, KKatsuyuki has an excellent post on how to configure notmuch and offlineimap for use with Emacs. He’s got a complete recipe so you should be able to pretty much paste his configuration into your init.el making only the obvious changes to things like paths and email account info. KKatsuyuki’s configuration is for Gmail, so you may have to do a bit of research on offlineimap if you’re using something else.

KKatsuyuki’s post is an excellent go-by for anyone wanting to bring email into Emacs using notmuch.

Posted in General | Tagged | 1 Comment

An Application of let-alist

Since Emacs 25.1, Artur Malabarba’s excellent let-alist macro has been a built-in feature of Emacs. As the name suggests, it’s a way of dealing with alists. The idea is that instead of writing a series of assq and cdr statements, you just write .tag where tag is the car of an alist element. Malabarba’s post gives an example of its use.

There’s a nice example of its use by T. V. Raman in a post about parsing the result of a json-read. Most of the examples I’ve seen use json-read to produce the alist, but the macro can, of course, be used with any alist. It can even handle nested alists as both Malabarba’s and Raman’s examples make clear.

Posted in General | Tagged | 1 Comment

Zamansky 36: Swapping Buffers and Some Elisp

Mike Zamansky has another video up. This time, it’s about swapping buffers but keeping focus in the original window. The video is interesting because it shows the process Zamansky went through to solve a problem he was having.

The problem was that he had a window configuration with one large buffer and two smaller ones. He wanted to swap the buffer in one of the smaller windows with the one in large window. If you have ace-window installed, it’s easy to swap two windows. I have the proper call in a hydra and use it reasonably often.

The problem with that for Zamansky is that he’s trying to move another buffer into the large window so he can work on it but ace-window keeps the focus with the original buffer so it’s in the wrong window. What he needed was to swap the buffers but keep the focus in the original window.

Most of the video is how he solved this problem with a bit of Elisp and how he felt his way to the solution by using the Emacs help system and by looking at the ace-window code. It’s an instructive video especially if you have only minimal Elisp skills. Zamansky shows that you don’t need to be an expert to solve real problems.

Even if you already use ace-window, the video may teach you something you didn’t know. It did me. It turns out that after calling ace-window to change to a new window, you can give it a subcommand instead of a window number. That makes it easy to swap windows and do certain other actions. See the video for the details.

The video is a little over 12 and a half minutes so it should be easy to find time for it. As with all of Zamansky’s videos, it’s well worth your time.

Posted in General | Tagged | Leave a comment