Retrieve tab size from CodeStyleSettings

I need to know how to retrieve the conifgured tab size (of the file type of the currently edited document) from the CodeStyleSettings.

thanks for any help :-)

0
2 comments
Avatar
Permanently deleted user

Hi Kay,

CommonCodeStyleSettings.getIndentOptions().TAB_SIZE

Denis

0

Hi Denis,
thanks a lot for your answer! :)

here my solution with a fallback to the general tabsize of the project, in case someone else needs it:


 // Get tab size
 Integer tabSize = 0;
 Project project = editor.getProject();
 PsiFile psifile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
 CommonCodeStyleSettings commonCodeStyleSettings = new CommonCodeStyleSettings(psifile.getLanguage());
 CommonCodeStyleSettings.IndentOptions indentOptions  = commonCodeStyleSettings.getIndentOptions();


 if(indentOptions != null) {
  tabSize   = commonCodeStyleSettings.getIndentOptions().TAB_SIZE;
 }
 if(tabSize == 0) {
  tabSize= editor.getSettings().getTabSize(editor.getProject());
 }


Greetings, Kay

0

Please sign in to leave a comment.