Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get tab-size through command line

Is there an automated way of retrieving the tab size of the matlab editor and command window? Yes, you can just open the preferences window and look it up yourself, but I want it automated. Actually I think this could be generalized to retrieving any of those user preferences in the screenshot below.

enter image description here

like image 558
Gunther Struyf Avatar asked May 30 '12 13:05

Gunther Struyf


People also ask

How many spaces is a tab in Terminal?

Generally, a tab is the same width as 4 to 5 spaces provided the font being used equally sizes each character. For example, the Courier font's tab equals 5 spaces, whereas the Arial font is 11 spaces to each tab when the font size for both is set to 12.

What is the default size of tab?

The default value for the tab-size property is 8 space characters, and it can accept any positive integer value.

How do I set tab space in Linux?

Use spaces for indentingThe first line enables expandtab option in Vim. This option makes sure that spaces are used for indenting lines, even when you press the 'Tab' key. The second option tabstop takes a numerical value. Let's say I typed set tabstop=2, this will insert 2 spaces for a line indent.


1 Answers

I found the solution pretty quickly and after digging in thought it's best to share this link:

http://undocumentedmatlab.com/blog/changing-system-preferences-programmatically/

So what you do is:

  1. Open up the preferences file and look for the preference you want to read:

    edit(fullfile(prefdir,'matlab.prf'));
    

    In my case it were the lines CommandWindowSpacesPerTab=I4 and EditorSpacesPerTab=I4 that looked promising. I think the I stands for the type (integer).

  2. Test it out by loading the value:

    com.mathworks.services.Prefs.get<type>Pref(<pref-name>)
    

    In my case:

    >> com.mathworks.services.Prefs.getIntegerPref('EditorSpacesPerTab')
    ans =
    
        4
    

There is also a small overlap with this question: Saving settings in matlab

EDIT: Apparently, when using this function, it doesn't read the default value of the preference. ie: when you haven't yet changed the value of the preference, the value isn't saved into the preference file, and thus can't be loaded this way. The functions just returns 0. For now, I'm detecting this case manually:

if loadedpref==0
    set default
end

EDIT2: I also use matlab in linux commandline, which has it's own tab setting (usually defaulted to 8). To detect this situation I used the following:

function retval = isCommandWindowOpen()
    jDesktop = com.mathworks.mde.desk.MLDesktop.getInstance;
    retval = ~isempty(jDesktop.getClient('Command Window'));
end
like image 90
Gunther Struyf Avatar answered Oct 13 '22 00:10

Gunther Struyf