在编辑器中自定义数据提示 - 处理结构

时间:2016-12-08 10:24:25

标签: matlab

这个问题与我在1年前发布的Q& A相关联:Customizing data tips in editor

目标是自定义在编辑器中悬停在变量上时显示的数据提示。

那里提出的解决方案适用于标准变量。截至今天,我开始使用结构以使事情更清洁,但datatipinfo.m的黑客不再起作用。

以下是发生的事情:

enter image description here

如您所见,只有父结构在悬停时获得数据提示。

我想做什么,(根据excaza对我上一个允许摆脱外部依赖的问题的回答):

  • 我创建了一个与我的变量名称相同的结构,其中包含描述

对于此示例,它将沿DATASTRINGS.DATA_GEOMETRIE.GLOBAL.Nsats='description'

  • 现在我想破解datatipinfo函数,这样当我将鼠标悬停在一个变量上,而不是显示父结构的描述时,它将获取整个名称并显示链接的描述。

如果您查看datatipinfo.m代码(在命令窗口中输入edit datatipinfo),则有一部分要处理结构:

function datatipinfo(val)

% Some stuff

if isstruct(val)
        % disp the result of display, without the equal sign and
        % with the correct variable name.
        displayStr = evalcWithHotlinksOff('display(val)');
        pat = '\s*val\s*=\s*([^\n]*)\n+';
        rep = [name, ': $1\n'];
        if isscalar(val) && numel(fieldnames(val)) > 0
            pat = '\s*val\s*=\s*\n+';
            rep = [name, ':\n'];
        end
        disp(regexprep(displayStr, pat, rep, 'once'));
    elseif isempty(val)
        callDisp('sizeType');

    else

% Some other stuff

end

但我无法理解那里发生的事情......

有什么想法吗?

编辑:

我可以使用自定义数据提示,但仅适用于父结构,如下所示:

enter image description here

我修改了以下代码,以便在val是结构

时添加注释
if isstruct(val)
        % disp the result of display, without the equal sign and
        % with the correct variable name.
        displayStr = evalcWithHotlinksOff('display(val)');
        if NameFound

           disp(Comment); 

        end


        % Rest of function

    elseif isempty(val)

        %

    else

end

但是我很难让MATLAB为结构字段触发datatipinfo。它来自MATLAB不能将结构的字段识别为变量的事实。

0 个答案:

没有答案
相关问题