Skip to content

Instantly share code, notes, and snippets.

@stdavis
Created November 28, 2016 17:46
Show Gist options
  • Select an option

  • Save stdavis/d7b7e9b949a6566efbacbd7c6ef022bb to your computer and use it in GitHub Desktop.

Select an option

Save stdavis/d7b7e9b949a6566efbacbd7c6ef022bb to your computer and use it in GitHub Desktop.
object function console log
atom.commands.add('atom-text-editor', 'custom:conlog', function () {
editor = atom.workspace.getActiveTextEditor();
const modName = editor.getTitle().split('.')[0];
const folder = path.basename(path.dirname(editor.getPath()));
const currentPoint = editor.getCursorBufferPosition();
let funcName;
editor.scan(/(\S*): function?\s\([\s\S]+?console.*/g, function (iterator) {
if (iterator.range.containsPoint(currentPoint)) {
console.log('found');
funcName = iterator.match[1];
iterator.stop();
}
});
const txt = `console.log('${folder}/${modName}:${funcName}', arguments);`;
const checkpoint = editor.createCheckpoint();
editor.setTextInBufferRange(editor.getCurrentParagraphBufferRange(), txt);
editor.autoIndentSelectedRows();
editor.groupChangesSinceCheckpoint(checkpoint);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment