Save Open State in Editor???

Is there no preferences option to have editor reload previous state w/o having to open each and every file again? Very rude behavior...

Risposte (1)

Steven Lord
Steven Lord il 17 Gen 2020

1 voto

In the Preferences for MATLAB, there's a section titled Editor/Debugger. One of the options that you can select (and I believe is selected by default) is "On restart reopen files from previous MATLAB session". However I believe under certain circumstances (like if MATLAB crashes) that may not always work.
Or do you mean you accidentally or intentionally closed a file (or all the files) and want to undo that action? I don't believe there is a way to undo that, but it seems like a reasonable enhancement request.
As a third option, if you want to be able to "remember" what files are opened, close some and/or open others, then restore the "remembered" set of files I think the projects functionality in MATLAB may be of interest to you. That functionality was introduced in release R2019a.

8 Commenti

dpb
dpb il 17 Gen 2020
Modificato: dpb il 17 Gen 2020
Thanks for the overview, Steven.
I am used to programming editors that retain their previous state on closing and will, with no files on the command line, reopen all previously open buffers when last exited (those that still are available, anyways). OTOH, if you give one (or more) files on the command line, it should (and will) open those instead and ignore the previous.
That, to me, seems the logical way any programming editor should work...you should be able to pick up from where one left off easily with multiple files, etc., etc., ...
Until quite recently I never used the MATLAB editor but the external editor that I have used for 20+ years for anything except just a line or two of sample code. But, the integration with the debugger and code completion and so on are now of sufficient value as to make at least exploring it of more interest. This was the first real "kick in the teeth" behavior I noticed.
I'll undoubtedly be commenting further... :)
So you were expecting if you executed
edit
at the MATLAB prompt with the Editor not open, it would open all the files that were open the last time and are still available rather than opening a new file? That's instead of (or in addition to) when you open MATLAB it opening the last session's files?
I think you should take a look at the projects functionality as I suspect that will be more in alignment with what you're expecting in terms of "persistence".
dpb
dpb il 17 Gen 2020
Modificato: dpb il 17 Gen 2020
That's the behavior I've been used to since Brief was first introduced, yes. ISTR there was a way even back on old VAX/VMS too to configure that system editor to behave similarly. (That's now been so long ago I can't even recall which editor it was that was WYSWIG on the VT100 dumb terminal that was such an advance over TECO :) ).
Behavior seems only reasonable to me and was what I was expecting the "On restart reopen files from previous MATLAB session." checkbox to do internally as well as if close ML w/ editor still open as I presume is what it must do...
I'll look at the projects functionality; unfortunately, the old DOS Brief no longer will run in DOS window w/ latest incarnations that killed the direct screen buffer access and the only workalikes just aren't quite up to snuff; primarily because there's none that have implemented the macro language and I had my version heavily customized with file-extension-specific behavior including having built a set for .m files from the supplied Fortran/BASIC language code templates. That made for a seamless and consistent coding environment across all languages that I used extensively in the "real" consulting days. Now that am retired, can afford to play some with alternate toolsets; "in anger" simply wasn't sufficient time to get used to using something unfamiliar that didn't have the features used regularly.
dpb
dpb il 17 Gen 2020
" That's instead of (or in addition to) when you open MATLAB it opening the last session's files?"
Yes, precisely. By habit I never intentionally exit ML w/ the editor still open--that just seems too risky for my taste with source code file(s) still in the editor buffer(s). Hence, at least for me the action on restart is virtually always a "do nothing" one and I restart the editor inside the session.
I'll have to explore the project stuff, but I'm strongly suspecting it's not going to be what I would prefer for this purpose; I'm not trying to build a project which I'm guessing is what will be required--I just want what I had when I quit back unless I specifically say I want something different.
I guess I'm so ingrained with 30+ years habit with a specific toolset that I'm just where I presume that's the way everybody works! :)
Les Beckham
Les Beckham il 18 Gen 2020
I'm pretty sure that Matlab saves the editor configuration when Matlab itself is closed. If you close the editor while Matlab is still open you are basically telling Matlab "I'm done with this editor session and you can completely forget about it". If you close Matlab with an open editor session and then restart Matlab, the configuration of the editor will be restored as it was when you last closed Matlab. This seems relatively intuitive if you think of Matlab, and all of its associated windows as an IDE. When closed, the IDE configuration is saved, and when opened, it is restored.
I've used Matlab this way for years (I always have my editor session open when I close Matlab and it re-opens when I restart Matlab -- ready to pick up where I left off).
It sounds like you are concerned about having the editor open when closing Matlab because of a fear of losing possibly unsaved edits. I'm pretty sure that if you close with an unsaved edit you will be prompted to save or discard your changes.
Try it and see. Projects are a cool addition but, I think, aren't really relevant to your issue.
dpb
dpb il 18 Gen 2020
"t sounds like you are concerned about having the editor open when closing Matlab because of a fear of losing possibly unsaved edits"
I'm more concerned about the files themselves than an edit or two...if it's reliable to ensure never an open/dangling handle.
I suppose if one is used to just leaving the editor open and can prevent the reflex action of closing it (take a lot of retraining for a very old dog on that one :) ) that would end up similarly-behaving.
Agree projects as typically defined in IDEs is not what am looking for at all.
Mac
Mac il 9 Ott 2025
Would it also be possible to use the automatically saved list of open matlab files (for instance in Matlab2020a) to make a newer matlab version (for instance Matlab2024b) installed on a different computer (with the same file structure) open the same files?
(Or is there some other way to open a long-ish list of files (same file structure on computer) on another computer)
I do not know precisely where the list of open files is kept; somewhere in the preferences, probably, but I'd guess it wouldn't be directly portable to a new version, particularly from prior to R2024x to R2024x+.
The way to do it that would be portable would be to retrieve the open files via the MATLAB Editor API and then export those filenames to the new system as arguments to the edit command or through the openDocument API function. This could all be done programmatically.
The editor API is supported, but it is not documented beyond the help text in the code files themselves.
help matlab.desktop.editor
matlab.desktop.editor Summary of Editor Document functionality Programmatically access the MATLAB Editor to open, change, save, or close documents. MATLAB Version 25.2 (R2025b) 28-Jul-2025 Work with all documents open in the Editor: isEditorAvailable - Verify Editor is available. getAll - Identify all open Editor documents. Work with single document open in the Editor: getActive - Find active Editor document. getActiveFilename - Find file name of active document. findOpenDocument - Create Document object for open document. isOpen - Determine if specified file is open in Editor. Open an existing document or create a new one: newDocument - Create Document in Editor. openDocument - Open file in Editor. openAndGoToFunction - Open MATLAB file and highlight specified function. openAndGoToLine - Open file and highlight specified line. Work with text from an Editor document: indexToPositionInLine - Convert text array index to position within line. positionInLineToIndex - Convert position within line to text array index. linesToText - Convert cell array of text lines to character array. textToLines - Convert character array into cell array of text lines.

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Centro assistenza e File Exchange

Prodotti

Richiesto:

dpb
il 17 Gen 2020

Commentato:

dpb
il 9 Ott 2025

Community Treasure Hunt

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

Start Hunting!

Translated by