Question Regarding Tab Lengths


#1

Hey guys,

Noticed the default tab-length for Python is 4, while I can’t seem to be able to access it anywhere. My config.cson doesn’t seem to hold any information regarding language-specific tab lengths. Specifically, I am trying to access the current active Editor’s tab length and what I am doing is essentially:

const tabLength =  editor.tabLength ? editor.tabLength : atom.config.get('editor.tabLength');

If there is a more preferred method/best practice, I would love to hear it. I am currently checking manually for Python and assuming tab length is 4 in my package.


#2

The settings are defined in the language package itself.


#3

Thank you, I understand. Is there any way I can dynamically resolve the appropriate tab length for a given editor instance? There may be many different packages for the same language but only one is used at that instance.


#4

By that I also mean to ask, can I trust TextEditor::getTabLength() to get the appropriate tab length? Or should I use what I suggested before?


#5

getTabLength() is going to give you whatever the tab length is for that TextEditor object at that moment.


#6

It seems you’re asking two separate questions:

  1. How do I get the current editor’s current tab width?
  2. How do I get the configured tab width for the grammar that is currently selected for the current editor?

TextEditor.getTabLength() is the answer to question 1. The answer to question 2 is in the documentation for atom.config.get():

atom.config.get('editor.tabLength', scope: @editor.getRootScopeDescriptor()) 

where @editor is the instance of the text editor whose grammar you want to get the configuration for.


#7

Thank you. Very much appreciated!
Follow up - when would these not intersect?


#8

When someone manually changed the tab width after an editor had been opened.