通过命令行获取选项卡大小 [英] Get tab-size through command line

查看:102
本文介绍了通过命令行获取选项卡大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种自动的方法来获取matlab编辑器和命令窗口的标签大小?是的,您可以打开首选项窗口并自行查找,但我希望它可以自动执行.实际上,我认为这可以概括为以下屏幕快照中的任何个用户偏好设置.

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.

推荐答案

我很快找到了解决方案,并且在深思熟虑之后,最好共享此链接:

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-以编程方式/

所以你要做的是:

  1. 打开首选项文件,然后查找您要阅读的首选项:

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

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

在我的情况下,看起来很有希望的是行CommandWindowSpacesPerTab=I4EditorSpacesPerTab=I4.我认为I代表类型(整数).

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

通过加载值进行测试:

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

就我而言:

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

    4

这个问题也有一点重叠:在Matlab中保存设置

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

编辑:显然,使用此功能时,它不会读取首选项的默认值.即:当您尚未更改首选项的值时,该值不会保存到首选项文件中,因此无法以这种方式加载.该函数仅返回0.现在,我正在手动检测这种情况:

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 :我还在Linux命令行中使用matlab,它具有自己的标签设置(通常默认为8).为了检测这种情况,我使用了以下内容:

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

这篇关于通过命令行获取选项卡大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆