Zamansky on Keyboard Macros

Mike Zamansky has another video up in his Using Emacs Series. This time it’s about keyboard macros. I’m always inclined to think that everyone knows all about them but I keep reading tweets about people discovering their power and being amazed so Zamansky’s video is apt to be useful for many people.

If you aren’t using keyboard macros, you’re almost certainly working too hard. Zamansky gives a couple of examples that show how macros can make quick work of repetitive tasks. Often you can accomplish these tasks with something like multiple-cursors but keyboard macros are built in and always available. Zamansky compares them to a Leatherman but I like the Swiss Army Knife analogy better. In either case, the point is that macros are a flexible and powerful tool to quickly get things done. As Zamansky says, there might be a better tool for a particular task but macros are almost always good enough.

Take a look at the video to see a few more tricks like counters and saving macros. The only thing I would add is that the ability to repeat the macro a fixed number of times or until the end of the buffer is often useful. On the other hand, as Zamansky says, usually it’s just as easy to manually repeat the macro the required number of times.

As usual, the video is short—11:31 (min:sec)—so it should be easy to find time to watch it.

Posted in General | Tagged | Leave a comment

Computerphile: Unrolling Loops

Professor Brailsford of Computerphile has an interesting short video on unrolling loops. He motivates the discussion by relating a story about the introduction of the Laserwriter. John Warnock, from Adobe, and Steve Jobs planned to show off the Laserwriter’s capabilities by having it print a U.S. tax form. The problem was that the form is visually complicated and took a minute and 20 seconds to print.

Jobs felt that that was too long for an effective demonstration so Warnock took the PostScript file and removed all the procedure calls and unrolled the loops. The new file printed in 20 seconds, only 25% of the initial version.

Brailsford goes on to explain how unrolling loops can dramatically increase the speed of your code. Of course, doing so violates all sorts of rules about properly structuring your code so it’s something you should do only for critical code paths. He also mentions that once you get away from trivial programs, manually unrolling loops is too burdensome so he introduces the notion of translation programs to do the unrolling.

He demonstrates all this by writing a short PostScript program and then unrolling the loop inside it. His notes for the video contain the PostScript program, the flattened version of it, and the PostScript program to automatically unroll loops.

It’s an excellent video and just short of 10 minutes so it’s easy to find time for it. Don’t worry about the program being in PostScript; Brailsford explains everything you need to know.

Posted in General | Tagged | Leave a comment

Random Medical News

From John Cook we have this bit of humor that also has the feel of truth:

I’m old enough that I can remember at least 3 cycles of

  • Coffee is good for you and prevents heart disease and other ailments.
  • Coffee causes heart disease and cancer.

Basically, I’ve stopped listening. For years butter was really really bad and you should eat margarine if you must have a butter-like spread. Now, it’s margarine that’s bad and butter is all right after all.

The best medical advice is eat what you like: sooner or later someone will publish a study showing it’s good for you.

Posted in General | Tagged | Leave a comment

Escaping Org Examples in Org

From Karl Voit we have this really useful piece of advice:

If you follow the link to Stack Overflow you’ll discover the proper way to include Org markup as an example in an Org file. For a trivial example of this see yesterday’s post in which I included a small bit of Org markup.

The idea is that you put the example in an Org source block rather than, say, an Example block:

#+BEGIN_SRC org
* A heading
** Subhead
   With a bunch of other stuff
#+END_SRC

but that’s not quite enough. In my Org source file for this post the above was entered as:

#+BEGIN_SRC org
  ,#+BEGIN_SRC org
  ,* A heading
  ,** Subhead
     With a bunch of other stuff
  ,#+END_SRC
#+END_SRC

As you can see, the Org markup that you want to appear as the example (and not be acted on) is escaped by a comma. Although the Stack Overflow post does not make it clear, the easy way to do this is to insert the #+BEGIN_SRC org and #+END_SRC markers and then call org-edit-special, which is normally bound to 【Ctrl+c '】, and enter your Org example without worrying about escaping. When you finish by typing 【Ctrl+c '】 again, Org mode will automatically add the escaping for you.

I’m really glad to learn this trick. Trying to add Org mode markup in an example never worked well for me. Yesterday, I saw Voit’s tweet and, serendipitously, was able to use it immediately in my next post.

Posted in General | Tagged , | 1 Comment

Two New König Videos

Rainer König has posted two new videos in his OrgMode Tutorial series. Unfortunately for him but fortunately for us it’s raining in Augsburg so König has had to forego gardening in favor of making more of his excellent Org Mode videos.

This time he discusses dynamic blocks and habit training. Unless you’re really an Org mode expert, there’s sure to be a lot of things you didn’t know in the videos.

The first video talks about dynamic blocks. You may be familiar with them for displaying clocking data but they turn out to be much more general. It’s easy to set one up: you just add

#+BEGIN: function <parameters>
#+END:

to your Org file. The function identifier on the #+BEGIN: line represents the name of the function to generate the dynamic block. You can add parameter name/value pairs if necessary.

There are two builtin functions—clocktable and columnview—to cover the common cases of building dynamic blocks of clocking data and columnview representations. These are useful since the clocking data and columnview representations are normally buffer overlays and there’s no way to capture or export them. By building a dynamic block you get normal text that you can process however you like. See the video for the details on how to generate these dynamic blocks. There are keyboard shortcuts so you don’t have to bother with adding the #+BEGIN:/#+END: markers.

The second video considers habit tracking. The idea is that you have some periodic task that you want to establish as a habit—practicing an instrument, say—so you tell Org mode that it’s a habit you want to track and how often you want to do it and Org mode will provide a nice graphic in your agenda tracking your performance. You handle them just as you would TODOs. When you complete a task you mark it complete and Org tracks it for you. König has an excellent demonstration of this with his own bass and guitar practicing.

As always, these are excellent and informative videos. The two video are 13:12 and 12:37 (min:sec) long so you should have no problem scheduling them. As I’ve said before, these videos are the best introduction to Org mode that I know of and I can’t recommend them enough.

Posted in General | Tagged , | Leave a comment

Configuring Emacs for PHP

Ben Simon has a nice post on setting up Emacs for PHP. I don’t write in PHP and have no plans to start but Simon says it’s hard to get an intelligent setup for it that works for all PHP coding styles.

Simon recommends using php-mode from Melpa instead of the one that comes built into Emacs. That works well for files that are strictly code but for files that have markup he recommends web-mode. He gives his configuration for both packages; they should provide a good starting point for your own setup.

If you like autocompletion, you might also want to try ac-php. Simon shows a configuration for that as well. Simon offers step-by-step installation and set up instructions for each of these packages and says that together they make for a modern PHP development environment.

Posted in General | Tagged | 1 Comment

Common Lisp and Pink Floyd

Common Lisp and Pink Floyd. How could it get better than that?

Posted in General | Tagged , , | Leave a comment

Resistance is Futile…

…you will be assimilated:

Posted in General | Tagged | Leave a comment

Data Sharing in Publications

John Kitchin has a really interesting article in ACS Catalysis on Effective Data Sharing in Scientific Publishing. In it, Kitchin discusses various strategies for embedding supporting data—such as tables and processing code—in a publication’s PDF or source file so that other researchers can recreate the results or use the data for further analysis.

He begins by noting that one can simply embed supporting documents directly in the PDF, \(\LaTeX\) or Word document. The problem with that method is that it’s easy for the actual data and its representation in the final paper to diverge.

A better solution, Kitchin says, is to use Org mode and generate the published tables and results directly from data embedded in the manuscript source. Followers of Kitchin’s blog (or even Irreal) will recognize that this is Kitchin’s longtime publishing process. He and his group write their papers in Org mode along with the supporting data and code. That way, future researchers have everything they need to reproduce and extend the results.

If you’re interested in using Org mode to write papers or in reproducible research, you’ll enjoy Kitchin’s paper.

Posted in General | Tagged , , | Leave a comment

Say What?!?

I don’t have the words…

Posted in General | Tagged | 3 Comments