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

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