How to apply "smart indent" to a file programmatically

23 vues (au cours des 30 derniers jours)
Joseph
Joseph le 12 Juil 2011
Modifié(e) : Oleg Komarov le 7 Déc 2015
I have wrote a function that writes other functions. I want to now apply smart indent to the file to improve the aesthetics of the created function by aligning if_ends,etc. How can I do this programmaticly instead of the usual 'right-click' and select method as if programming manaually.

Réponse acceptée

Oleg Komarov
Oleg Komarov le 12 Juil 2011
Modifié(e) : Oleg Komarov le 7 Déc 2015
Suppose you have this fcn saved as foo:
function l = foo()
for l = 1:10
l
for l
l = 1:10
end
end
Then using editor API:
h = matlab.desktop.editor.openDocument('C:\Users\Oleg\Desktop\foo.m');
h.smartIndentContents
h.save
h.close

Plus de réponses (1)

Jason Ross
Jason Ross le 12 Juil 2011

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by