Changing an Atom Setting Through Code


#1

I’m trying to change an Atom setting via code, but I can’t seem to figure it out. I’m trying to change the Preferred Line Length setting. Here’s the code I’m currently running.

let editor = atom.workspace.getActiveTextEditor()
editor.preferredLineLength = 80;
console.log (editor.preferredLineLength);

Now, the console outputs the value 80 (even if the setting wasn’t set to 80 before), so it seems as if it is changing the value, however, nothing in the editor actually changes. When I check the settings page, the Preferred Line Length hasn’t changed. I’m not sure what I’m doing incorrectly.

Any help is much appreciated.


#2

You have to use the atom.config API to change configuration settings. The fact that the editor has a copy of the preferred line length is probably just for convenience in getting that information; it is not the actual setting.


#3

Thank you very much DS. Yeah I’m not very familiar with JavaScript or Atom dev and sort of made a bad assumption that getActiveTextEditor() returned a pointer to this structure. I’ll dig around that API when I get back to my comp! Thanks! :slight_smile:


#4

That’s not a bad assumption. It’s true. The bad assumption was that the word wrap uses the property on the TextEditor to determine when text gets wrapped. It certainly could, but it doesn’t, as your experiment demonstrates. If it did, it would be convenient for certain uses such as wrapping different editors at different points.


#5

Thank you very much again! Also, are these docs available in a repo somewhere? I found a few typos I could fix and can’t seem to find a source for them.


#6

They are inline with the source code


#7

Found it, thank you!