Creating a Branch from the Current Git State

Kris Jenkins, whose wonderful video I’ve written about before, has posted a very handy Magit tip. What do you do if you want to add a feature branch but start working on it before creating the branch? What you’d like to do is move your unpushed work to a new branch and set your current branch back to the state it had before you started working on your changes. Neither of the two common solutions are very good but it turns out that Magit has a solution: magit-branch-spinoff.

It does exactly what you want: it creates a new branch with your unpushed commits and resets your current branch to the last commit it shares with the upstream repository. As far as I can tell, this functionality exists only in Magit and is not part of Git. It’s yet another reason to be using Magit (and, of course, Emacs). Take a look at Jenkins’ post for the details and more background. Also take a look at the documentation to see its full functionality.

Posted in General | Tagged , | 3 Comments

The Most Beautiful Program Ever Written

If you’re a lisper and enjoy Scheme, you may like William Byrd’s video on The Most Beautiful Program Ever Written. Unless you’ve been immersed in the Lisp culture, it’s probably not what you think. According to Byrd, the most beautiful program is just 5 lines of code implementing a metacircular interpreter for Scheme. He has, he says, spent the last 13 years or so trying to understand the implications of those 5 lines.

His presentation starts off with a short introduction to Scheme and then moves immediately to writing a function (in Scheme) that can interpret Scheme expressions. He builds on a simple implementation and eventually pares it down to 5 lines.

His real interest, though, is using the ideas in the metacircular interpreter to do logic programming. The second half of the video is about a program that does program synthesis. You can specify some or even none of a program and what output you want and the program will compute Scheme expressions to give you the results. It’s sort of like Wilfred Hughes’ suggest.el for Emacs but much more sophisticated.

The video is just over and hour and a half so you will definitely need to schedule time. If you have only a casual interest in Lisp the hour and a half may be more time then you want to spend but the talk is interesting and self contained. You needn’t worry about not having enough background.

Posted in General | Tagged , | 4 Comments

Hosting Your Own Contacts and Calendar

Those of you who have been around for a while, know that I live in the Apple ecosystem. I like having all my devices synced up automatically and Apple does that pretty seamlessly and, I believe, reasonably securely. Still, I like to have a go-bag packed and ready for the time that disaster strikes and I have to leave the comfort of Appleland. That’s the reason all my data is either plain text or, in the case of things like pictures, in an open format that can be read with easily available open source tools. If Apple disappeared, I wouldn’t lose any data and could easily go back to a Linux based environment.

Part of my exit plan involves having a way of dealing with my calendar and address book. Apple handles those in a particularly pleasing way and keeps everything synced between my devices. What would I replace those with? I certainly don’t want to share my information with the world through Google so Google calendar and contacts is not an option.

Happily, Nick Touran has a nice solution. He has an interesting post in which he shows how he self hosts his calendars and address book. His setup includes syncing to both his Android phone and his wife’s iPhone so it’s a pretty comprehensive system. Take a look at his post to get the details.

I probably wouldn’t use the same clients as he does. As you know, I try to keep as much as possible in Emacs so I’d probably use bbdb or perhaps one of the Org solutions for my contacts and I’d import my calendars from the CalDAV server into my Org agenda and perhaps calfw. Touran’s setup allows him to share a calendar with his wife so my shared calendars wouldn’t be a problem. About the only thing I’d really miss is the wonderful Fantastical.

Posted in General | Tagged , | Leave a comment

Collapsing Empty Directories in Zsh

Earlier this month, I wrote about Fuco1’s package to collapse empty directories in dired listings. That’s a handy thing that lets you avoid clicking through a series of empty directories1 to reach the file or directory you really want.

The idea originated with GitHub where Karl Voit noticed it and soon became addicted. He started wishing he could do the same sort of thing in zsh. In particular, he wanted to have cd jump over the empty directories so he didn’t have to list all the intermediate directories. With the help of seanliao96 he offers a nice bit of shell code that does just that.

If you’re a zsh user, you should take a look at Voit’s post and see if you want to adopt his code. As I say, it’s a simple shell function that you can paste into your zshrc.local so it’s easy to experiment with and get rid of if you don’t like it.

Footnotes:

1

By which I mean directories that have only a single entry of another directory.

Posted in General | Tagged , | Leave a comment

Hydra Video

Oleh Krehel (abo-abo) gave a very nice talk on hydras at the london.el Emacs Meetup. The talk was on 2017-07-04 so the information is up to date. Happily, abo-abo recorded the talk so you can watch it on YouTube.

Krehel starts the talk by giving the history of the hydra package. Originally, it was just a simple macro that he used mainly to make zooming in and out easy. Sacha liked it and encouraged him to package it for Melpa. Today, of course, it’s much more full-featured. Actually, I wasn’t aware of the newest features. Mostly they make building hydras easier and also give better control over what gets displayed.

One nice use of hydras is for increasing the number of bindings available to use. You can pick a prefix (to call the hydra) and then have any number of other keys mapped to some action. You can do that by hand, of course, but using the hydra makes it easy and the :timeout keyword makes it behave just like a regular keymap with which-key installed.

Another nice example is getting all of the rectangle commands in a single place. By default, the rectangle keys are intermixed with the register and bookmark bindings and it’s hard to find exactly what you want. With a hydra, you see just the rectangle binding and, if you, unlike me, ever learn them, you can simply set a timeout so the hydra doesn’t display anything unless you forget.

The video is 37 minutes so you’ll have to schedule some time but it’s definitely worth watching, especially if you haven’t kept up with all the latest hydra features.

Posted in General | Tagged | Leave a comment

Emacs and Magit

There’s been some contretemps lately concerning Emacs and Magit. The issue is that Magit can’t be integrated into Emacs because not all the contributors have filed a copyright assignment. RMS is even on record wishing that someone would recreate Magit so that it could be integrated.

Frankly, I don’t get it. Why, exactly, does it need to be integrated? I see it as a net minus. The situation is parallel to that of Org mode, which has been integrated. The thing is, no one uses the integrated Org mode because it’s always outdated1. Everyone simply loads the Melpa version (or Melpa-stable if they’re paranoid) and stays up to date with the latest version. One thing for sure, the large Magit codebase and its user community certainly don’t need to be replaced simply so its functionality can be “integrated.”

It’s not easier for users, as one of the LWN commenters claimed, if Magit is integrated. A simple use-package with :ensure t will load Magit from Melpa with no more work than is needed to add a require for the integrated package. The package management functionality built into recent Emacs versions make using third-party packages as easy as using built in packages. Again, I don’t see the advantage of the integration other than the cachet associated with being an official part of Emacs.

When aggelos made this same point in the comments, about half of the respondents agreed with him. The other half cited such issues as having the copyright assigned makes copyright enforcement easier. Perhaps, but if that’s the issue then why not address it rather than fussing about integration?

I don’t see a pressing need—or even a non-pressing need—to integrate Magit into Emacs. Having it separate does not, as LWN ludicrously claimed, hinder its wider distribution. Just about everybody in the intersection of Emacs and Git users is already using it. The holdouts have their own reasons for not using Magit and I doubt integrating it will change their minds.

Doubtless, many of you will disagree. I’m interested to hear your reasons.

Footnotes:

1

Just recently Bastien celebrated the fact that the latest version of Org mode had finally been added to the Master branch but we can be sure it will be out of date by the time Emacs 26.1 ships.

Posted in General | Tagged , | 16 Comments

Tabula

Back in early July, I wrote a rant disagreeing with Robert Zaremba about retiring the use of PDFs. Zaremba believes that PDFs are no longer a good fit for today’s devices and that we should stop using them. I strongly disagreed. In the comments to my post, Mike Zamansky zinged me by noting that “PDFs are where data goes to die.” His point, of course, is that it’s pretty hard to get data out of a PDF.

Now, finally, I have a rejoinder: Tabula, a tool for extracting PDF tables into CSV data. Once you’ve got it in that format, it’s easy to convert it into others such as an Org mode table. That should be especially handy for researchers who like to write their papers in Org mode.

The problem of extracting table data from a PDF turns out to be surprisingly difficult. Follow the Tabula link to read about some of the problems. Regardless, Tabula can (usually) do it and help researchers capture data from a PDF in a relatively painless and accurate way.

Posted in General | Tagged , , | 3 Comments

Cash and Smart Phones in China

Back in May, I wrote about the central role that Smart Phones play in the day-to-day life of those in mainland China. In particular, you are considered odd if you try to pay for just about anything with cash. Now, The New York Times has an article that serves as a nice followup.

According to the Times, cash in urban China is rapidly becoming obsolete. This evolution has been remarkably swift: three years ago, cash was used for most transactions. Now, as I said, its use is considered odd. The secret to the fast uptake and near universal acceptance of digital payments is the use of QR codes. Instead of expensive card readers, merchants simply provide a print out of a QR code that the customer scans with his smart phone. That means that even very small merchants—even street musicians—can accept digital payments with virtually no cost other than the transaction fee.

The author of the article says that, so far, this trend has not moved outside of mainland China, not even to Hong Kong. I look forward to seeing its use spread to the West, although as I said in my original post, I hope it’s not through single portal like WeChat that has privacy implications.

Posted in General | Tagged | Leave a comment

Goodhart’s Law

Kontra has a useful reminder:

We see applications of this all the time. One famous example is the notion that we should use standardized tests to measure teacher/school effectiveness and base compensation/budgets appropriately. It’s one of those ideas that sounds good when you first hear it—who isn’t for rewarding more effective teachers, after all—but in reality those being measured soon learn how to game the system and we end up with “teaching to the test.”

We see it in our own industry every time some bean counter decides to evaluate programmer productivity by counting lines of code committed or some equally silly measure. Whatever the metric, programmers soon learn to maximize it even if the result is less and poorer quality work getting done.

The idea that making some measurement a target results in the measurement becoming useless is so common that it even has a name, Goodhart’s Law. It’s one of those things that everyone knows but always fail to take into consideration when starting out to measure some human activity with the aim of affecting policy in some way that matters to those being measured.

Posted in General | 3 Comments

John Wiegley and Sacha Chua on use-package

A couple years ago, John Wiegley and Sacha Chua made a video about Wiegley’s use-package package. I’ve mentioned it a couple of times in passing but never written about it. Recently, I stumbled across it again and rewatched it.

There’s a lot of interesting material in the video and I decided that even though it’s old it was worth writing about. If you aren’t already using use-package, you should definitely take a look. The package really does make your configuration simpler and more logical. It can even be used to speed up Emacs’ start time: Wiegley reports that he has over 200 package and his Emacs starts in about a third of a second.

Even if, like me, you’re already using use-package, there’s still a good reason to spend a half hour watching the video. Wiegley discusses some things I didn’t know about. First is the macrostep package. If you only use it to see exactly what use-package is doing, it’s worth installing. The use-package macro confuses many people. If you watch the video and then expand an invocation of the macro in your configuration, you’ll easily understand what’s going on. It’s really easy to use and if you bind a key sequence to invoke it1, it won’t be loaded until you need it.

Another thing I learned is that you can fold the text in a buffer so that any text that starts more than \(n\) columns from the left margin isn’t shown. Oddly, this is a built in functionality (bound to Ctrl+x $) so you don’t need to get anything to use it.

Once you start using use-package, you’ll automatically pull in bind-key so you’ll have describe-personal-keybindings available. When you invoke it, you’ll get a nice list of all the keybindings you’ve defined along with what, if anything, they replaced. That can be really handy for organizing your configuration.

Finally, one of the nice things about use-package is that you can configure it to record how long it takes to load and configure the packages it loads. That can really be handy for tracking down the hot spots in your configuration load time. It all goes into the *Message* buffer so you can ignore it except when you need it.

I really like use-package and have converted my entire init.el to use it. If you aren’t already using it, you should start and the video will go a long way towards convincing you of that.

UPDATE [2017-07-21 Fri 11:58]: Added link to video.

Footnotes:

1

Or you can ask use-package to delay loading it explicitly.

Posted in General | Tagged | 17 Comments