Upgrade Your Emacs-fu

Emacs is pretty twisty

There’s a huge number of things it can do to make your dev experience more amazing, but they’re not exactly obvious, either. (meta-shift-5 anyone?) You’ve probably found a bunch of these and already use them, perhaps like:

Ctrl-x 3 Split window vertically
Ctrl-r Search backwards
Meta-x shuriken-mode Transform your text editor into a highly concealable throwing blade with which to destroy your enemies

But there’s way more cool features lurking out there that we don’t hear about.

Having gaps and bumps in your daily workflow is frustrating and unsatisfactory

Wherever you’re at, I imagine you can sense that there’s a lot more you could learn that would improve your productivity and give yourself a greater feeling of mastery. But the flipside is that we experience frustration and dissatisfaction daily from the parts of our workflow that don’t work quite right. Ever find yourself wondering why you’re performing a repetitive operation on your code, when your computer ought to be taking care of that for you?

It’s hard to set the time aside to learn this, when you have code to ship

But it’s really important, too, especially when you consider how time we spend writing and editing code. We spend an inordinate amount of time in front of our editor of choice, and any frustration we feel using it will leak into the rest of our lives.

I worked this out personally, and I spend, on average, a scarily large portion of my life using emacs:

I’m a freelance ruby developer.
I aim for six hours of billable work per day.
Let’s estimate that I spend two thirds of that time editing (the rest goes into running tests, deployment, etc.)
That’s four hours per workday using emacs, or almost a fifth of my waking life if you assume I’m not coding on the weekends.
Woah, that’s a lot of time spent up close and personal with emacs.

Any frustration I feel about something not working quite right, I’m going to feel multiple times per day, every day I code. And you’re probably in the same boat.

Enter Emacs-Fu

I was frustrated by not being able to find a coherent, guided, step-by-step course on Emacs, so I went on a mission to upgrade my Emacs-fu and to record what I learnt as I went. Emacs-fu is the intermediate-level email course that came out of that. Here’s some benefits you can expect from the course:

You can jump straight into learning without getting distracted looking up tips

Time is already scarce enough as it is, and if the internet gets any more distracting, half our society will probably be diagnosed with ADD. Emacs-fu collects a bunch of useful tips and techniques together into one place so you can jump straight into the learning without getting lost in the interwebs.

Emacs-fu is designed to stick

Emacs-fu is designed to help you form lasting habits so you can be more productive without thinking about it. The course is broken up into bite-sized lessons and that are spaced a week apart. During each week, you’ll practice (as part of your regular development) the most valuable things you took from the previous lesson. That builds a habit, and once the habit’s in place, you’ll be able to benefit from it without thinking about it, just like you do with the editing habits you already have. When you’ve forgotten about Emacs-fu, you’ll still have the habits you gained from it.

The content’s simple and applicable every day

Here’s what’s covered:

  1. Introduction and basics
    • Explanation of shortcut key notation
    • Summary of useful functions / key combinations (eg. manipulating windows, running shells, using macros)
  2. Nifty built-ins
    • Looking up functions in help
    • Aligning text quickly and easily
    • Repeating keys and functions
    • Commenting regions
    • Selecting and indenting
    • Cursor movement
    • Auto-complete
    • Changing the case of words
  3. Regular expressions
    • Testing your regular expressions
    • Searching and replacing by regex
    • Moving between the regex syntax of Ruby/Perl and Emacs’ own flavour
  4. Configuration
    • Looking up configuration variables in emacs help
    • Where to store configuration files
    • File backups
    • A short diversion into lisp syntax
    • Key bindings
    • Indentation
    • Mode-specific configuration
    • Some useful plugins

It’s a really easy win

Emacs-fu is $29 for the course. Even if you learn just one thing that makes a small difference to your workflow, you’ll get that benefit every time you use it. And if you’re using emacs for your daily development, that’s a lot of benefit from a small change.

$29. Four-part email course. Ninjas. Click the button to get in on it.

Buy Now

PS. There are eleven ninjas hiding in this page. Nine of them use emacs. Can you tell which are which?

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Emacs-fu table of contents

I’ve been pulling everything together for the launch of Emacs-Fu, which greets the world on Friday (there’s a signup form for the discount email list at the bottom of this post) . Today I have the table of contents for the course to share with you.

Emacs-fu

  1. Introduction and basics
    • Explanation of shortcut key notation
    • Summary of useful functions / key combinations (eg. manipulating windows, running shells, using macros)
  2. Nifty built-ins
    • Looking up functions in help
    • Aligning text quickly and easily
    • Repeating keys and functions
    • Commenting regions
    • Selecting and indenting
    • Cursor movement
    • Auto-complete
    • Changing the case of words
  3. Regular expressions
    • Testing your regular expressions
    • Searching and replacing by regex
    • Moving between the regex syntax of Ruby/Perl and Emacs’ own flavour
  4. Configuration
    • Looking up configuration variables in emacs help
    • Where to store configuration files
    • File backups
    • A short diversion into lisp syntax
    • Key bindings
    • Indentation
    • Mode-specific configuration
    • Some useful plugins

To get a discount and early access to the course, plonk your email down here:



Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Your Intention Stack

Have you noticed the seam between habit-land and your editing software?

Habit: I want to go to the start of the next line – <end> <right>
Software: moves the cursor around

Habit: I want to tidy up that bit of code
Software: indent region

When we’re working, we have a stack of intentions. Mine, for one project I’m working on, looks like this:

  • Business problem: We want to mitigate the new year slump in sales
  • Proposed solution: Let’s implement a coupon codes feature and run a promotion with it
  • Story: I want to display the discount at the checkout after the code’s been entered (*failing acceptance test*)
  • Unit test: I need a way to calculate the discount
  • Code: Write a method to do that
  • Editing: Type some code, refactor it a little, indent everything
  • Habit: Press this key, press that key
  • Software: Perform those edits

Each of these layers is a world in itself, but today I’m particularly interested in the seam where our intentions meet software. How much of our editing do we perform inefficiently in habit-land when we could push it down to the software layer? When we want to indent some code, are we mindlessly indenting every line individually when there’s a feature to indent the whole region in one go? Is this a common code construct that could be inserted with a snippet instead of typing it every time? Could we write an emacs lisp function to perform that mini-refactor every time we need to?

With attention to this interface between our intentions and our code, we can minimise the friction at that interface and make the experience of coding that much more joyful.


Next week, I’m releasing Emacs-fu, an email course on emacs designed to stick with you and make your editing more flowy. Pop your email down here and you’ll receive an awesome-blog-reader-person discount:



Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Learning emacs movement keys

One of the techniques I share in Emacs-fu is the post-it note technique. I originally found it in a PeepCode screencast, and I’ve been using it since then to learn new keyboard shortcuts. The idea is to write down the thing you’d like to learn on a post-it and keep it near your computer or on your laptop next to your keyboard.

I found it to work especially well with learning new things (say C-x r k for rectangle delete). Recently, I’ve been using it to learn the alternative navigation keys. The theory is that emacs has some shortcuts bound to cursor movement that replace the regular arrow keys and home / end / pgup / pgdn. The supposed advantage is that you don’t have to move your hands from their regular typing position to use these shortcuts, so I expect that I’ll get at least a small payoff if I can get them ingrained. Two weeks ago, I stuck a post-it with the shortcuts on my laptop, and since then my habits haven’t shifted much. I’ve used C-n and C-p occasionally, but not enough for it to become a long-term habit.

The problem is that I have an addiction to the arrow keys, and unlearning it is painful – it makes me think about editing when I’d rather be thinking about the code, which is frustrating. I tried blocking out ten minute segments where I’d only use the bindings, but I didn’t end up doing that very often. So I came up with an idea – how about I unbind the arrow keys? That way I’d be forced to learn the new keys. A few minutes later:

(global-set-key (kbd “<up>”) ‘ignore)
(global-set-key (kbd “<down>”) ‘ignore)
(global-set-key (kbd “<left>”) ‘ignore)
(global-set-key (kbd “<right>”) ‘ignore)
(global-set-key (kbd “C-<up>”) ‘ignore)
(global-set-key (kbd “C-<down>”) ‘ignore)
(global-set-key (kbd “C-<left>”) ‘ignore)
(global-set-key (kbd “C-<right>”) ‘ignore)
(global-set-key (kbd “<home>”) ‘ignore)
(global-set-key (kbd “<end>”) ‘ignore)

This feels like just the right amount of force to overcome the habit. If you’re super-determined, this will do the trick.

Hello hello! You can find a bunch more nifty emacs tricks in Emacs-fu. Launch imminent!

Pop your email down here. You’ll get more tips about emacs and access to an early copy of Emacs-fu with a discount:



Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

How much does it cost to attend Burning Man from Australia?

TL; DR: $3,000

The Details

Thinking of travelling to the US from Australia to attend Burning Man? Daunted by how much it might cost to get yourself over there and buy all the supplies you need to survive a week in the desert, decked out in fun fur and EL wire? Worry no longer, because it turns out that it’s surprisingly affordable. Here’s the breakdown:

  • Burning Man Ticket (early round): $443
  • Plane ticket (return): $1193
  • ESTA (VISA waiver): $14
  • Travel insurance: $141
  • Expenses in USA: $1221

Total: $3,012

(All prices in $AU)

Not too painful at all. You can do it! See you in the dust!
Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Writing controller tests for Spree controllers

Without configuration, using Spree 1.1.1, rspec controller tests for spree controllers fail:

Failure/Error: get :select, :id => d.id
ActionController::RoutingError:
No route matches {:id=>"39", :controller=>"spree/distributors", :action=>"select"}

As mentioned in a related github issue, this is because the engine’s routes are not included by default in the rspec environment. However, the solution suggested there (using spree_api’s ControllerHacks module) is out of date. Instead, investigate spree_core/lib/spree/core/testing_support/controller_requests.rb, which begins with some instructions to include the helper in your rspec environment and then use the spree_get, spree_post, spree_put and spree_delete methods to access spree controller actions. In spec_helper.rb:

require 'spree/core/testing_support/controller_requests'

RSpec.configure do |config|
  config.include Spree::Core::TestingSupport::ControllerRequests, :type => :controller
end

Once I had that working, there was one other problem I ran into:

Failure/Error: spree_get :select, :id => d.id
NoMethodError:
undefined method `authenticate' for nil:NilClass

This was easily resolved by including Devise’s controller spec helpers, like so:

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

After which, my tests began running (and in this case failing) in the correct manner. Hooray!

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Faster emacs key repeats

My secret intent behind creating a course on emacs was to become much more proficient with it myself. One of the course beta testers, Jack Kelly (software engineer turned pirate) mentioned something really spiffy that I hadn’t heard before.

In the second lesson, we cover C-u which (among other things) can be used to repeat keystrokes, like this: C-u 80 *. However, it turns out that you can leave off the C-u prefix and achieve the same thing by holding control while typing the number, like so: C-8 C-0 *.

Now your crafting of comment headers and ascii art can be that much more enjoyable.

Emacs-fu launches on the 1st of May. Sign up and impress us with your emacs-crafted ascii art.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Using Spree and Refinery together

The combination of Spree and Refinery is promising for e-commerce sites incorporating some CMS pages. I recently ran through the process of installing both of these engines and configuring them to play nice with each other. You can do this too!

Firstly, a note on versions. For this guide, I’ve use Rails 3.2.3, Spree 1.1rc and Refinery 2.0.2. I’ve used the Spree 1.1rc instead of the stable 1.0.x version because the stable version depends on Rails 3.1 and Refinery 2.0.x expects Rails 3.2. The Spree 1.1rc is Rails 3.2 compatible, so our whole project can happily run on Rails 3.2.

Install Rails

$ rails new spreefinery
Uncomment therubyracer in the Gemfile

Install Spree 1.1rc

$ cd spreefinery
$ spree install --git=git://github.com/spree/spree.git --branch=1-1-stable

Install Refinery

Add to Gemfile: gem 'refinerycms', '~> 2.0.0'
$ bundle install
Comment out the Spree lines in db/seeds.rb to avoid double-seeding Spree
$ rails generate refinery:cms --fresh-installation
Uncomment the Spree lines in db/seeds.rb

Reference: http://refinerycms.com/guides/with-an-existing-rails-app

Patch will_paginate

Refinery uses the will_paginate gem for pagination, while Spree uses Kaminari. Unfortunately, these two gems are incompatible. To work around this, add the following to config/initializers/spreefinery.rb:

if defined?(WillPaginate)
  module WillPaginate
    module ActiveRecord
      module RelationMethods
        alias_method :per, :per_page
        alias_method :num_pages, :total_pages
      end
    end 
  end
end

References:

Configure routes

I wanted my home page and an about page served by Refinery, and the products page served by Spree. To accomplish this:

Mount Spree before Refinery in config/routes.rb
Above both engine mounts, add:
root :to => "refinery/pages#home"

You should now have Spree and Refinery running together. There’s room for some further improvements to this configuration, since Spree and Refinery still use their own authentication systems and layouts, but it should be enough to get started with.

Become so much more better at emacs. Maybe not grammar, though.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Introducing Emacs-fu

TL;DR

  • There’s lots to learn about emacs.
  • I learnt some of it and made a course.
  • It’s coming out 1st May and it’s going to be awesome.
  • Put your email down at the bottom of this post to be the first to hear when it’s ready.

There’s a lot to Emacs

There’s so much I don’t know about it. I’ve been using emacs as my main editor for who knows how many years, so I’m pretty comfortable with it. But I started to get frustrated with a few work habits that seemed embarrassingly clunky, and there was a growing feeling that I was actually doing a lot of things the slow way.

On top of this, I’d been dancing around Lisp ever since reading Paul Graham’s gospel writing on the subject. Never quite learning it properly, but interested enough to read up on it. And of course emacs uses its own flavour of lisp at the core, so the glimmering possibility of being able to shape my editor was definitely alluring. But I hadn’t actually reached the point of, you know, actually writing any lisp.

So here I was, basically frustrated with my work habits and non-ninja-ness.

So I went out and learnt a bunch of stuff

A bunch of screencasts, tutorials, features, shortcuts, customisations. I dug through them, kept track of the bits I found useful, and kept them post-it noted on my laptop until they’d sunk in. I haven’t reached any sort of mastery, but it was definitely an upgrade.

I wrote down the good stuff

I made a course, in fact. An email course, in four parts. An email course is perfect for this because you can become a lot more effective with emacs by learning new habits. An email course, with an email every week, is ideal for that because you get plenty of time to practice and internalise each week’s lesson before moving on to the new stuff. Once the new habits are internalised, you don’t have to think about them and you just automatically do the new, more productive thing.

The course consists of four emails, one per week. Here are the lessons:

  • The Basics – get the fundamentals down for speedy editing
  • Nifty built-ins – extend your repertoire of nifty functions
  • Regexp – get your head around emacs’ very special flavour of regular expressions
  • Customisation – tweak emacs to your liking

The course is at an intermediate level. It starts off with some basics to fill in some gaps, but doesn’t dwell there, moving on to more interesting topics. It’s also not super-advanced. There’s a touch of lisp in the last section, but the focus of that lesson is not on the lisp technicalities, but on getting emacs customised to your liking.

There’s lots of good stuff there. It’s going to be awesome, and it’s coming out 1st May. Pop your email in this box and I’ll let you know when it’s ready.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter

Relative money buckets

Leaving out edge cases, no matter what your level of financial abundance, there’ll always be things that fall into each of these buckets:

  • Easy to afford. You don’t even think about it. For example, if you work full-time, you can probably buy yourself a coffee without considering your budget.
  • Save for it. You might have to save for a little while, and you’re not comfortable buying things in this price range on impulse, but you know that you’re capable of achieving these savings goals.
  • Hard. You can afford these things, but they’re at the edge of what you consider possible for you. An example might be an expensive holiday that you feel you can only make happen once every few years.
  • Seemingly impossible. Things you don’t consider possible for yourself. A private jet, your own skyscraper in the CBD, etc.
When you’re income goes up a notch, the things you might spend money on drop down into a more achievable bucket, but the buckets remain the same. If you develop a good relationship with the purchases you make in each bucket, that relationship will serve you well no matter your income level.
Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Twitter