Baby steps to buffer manipulation without UI stuff getting in the way?


#1

Hi there.

So I’ve been using Atom for a few months, and it’s about time to hack on it. Problem: I’m not primarily a web/UI guy, so even though I know basic CSS and JS, most of the way I write code is data stuff in Python.

What I’d really like to do is write a very simple package that takes either highlighted text or the entire buffer, pipes it directly as a string to an external script, which does its work and then sends a string back (standard streams are our friends?) to atom, to replace highlighted text/entire buffer.

So I look at the official docs for package creation, and the wordcount walkthrough, and it’s all like “here’s all this DOM manipulation you need to do,” and “here’s how you get menu items,” and “here’s what needs to be in your view class” and I’m like “but I don’t want to do DOM manipulation or create a view or anything else, I just wanna pass a string to a script.”

And buried in there I can see the methods I want — it looks like atom.workspace.getActiveTextEditor().getText() will give me the entire buffer, but can I get at that and pipe it somewhere without messing around with all the UI/DOM stuff?

I’d appreciate any tips anyone has! Thanks!


#2

You may want to take a look at the API documentation:

Where you will find things like:


#3

Thanks! I’m mostly confused by I/O rather than the stuff in the API docs— like once I manage to get a string, how do I pass it to stdout or somewhere else where resources outside of Atom can get at it? Or am I thinking about this the wrong way… (like, if this were a webpage, I’d have to use some kind of ajax call to do it, but it’s not a webpage, it’s a local application that’s written in javascript, which just confuses me like woah…)


#4

Well, the thing to keep in mind for stuff like that is that Atom is built on top of Node.js. So techniques that work for Node.js will tend to work for Atom (perhaps with some modifications). There are a number of discussions on the forum here about how to work with child processes:

https://discuss.atom.io/search?q=child%20process


#5

Aaah. Thank you—as a total node newbie, that might be just the little pointer I needed.