gpt4 book ai didi

matlab - 如何在 Matlab 中保存时自动删除尾随空格?

转载 作者:太空宇宙 更新时间:2023-11-03 19:27:03 28 4
gpt4 key购买 nike

我没有在 Matlab 2012b 中找到基本功能:

Remove trailing whitespaces on save.

相关:

How to auto-remove trailing whitespace in Eclipse?

Aptana 3 - How remove trailing whitespaces on save

最佳答案

我有同样的需求,写了一个小脚本来做一些接近的事情。将以下内容放在 MATLAB desktop shortcut 中.每当您单击快捷按钮时,它都会从编辑器中的事件文件中去除尾随空格。不如在保存时自动执行它那么好——你需要记住在保存之前按下按钮——但差不多。在 11b、12a 和 13b 上进行了测试,但在 12b 上也应该没问题。

希望对您有所帮助!

% Temp variable for shortcut. Give it an unusual name so it's unlikely to
% conflict with anything in the workspace.
shtcutwh__ = struct;

% Check that the editor is available.
if ~matlab.desktop.editor.isEditorAvailable
return
end

% Check that a document exists.
shtcutwh__.activeDoc = matlab.desktop.editor.getActive;
if isempty(shtcutwh__.activeDoc)
return
end

% Get the current text.
shtcutwh__.txt = shtcutwh__.activeDoc.Text;

% Remove trailing whitespace from each line.
shtcutwh__.lines = deblank(regexp(shtcutwh__.txt,'[^\n]*(\n)|[^\n]*$', 'match'));

% Reconcatenate lines.
shtcutwh__.addNewline = @(x)sprintf('%s\n',x);
shtcutwh__.lines = cellfun(shtcutwh__.addNewline, shtcutwh__.lines, 'UniformOutput', false);
shtcutwh__.newtxt = horzcat(shtcutwh__.lines{:});

% Set the current text.
shtcutwh__.activeDoc.Text = shtcutwh__.newtxt;

% Delete temp variable.
clear shtcutwh__

关于matlab - 如何在 Matlab 中保存时自动删除尾随空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19770347/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com