I have a palette including this button:
CreatePalette[{
Button[
"m-editor",
Module[{modifyCodeStyle},(*by David Reiss*)
modifyCodeStyle[nb_NotebookObject, Notebook] :=
Module[{styledefs, editable},
editable = Editable /. Options[nb, Editable];
SetOptions[nb, Editable -> True];
styledefs = StyleDefinitions /. Options[nb, StyleDefinitions];
Switch[Head[styledefs], Notebook,
styledefs =
Notebook[{First@First[styledefs],
Cell[StyleData["Code"], PageWidth -> WindowWidth,
AutoIndent -> True, AutoSpacing -> True,
LineBreakWithin -> Automatic, LineIndent -> 1,
LinebreakAdjustments -> {0.85, 2, 10, 0, 1}],
Rest@First[styledefs]},
Sequence @@ Rest[List @@ styledefs]],
String | FileName | FrontEnd`FileName,
styledefs =
Notebook[{Cell[StyleData[StyleDefinitions -> styledefs]],
Cell[StyleData["Code"], PageWidth -> WindowWidth,
AutoIndent -> True, AutoSpacing -> True,
LineBreakWithin -> Automatic, LineIndent -> 1,
LinebreakAdjustments -> {0.85, 2, 10, 0, 1}]},
StyleDefinitions -> "PrivateStylesheetFormatting.nb"]];
SetOptions[nb, StyleDefinitions -> styledefs];
SetOptions[nb, Editable -> editable]];
modifyCodeStyle[SelectedNotebook[], Notebook]];
]
},
WindowTitle -> "fix editor"
]
the code for which I lifted from a post of David Reiss on the mathgroup.
To use it: open an m-editor, then click on the button. It will do what you want from there on. However, this must be repeated if you close and re-open the editor window.
Notebooks[]using aScheduledTaskand apply this to any new *.m that are found. The code for would be put in aninit.msomewhere. I don't know if there is a way to get notification form the front-end whenever a new file is opened. That method would be preferable to pooling... – Ajasja May 19 '12 at 20:14Dynamicand having it do something whenever the list of open windows changes, but that doesn't work reliably if it's off-screen. But, perhaps there is some other way to get this to work always. although you'll quickly start getting annoyed again: construct your beautifully indented code and then attempt to wrap aTotal[](say) around it. You can't block-indent... – acl May 19 '12 at 20:39SetOptions[$FrontEnd, ...]but it doesn't seem to work. – Ajasja May 21 '12 at 08:03