edmz

View on GitHub

Adding Elixir Support to Quick Look via QLColorCode

Quick Look Sample

I make enough use of Quick Look in Finder that I started to hate the fact that Elixir wasn’t supported by it.

Turns out, it is relatively easy to add support to it using the QLColorCode plugin.

(As a bonus QLColorCode comes configured with support for Erlang, Ocaml and Haskell and other languages)

QLColorCode uses Highlight, under the hood, which is a good thing because it is quite customizable.

Sadly, Highlight doesnt include Elixir support so we need to add it.

Hihglight is embedded in QLColorCode, so we need to download QLColorCode, open its package contents and make some changes.

So, in order to add Elixir support to Mac OS X we need to:

DownloadQLColorCode

You can find it in https://code.google.com/p/qlcolorcode/

Modify QLColorCode

Locate the QLColorCode.qlgenerator file, right click on it select “Show Package Contents”.

Some small changes have to be made to its files.

Add the Elixir language definition

Create a file called exs.lang in Contents/Resources/highlight/share/highlight/langDefs with the following contet:

# Elixir language definition file
#
# Author: Edmz
#   Mail: twitter/edmz
#   Date: 11.9.2014
# ------------------------------------------
# This file is NOT a part of highlight, a free source code converter released under the GPL.
#
# The file is used to describe keywords and special symbols of programming languages.
# See README in the highlight directory for details.
#
# New definition files for future releases of highlight are always appreciated ;)
#
# ----------
#
#

$DESCRIPTION=Elixir

$KEYWORDS(kwa)=begin do end defmodule module def

$KEYWORDS(kwb)=and false then defined module in return redo retry end for true self when
next until do begin unless nil break not case cond alias while ensure or
include use alias fn quote

$KEYWORDS(kwc)=regex((\w+):)
$KEYWORDS(kwd)=regex((\w+)\s*\()

$STRINGDELIMITERS=" '

$SL_COMMENT=#

$IGNORECASE=false

$ESCCHAR=regex(\\\d{3}|\\x\p{XDigit}{2}|\\[ntvbrfa\\\?'"])

$SYMBOLS= ( ) [ ] { } , ; : & | < > !  = / * + - .

Make .ex files an alias of .exs files

Edit the file Contents/Resources/etc/highlight/filetypes.conf and make two changes.

Let highlight know that a file with an .ex extension is also an Elixir file:

$ext(exs)=ex

And, remove the .ex extension from the Euphoria languages alias. Who knew that .ex is also the extension of Euphoria?

Edit the Euphoria aliases and remove the ex extension from its list.

$ext(euphoria)=exw exu ew eu

Lastly, let OS X know that that .ex and .exs files are source code files.

Edit the Info.plist file to add a definition for Elixir files.

OS X needs to know that a file with extension .ex or .exs is a file that contains source code.

I added this block after the Erlang definition:

<dict>
	<key>UTTypeConformsTo</key>
	<array>
		<string>public.source-code</string>
	</array>
	<key>UTTypeDescription</key>
	<string>Elixir Source File</string>
	<key>UTTypeIdentifier</key>
	<string>org.elixir.elixir-source</string>
	<key>UTTypeReferenceURL</key>
	<string>http://www.elixir-lang.org/</string>
	<key>UTTypeTagSpecification</key>
	<dict>
		<key>public.filename-extension</key>
		<array>
			<string>exs</string>
			<string>ex</string>
		</array>
	</dict>
</dict>

Install the plugin

Just copy QLColorCode.qlgenerator to ~/Library/Quicklook, OS X will pick up changes and install it itself.

If you want to uninstall it, just remove the QLColorCode plugin from its directory.