How to build GNU Emacs 25.1 on (X)Ubuntu 16.04

Explain how to build GNU Emacs 25.1 on Ubuntu Linux

Now that GNU Emacs 25.1 has been released, it is time for my customary “how to install Emacs 25.1 on a recent Ubuntu” post. In my case I’m using XUbuntu 16.04, but the instructions are pretty much the same for just about every recent Ubuntu version. The package versions of the referenced packages differ, but the package names haven’t changed since I first published one of these posts.

I make sure that the build-essential package is installed, plus to make things easier I’m also installing the build dependencies for Emacs 24. That way the Emacs 25.1 build should have the same options enabled as the official Emacs 24 package you get with Ubuntu.

sudo apt install build-essential
sudo apt-get build-dep emacs24

I already had build-essential installed, but not the build dependencies. Don’t be surprised if apt-get wants to install a fair number of packages as build dependencies – it installed 171 new packages on my machine.

At the same time, you want to download the Emacs sources via the Emacs download page and untar it into a convenient directory. Then it’s simply a matter of running ./configure and kicking off the build:

./configure --prefix=$HOME/local
make && make install

I prefer to install my home-built Emacsen and other binaries into a directory tree that’s user local, hence the –prefix above. That way, I don’t run into conflicts with system packages.

That’s it, a quick check that we have a working version of Emacs 25.1 and we’re in business:

~/local/bin/emacs --version
GNU Emacs 25.1.1
Copyright (C) 2016 Free Software Foundation, Inc.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

Of course I also have the GUI version for the time when I’m not ssh’d into a remote server:

GNU Emacs 25.1 running on XUbuntuHappy Emacsing! I’m off to check out the new features in Emacs 25.

Getting WordPress to work on FreeBSD 10 with PHP 7.0 and Jetpack

This blog is self-hosted, together with some other services on a FreeBSD virtual server over at RootBSD. Yes, I’m one of those weirdos who hosts their own servers – even if they’re virtual – instead of just using free or buying services.

I recently had to migrate from the old server instance I’ve been using since 2010 to a new, shiny FreeBSD 10 server. That prompted a review of various packages I use via the FreeBSD ports collection and most importantly, a decision to upgrade from PHP 5.6 to PHP 7.0 “while we’re in there”.

The basic procedure was as expected – install the basic PHP 7.0 port, then install the WordPress port so that the WordPress port dependency doesn’t pick up an older PHP version. So far, so good – after installing the database server (MariaDB) I was able to import all the posts and comments from the old WordPress instance and was up and running.

There were a few issues though when I tried to connect Jetpack, namely that the xmlrpc service wasn’t working despite it printing out the correct message when trying to access it via a web browser:

XML-RPC server accepts POST requests only.

Turns out that the basic PHP 7.0 + WordPress ports install doesn’t install a few packages that are necessary to get XMLRPC working correctly and that prevented Jetpack from connecting. After a lot of digging through the various log files, it turned out the following packages weren’t installed:

  • php70-ctype
  • php70-filter

I also installed the optional package php70-mbstring – while I don’t expect to start posting in languages requiring multibyte strings anytime soon, I decided I could do without that particular warning message.

The blogging hiatus is almost over

I switched jobs in October last year and getting up to speed in the new role did take priority over anything else, so I had to put a few other endeavours including this blog on hold for a little while.

The publishing frequency will still be lower than previously, but as I have moved from a mostly managerial role back to a pure software engineering role, I will be able to post more articles in line with the original intent of the blog, ie more C++-related articles and of course, the usual smattering of “look what cool feature I found in Emacs”.

Thanks for not removing my blog from your RSS feed reader.

Using the Hack 2.0 font in Emacs on OS X

The Hack 2.0 font got a lot of attention recently as a font specifically designed for use with source code. So of course I had to try it out in Emacs.

I decided to install the font on my Mac, so I downloaded the TTF version of the font from the link above. Installing a new font in OS X is easy – unzip the downloaded file, then double-click on each ttf file that you just unzipped. This brings up the Font Book application. Just click “Install Font” and you’re done.

With the font installed, I needed to find out what Emacs believes the name of the font to be. The easiest way I found was to run M-x ns-popup-font-panel to bring up the OS X font picker, select the freshly installed Hack 2.0 font and then run M-x describe-font to pick out the correct name.

I plan to use the font for a little while to see how I like it so I wanted to tweak the default font setting to use the Hack 2.0 font as the default font. In my case, I only wanted to tweak the OS X settings part of my global .emacs, at least until I have the font installed on Linux and Windows also. Inserting the lines below into my .emacs achieves exactly that and sets the default font on OS X systems to Hack:

(when (eq system-type 'darwin)
      (set-default-font "-*-Hack-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1"))

Obviously the above is only a temporary change and once I decided if I am happy with the new font, I really need to set the default font family instead of the default font. However, the above suffices for a quick test.

The difference between Hack and the Menlo font that my OS X Emacs installation picks by default is very subtle. You can see that the height is different and in general, I find the Hack font a tad more readable. You can see a side-by-side comparison in the picture below.

Hack 2.0 and Menlo side by side
Font comparison – Hack 2.0 and Menlo side by side

Don’t make me yawn with your job ad

As a lot of people keep pointing out over and over again, a job ad is an ad. Its often forgotten purpose is to get someone competent excited enough about your company and the job opening you’re trying to fill to send in a well crafted resume with a well crafted cover email[1].

If I read it, I want to know why I should be excited to work at your company, not that I’ll be manually backing up the git server every Friday morning between 4.45am and 5.13am.

Good programmers are really hard to find – especially in the current startup boom – and you’re not going to attract them by putting out job ads that look like they’ve been written by Catbert in one of his fouler moods.

A list of meaningless job duties like “3% of time will be spent swearing at the office Keurig” doesn’t tell me anything about what it’s like to work at your company and especially the team that you are currently hiring for. That’s what all but the most antisocial software engineers are interested in – tell me about the team and the people who make up the team, and tell my why I want to work with them instead of where I’m working now or the myriad of other companies that are also trying to hire a developer right now.

Every software engineer knows that a list of supposed job duties is often meaningless if the organization has any flexibility because over time, the job will get tailored to the intersection of an individuals strengths and the company’s needs. Tell me about that instead.

[1] Of course you’ll also get emails with no content in the mail body and a lone resume attached from people who use a scatter gun approach to job search, but we’re not talking about those kind of candidates here. If you want to attract them, you don’t need to put a lot of effort into the job ad.

Rotate nginx logs on FreeBSD with newsyslog

I’ve moved from using Apache as a web server to nginx for various projects. The machines I’m running these projects on are a somewhat resource constrained and nginx deals with low resource machines much better than Apache does and tends to serve content faster in those circumstances. For example switching the machine that hosts this WordPress blog from Apache and mod_php to nginx with php-fpm improved the pingdom load times on this blog by about 30% with no other changes.

The last piece of the puzzle was to get newsyslog to rotate the nginx logs. The instructions on BSD Start suggest they’re for FreeBSD 10, but they work fine on FreeBSD 9.x as well.

Embedding YouTube vidoes via org-mode

Artur Malabarba over on Endless Parentheses has a short post about embedding a YouTube video directly from org-mode. I haven’t tried using it in org2blog yet, but I’m hoping/expecting that it’ll work there, too.

It’s a very timely post as I’ve got a couple of Emacs related short video tutorials planned that would really benefit from being directly embedded on the blog here.

Building Emacs on OS X using homebrew

I’ve recently switched to using homebrew as my source for Emacs on OS X  after seeing this blog post by Philip Ingram.

It’s a simple way to install a current Emacs once or twice a year. I don’t use beta versions or other pre-release versions, only released versions. My editor is too important a tool for me to risk using pre-release versions.

Good analysis on the Android security ecosystem

I recently blogged about Google and Samsung starting to offer regular security patches for their Android devices.

Over on ars technica, Ron Amadeo has an interesting article describing why the current Android ecosystem is not conducive to the quick and widespread distribution of security fixes and why this needs to change, urgently.

At this point in time it seems that in order to be halfway secure, one has to basically root the phone and run well-tested and well supported distribution like CyanogenMod. While I – and presumably most, if not all, readers of this blog – certainly have the technical know how and abilities to root a phone, that’s a poor approach to security because most people either will not or cannot root their phones.

An elegant way to extract keys from a C++ map

I’ve been doing a reasonable amount of Clojure development recently and like a lot of other Lisp dialect have marveled at the ease of separately pulling out the keys and values from a map. This is a very common operation after all, but C++ does only appear to support manual key or value extraction from a std::map.

Obviously the code isn’t hard to write. In C++11, the following function will return a vector of all keys in a map:

std::vector<std::string> extract_keys(std::map<std::string, std::string> const& input_map) {
  std::vector<std::string> retval;
  for (auto const& element : input_map) {
  return retval;

Same goes for the values:

std::vector<std::string> extract_values(std::map<std::string, std::string> const& input_map) {
  std::vector<std::string> retval;
  for (auto const& element : input_map) {
  return retval;

This being C++, we most likely don’t want to go and write the code every time, so we turn it into a set of templates:

template<typename TK, typename TV>
std::vector<TK> extract_keys(std::map<TK, TV> const& input_map) {
  std::vector<TK> retval;
  for (auto const& element : input_map) {
  return retval;

template<typename TK, typename TV>
std::vector<TV> extract_values(std::map<TK, TV> const& input_map) {
  std::vector<TV> retval;
  for (auto const& element : input_map) {
  return retval;

The code above is reasonably efficient under most circumstances. Yes, you can improve it by calling retval.reserve() to make sure we don’t have to reallocate memory for the vector and make some other small tweaks, but overall, the couple of lines above do the job.

They’re also a lot better than finding the above for loop in the middle of a function. That requires me to scratch my head for a couple of seconds before the usual dim light bulb appears over my head and tells me, “hey, someone’s trying to pull the keys out of a map”. Why is this?

Because just having the loop floating around in the middle of your or my code doesn’t document intent, all it documents is that, well, we have a loop that copies stuff. Even if you wrote the code and then come back to it six months later, this is likely to give you a bit of a pause until you remember what it does. Of course you can put a comment right next to it, but that is also a poor attempt at documenting intent. Not to mention that the comment will go out of date faster than the code itself will. Using a function with a descriptive name is much better as you can then read the code and the function name gives you a reasonable expectation what the code is supposed to do.

Of course, if you use Boost, you can just write this piece of code using the boost range libraries:

boost::copy(input_map | boost::adaptors::map_keys,

It’s probably not going to do Good Things for your compile time, but it’s succinct, readable and documents intent.