dotject Atom Text Editor Plugin

dotject

After yesterday’s post about dotject, it quickly became apparent that although some people may find it useful, they wanted the dotject functionality to be part of an IDE. This was always my intention and it’s now available as an Atom plugin.

Atom

Titled as “a hackable text editor for the 21st Century”, GitHub’s Atom has created some controversy about being a closed-source open-source text editor (yes you read that right). Although the core isn’t open source, developers have the ability to develop plugins and themes to completely change or enhance the way the editor works.

The Plugin

I found it easy to create an Atom plugin for dotject, mainly due to it’s familiarity with npm (it also has a root package.json file etc). Under the hood, it even uses my dotject node package, so there’s no duplication of the dotject code whatsoever.

Installation

Use the Atom package manager, which can be found in the Settings view or run apm install dotject from the command line.

Usage

The default keymapping is shift-cmd-J (although this can be configured). You simply highlight your dotject string and press shift-cmd-J to perform the conversion.

Example

Highlighting a.b.c,d.e then pressing shift-cmd-J will replace a.b.c,d.e with:

1
{"a":{"b":{"c":{}}},"d":{"e":{}}}

The code

It’s essentially 2 lines of code, with a little glue and keymapping:

1
2
3
4
// convert the current text selection
var converted = dotject(editor.getSelection().getText());
// insert the stringified json in place of the selection
editor.getSelection().insertText(JSON.stringify(converted));

This would all be perfect, if it was not for CoffeeScript (I’ve written in JavaScript above).