Listen for specific regex on line and insert text


Hey All,

I’ve never posted on this thing before. So go easy on me.

I just thought of a really valuable feature that can help me write some javascript faster and better.

Here it is:

When I start typing the following line of code.

var example = function(

Right when I type the function( in what I’d like to happen is it takes the variable name example and places it after the word function with a space. (no stranger to regex)

So the text becomes.

var example = function example(

This in javscript converts the variable example from being assigned to a anonymous function.

This may seem trivial because you can just declare the function with function example(). Where it comes in handy is here.

var cars = {} = function(

In this example the text line would read. = function carsLexus(

I would also like watch for different keywords. like require.

var expressPromiseRouter = require("express-promise-router")

In this case I’m writing the variable definition in camel case and the name of the module is dashed. I feel like this is the most popular convention.

Ideally atom could lookup possible matches. But in the case of something like this:

var Promise = require("bluebird")

It would totally fail, ideally in this case if I continued typing it would remove the insertion of "bluebird")

Thoughts? Can Atom handle this? Do these processes have a name? Events? Capturing lines? Does something like this exist?


Sure, if coded in a plug-in.

I doubt it but there are so many plug-ins, you never know. You should search on Snippets come close of course but you are asking for super-snippets.


Thanks @mark_hahn

Ideally it was a plugin that could handle rewriting any line like this

var fireEventRegex = new Regex("^var (.+) = require\(") 

fireEventRegex.on("found", function(e){
  e.line = e.line+e.match+"")"

I’d love some direction on how I can make this plugin myself :slight_smile: