Search code examples
eclipsercp

Programmatically retrieve the tabsize of eclipse


I am writing a plugin which needs to retrieve the tab size setting of eclipse.

That is the 'Windows > Preferences > General > Editor > Text Editors > Displayed tab width' setting

Does anyone have any idea how to achieve this? Thank for your help.


Solution

  • If your code is in a text editor extending TextEditor you can get the tab setting from the source viewer configuration using:

    getSourceViewerConfiguration().getTabWidth(getSourceViewer());
    

    elsewhere you could use:

    IPreferenceStore store = EditorsUI.getPreferenceStore();
    
    store.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH));