Claude Shannon

Like most tech people, I know of Claude Shannon but not much about him. We all know he is the father of Information Theory but how many know anything about the man himself? Jimmy Soni and Rod Goodman have written A Mind at Play: How Claude Shannon Invented the Information Age, a biography of Shannon and his work.

The IEEE Spectrum has a nice article based on excerpts from the book. I always appreciated that Shannon was smart but he actually had a genius level intellect. He, along with Barney Oliver and John Pierce were legendary at the Bell Labs headquarters in Manhattan during the Second World War. One interesting fact is that although Shannon slaved away on war related projects during the day, at night he was working on his ground breaking theories about information. Virtually no one knew anything about his work or the results he had obtained until he published them after a decade of labor.

When he published his work, scientists were amazed. No one had anticipated his results or even thought very much about exactly what “information” is. Read the Spectrum article and you will have a new appreciation for how groundbreaking his work was and what a genius he was.

Posted in General | Tagged | 1 Comment

Removing Org Source Block Results

Grant Rettke over at Wisdom and Wonder has posted a nice bit of Elisp that runs a function on every source block in an Org file. His use case for this is getting rid of the results from running the source blocks. As he says, sometimes you accidently evaluate the source blocks—usually as a result of exporting—and then have (potentially) large results cluttering up your document.

Rettke solves that by running his source block code with a function that calls org-babel-remove-result. It’s a cute trick and introduced me to org-babel-remove-result, which I wasn’t familiar with. Hop on over and take a look if you have a need for cleaning up your results or need to run a function on all your source blocks.

Posted in General | Tagged , | Leave a comment

Measuring Package Load Times

If you’ve ever wondered which packages are slowing down your Emacs load time, Matthias Bloggt has a quick and easy way of finding out. The TL:DR is that he surrounds each package load (really, each section of his config) with some unique comment strings. When he wants to measure his load times, he does a query-replace-regexp to add code that captures the name of the section and the internal running time.

Afterwards, he runs an Org Babel file that post processes the data and produces a graph. It’s all very simple and doesn’t require a lot of setup or a fancy framework—other than Org mode, of course.

Also be sure to see the comments where Sacha Chua suggests an alternative method using use-package. If you’re already using use-package, and you should be, that may be an easier way.

Posted in General | Tagged | Leave a comment

Ivy and Internal Org Links

Last month, Ben Maughan wrote a very nice post on how to insert internal Org links. The problem he was solving was that he wants to insert an internal link to one of the headers in his Org file. That’s not very hard to do manually, of course, but when you do it a lot or you have a long document, a little automation can remove a lot of friction.

You can follow the link to see how he solved the problem but I want to emphasize how he leveraged the excellent Ivy library to accomplish his task. First he accumulates a list of the headings using the Worf package. Then he calls ivy-read (a completing read) with that list so that he can choose one of them. A nice feature of ivy-read is that you can specify an action for the selection. In his case he calls a function to grab the link and insert it at point.

The whole thing is just a few lines of code and is an excellent example of the power of Ivy. Take a look at his post and see how easy it is. The more I use Ivy, the more I like it, both for the built-in Ivy functions, such as Swiper, and the Ivy library functions for writing my own Elisp. I’ll say it again, the Ivy/Counsel/Swiper suite is the most useful set of packages I use.

Posted in General | Tagged , | Leave a comment

Revisiting abo-abo’s Refactoring Video

Last year I wrote about abo-abo’s screencast demonstrating a bit of his refactoring workflow. I just ran across it again and it’s so great I want to mention it once more in case some of you haven’t seen it.

The video shows how he does a small refactoring of some code in his Avy library. The basic plan is

  1. Use swiper to locate every instance of the code to be changed
  2. Call ivy-occur to save the swiper results to a separate buffer
  3. Switch to the occur buffer
  4. Start a keyboard macro
  5. Select the first item in the occur buffer
  6. Perform the refactoring of the first match (we’re now in the code buffer)
  7. Switch back to the occur buffer, move to the next item, and end the macro
  8. Run the macro on the rest of the items.

Notice how he is switching buffers while recording the macro. This is a much more efficient method than, say,

  1. Search for the first match
  2. Perform the refactoring while recording the macro
  3. End the macro and save it
  4. Search for the next match
  5. Run the saved macro if not done
  6. Goto 4

Actually, abo-abo also collects some information along the way that he uses to set up defaults. He puts this in a third buffer so his macro is actually dealing with three buffers. This is a brilliant use of keyboard macros and a tour de force in refactoring technique. It’s worth watching for the entertainment value alone. It’s only 10 minutes so there’s no excuse for missing out.

Posted in General | Tagged | 1 Comment

Oldies but Goodies Updated—Part 2

This is the second of my two-part post on packages that I find especially useful in my day to day work. I’ve discussed all these packages before but it’s worthwhile bringing them all together as suggestions that others might want to try out.

I used guide-key for some time until Kaushal Modi recommended I try out which-key as a replacement. This package is the ultimate in ease-of-use. Just install it and forget it. If you pause in the middle of a key sequence, which-key will pop up a buffer of the possible completions and what they do. You don’t have to specify what sequences you want it to work for; just pause and it will tell you what it knows. You can adjust things like the font and colors and the amount of time you have to pause but I did none of that and it works perfectly for me. Mostly, it stays out of the way but when I want to call a seldom-used command and can’t remember the whole sequence, it pops up a buffer that displays the possible completions.

I’ve written about mu4e so many times that I’ll just give the results of a blog search for reference. If, like me, you’re the type who wants to bring as many of your tasks as possible into Emacs or if you just want to have the convenience of Emacs editing for writing your emails, mu/mu4e is an outstanding solution. One of the things I love the most is that I no longer worry about storing away saved emails in a particular folder. There’s only one folder for that and I locate old emails in it with the extremely powerful search provided by mu.

There are other popular solutions—the notmuch suite seems to be a favorite—that do much the same but I’ve settled on mu4e and have been very happy. It’s still under active development so I don’t see myself changing systems. The only downside is that configuring mbsync can be tricky—especially for macOS—but I provide detailed instructions for that in one of those blog posts I mentioned above.

Once I got mu4e installed and working, I brought the last remaining assimilable task into Emacs: my RSS reader. For that, I used the wonderful elfeed package. It’s easy to use, and puts all its results in a database that is easy to search. For an excellent introduction to the post, see Mike Zamansky’s 3 videos on Elfeed, especially the first.

As part of getting mu4e working, I needed an easy and secure way of providing the passwords for my SMTP servers. The way to do that is with authinfo and the associated ~/.authinfo file. I just put the services and associated passwords in the .authinfo file and encrypt it. When Emacs starts up (about once every week or two for me) it will ask me for the password to decrypt .authinfo and will just cache the results. The documentation says that there’s some time limit before the cache expires, but for me, at least, I’ve never had it ask me for the .authinfo password except at Emacs startup.

You can put any of your passwords in the .authinfo file and retrieve them with auth-source-user-and-password. I do that, for instance, for my WordPress password for Irreal. It’s very handy.

Finally, there’s winner-mode. I’ve been using it for a long time and don’t know why I didn’t mention it in my first “Oldies but Goodies” post. It’s built into Emacs so all you have to do is enable it with

(winner-mode 1)

Thereafter, you can recover a previous window configuration by simply typing Ctrl+c repeatedly until you’re back to the desired configuration. It’s just perfect for those times when you have a complicated window configuration showing and then need to, say, call help or some other function that changes the window configuration. With winner-mode you can make your call and then reestablish the old configuration easily. Actually, you can scroll the window configurations in either direction by using Ctrl+c to move to newer configurations but I never do that.

I hope that you’ll find some of these packages useful and start using them yourself. They make my workflow much more frictionless and make my editing easier and more fun.

Posted in General | Tagged | Leave a comment

Some Oldies but Goodies Updated—Part 1

About 15 months ago, I wrote a post, Some Oldies but Goodies, that talked about some of the packages that I found most useful in my day-to-day work. On rereading that post, I find that it’s aged well in the sense that the packages I talked about are still important parts of my workflow. In particular, abo-abo’s define-word and Steve Purcell’s whole-line-or-region packages remain two of my most used packages. Each of them gets invoked several times a day.

Of course, there’s always more to learn about Emacs and new packages are being added everyday so I thought I should talk about some of the packages I’m using now that have become important for my workflow. This time I have 9 packages to discuss so I’ll break the post into two parts. As I did in the original post, I’ll point back to the post that originally discussed them.

By far, the package that’s had the most impact on my workflow is the Ivy/Swiper/Counsel suite. I really love these packages. They’ve completely replaced isearch, ido, and smex in my workflow. The modified regular expression selection that Ivy implements takes a day or two to get used to but I’ve found it’s much more useful than normal regular expression search (which is still available, of course). If I could have only one package—suite really—this would be it. If you’re not using it, you owe it to yourself to check it out. Mike Zamansky’s post and video is a good place to start. I show my current configuration below but I also use other counsel functions by calling them with Meta+x.

(use-package swiper
  :ensure t
  :diminish ivy-mode
  :bind (("C-s" . swiper)
         ("C-c C-r" . ivy-resume)
         ("M-x" . counsel-M-x)
         ("C-x C-f" . counsel-find-file)
         ("C-M-i" . complete-symbol)
         ("C-." . counsel-imenu)
         ("C-c 8" . counsel-unicode-char)
         ("C-c v" . ivy-push-view)
         ("C-c V" . ivy-pop-view)
         ("M-y" . counsel-yank-pop))
  :config
  (ivy-mode 1)
  (setq ivy-use-virtual-buffers t)
  (setq ivy-count-format "%d/%d "))

For years I’ve been taking Steve Yegge’s advice and using search for navigation. My use of isearch for that has almost entirely been replaced by abo-abo’s Avy library that provides (or, really, powers) a replacement for ace-jump-mode. I tend to edit as I write so I’m always jumping around in the buffer. Avy makes that almost painless. This is another package that I use constantly everyday. Avy also provides ace-window, which is just what you need if you have more than two windows open and need to switch among them easily. The Avy library powers other useful tools as well. If you’re not already using it, take a look at its GitHub page.

If you’re using Emacs for coding, something like TAGS is really useful for quickly jumping to a function or variable definition even if it’s in another file. I’ve never been able to warm up to TAGS systems because they are hard to maintain. You have to take steps to regenerate your TAGS file every time you make a change to any of the covered files. Then I found dumb-jump. It’s just perfect for me. There’s nothing to maintain and it’s very fast. If you’ve resisted using a TAGS system because of the hassle of dealing with the TAG file, take a look at dumb-jump.

Another package I resisted installing for a long time is PDF Tools. I finally decided to give it a try after reading Piotr Limanowski’s post on Reading for Programmers. I really liked the way he used the Interleave package to take notes while reading a PDF paper. Even without Interleave, PDF Tools is a substantial improvement on the default DocView. It’s fast and you can make annotations directly to the PDF. If you interact with PDFs, this package is definitely worth a look.

In the second part, I’ll take a look at 5 other packages that are making my workflow easier.

Posted in General | Tagged | Leave a comment

Decouple Your Phone from Sensitive Accounts

Laura Shin over at Forbes.com offers some excellent advice for safeguarding your sensitive accounts such as bank accounts, Dropbox, cloud storage, and the like. Some of it is the usual sensible advice such as using a password manager that generates long high entropy passwords, using two-factor authentication, and lying about the answers to security questions1.

But as Shin points out, a weak link for most accounts is your phone. If a criminal can get access to your phone account and forward calls to his account, two-factor authentication can be largely bypassed and password reset protocols can be compromised. Shin recommends that you

  • Disable online access to your phone account
  • Add a password or pin to your phone account
  • Use a phone account specific email address for your phone account
  • Tell your phone carrier to allow changes only in person with a photo ID
  • Try Google Voice
  • Don’t associate your main phone number with any sensitive accounts
  • Use biometric authentication

Shin explains how you can implement the above steps. She’s got a lot of good advice and it’s definitely worthwhile implementing as much of it as you can. Don’t think you’re safe because you’re not important or rich; criminals will be just as happy to steal your money as anyone else’s.

Footnotes:

1

I like to use UUIDs for this (on macOS you generate them with uuidgen) but of course this make sense only when you’re using a password manager.

Posted in General | Tagged | Leave a comment

An Emacs Tutorial Series

Mickael Kerjean has an interesting series of Emacs tutorials over at his blog. He approaches the tutorials from the point of view of the learning path that he would have liked to follow when he learned Emacs.

The tutorials are not how-tos on the fine points of using Emacs but instead offer pointers to resources along with commentary on why a given facility is useful. There are 5 tutorials covering:

  1. Basics
  2. Org Mode
  3. Built-in packages
  4. Adding packages
  5. Elisp and documentation

If you’re new to Emacs you can use these tutorials as a way to organize your study and learning.

Posted in General | Tagged | Leave a comment

Pretty Printing and Macroexpanding the Last Sexpression

As Emacs users, we’re always discovering some new feature of our favorite editor. Here’s one that’s so obscure not even John Wiegley was aware of it.

Over at the Emacs subreddit, glyfo was showing off a bit of elisp that he wrote to macroexpand the last sexpr. Kaushalmodi noted in the comments that there’s already a command for that, pp-macroexpand-last-sexp. That nice to know because it can often be useful. At bit later John commented that he hadn’t been aware of the command but had often needed it.

If you’re writing Elisp or just trying to read and understand some code that uses a macro, this is a command worth knowing. The name is pretty easy to remember and even if I forget, I can find it again by searching Irreal.

Posted in General | Tagged , | Leave a comment