Get tab-size through command line

旧街凉风 提交于 2019-12-06 02:20:37

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/10817832/get-tab-size-through-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!