A Guide to Light Table’s Watches

Brian Zindler
3 min readOct 21, 2014

--

Light Table watches are a great feature in the Light Table IDE, but it is a little difficult to understand what they are, and how to get started using it. Below I’ve tried to help you understand LT watches, and how to use them.

This guide assumes you are familiar with the Light Table environment, and know how to evaluate code in LT. If you want to get set up in Light Table a good tutorial is here.

What are Watches?

Watches are meant to be an improvement upon printing to the console for debugging. LT watches allow you to highlight a section of your code, and hit Alt-W to watch that section of the code. While code is being watched the last result of the code is printed next to the watched value. A watch can be removed with Alt-Shift-W. Watches are available for Clojure, Clojurescript, Javascript, and Python.

Why use Watches?

Differences. Some aspects of watches are an improvement over console printing. To print in console you need to change the text of your code, and insert a print statement. watches require no code changes. Additionally, watches are always shown right next to the value they are watching, logs are typically in another area. This is especially nice when using multiple watches. You always know where the values are coming from.

Some of the drawbacks of watches are that they do not log the previous values. Also, watches can become messy if you are trying to observe a large function.

How to use Watches

https://www.youtube.com/watch?v=nOTuSkTK_PE&feature=youtu.be

You will notice that when I watch the variable called collection the value of data changes even though I did not evaluate the for loop. In fact we did call the for loop. When you put a Watch on a line of code it evaluates the block of code that the Watch resides in. This is especially dangerous in languages with mutable data like Javascript. We see above that evaling the for loop twice changes the values of the collection, and data variables.

Another potential gotcha of watches is figuring out what is ok to put a watch on. A good rule of thumb is that you can only watch something that evaluates to a value.

Watches are especially cool when you are trying to observe streaming values like events.

https://www.youtube.com/watch?v=w0724Kokl-k

Custom Watches

Light Table allows you to customize your watches. Unfortunatley, right now they only work in Clojure, and Clojurescript. You can set up a custom Watch by going to the user keymappings. Select any key mapping you want to, and enter the type :editor.watch.custom-watch-selection as below.

The block of text is the code that is evaluated. “__SELECTION__” is the block of text that is selected. The code in between “_| |_” is the output of the Watch. The :class is a class that can be used to style the color of the Watch underline. :verbatim determines whether or not the value in between “_| |_” has pr-str applied to it or not. [1] “__ID__” gives you the unique id of a specific Watch. So if several watches are on a page at once you can tell them apart. [2]

Rolex

Most people will not want to create custom watches. Luckily, there is a plugin called Rolex that collects useful custom watches. Additionally Rolex provides better facilities for defining custom watches. You can get Rolex by going to the plugins menu in Light Table.

--

--