Miskatonic University Press

Pretty symbols in Ruby in Emacs

emacs ruby

Ruby scripts in Emacs can look nicer with prettify-symbols-mode, which is now built in to ruby-mode. With symbol prettification enabled, symbols are made prettier to the eye. For example, this is a Ruby script. Note the >=, <= and lambda (a lambda function is a special thing in computer science).

if 2 >= 1
  puts "Two is greater than or equal to one."
end

foo = lambda { |i|
  if i <= 0
    puts "#{i} is equal to or below zero"
  end
}

With symbols prettified, this will appear like so, even though the real characters are actually there:

if 2  1
  puts "Two is greater than or equal to one."
end

foo = λ { |i|
  if i  0
    puts "#{i} is equal to or below zero"
  end
}

I’ve been prettifying R for seven years, and it’s nice to be able to do it in Ruby now. I use it in Org and AUCTeX, too. In my Emacs configuration I make it work so:

(global-prettify-symbols-mode 1)
(setq prettify-symbols-unprettify-at-point 'right-edge)

I’m very happy to say this got in place because I submitted my first patch for Emacs. What I sent in was actually unhelpful and misleading, but a few people looked at it, thought about it, made it better, and updated the code. Many thanks to them! If you run Emacs from the development source you can see this in place now; others will wait until version 28 comes out officially.

While I’m at it, let me thank Keith Browne for introducing me to Emacs. One day in 1994 at Internex Online (Toronto’s first commercial dial-up internet service provider), I was looking at Keith’s screen—he was probably working on the billing system, which he’d named Funes—and asked what editor he was using. It was Emacs. I said I’d heard about Emacs, but it seemed really complicated to learn. He asked what I used. I said Pico. He pointed out that Pico had about six keystrokes, so all I had to do was learn their equivalents in Emacs, and then after that I’d have the whole rest of Emacs to grow into. This made perfect sense, so I switched and have been a happy Emacs user ever since. Wherever you are, Keith, thank you.

UPDATE (01 Jun 2021): Fixed where I said ≤ is just less than, not less than or equal to.