Skip to content

Commit

Permalink
Merge pull request #540 from WolframResearch/539-loading-a-subcontext…
Browse files Browse the repository at this point in the history
…-with-needs-behaves-badly-when-chatbook-is-already-loaded-via-mx-file

Fix unnecessary loading of package files when Chatbook subcontexts are loaded via `Needs`
  • Loading branch information
rhennigan authored Jan 12, 2024
2 parents 390c78b + daf0d15 commit 8922d2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Source/Chatbook/Chatbook.wl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ Quiet[
Unprotect[ "Wolfram`Chatbook`*" ];
ClearAll[ "Wolfram`Chatbook`*" ];
ClearAll[ "Wolfram`Chatbook`*`*" ];
Get @ Wolfram`ChatbookLoader`$MXFile
Get @ Wolfram`ChatbookLoader`$MXFile;
(* Ensure all subcontexts are in $Packages to avoid reloading subcontexts out of order: *)
If[ MatchQ[ Wolfram`Chatbook`$ChatbookContexts, { __String } ],
WithCleanup[
Unprotect @ $Packages,
$Packages = DeleteDuplicates @ Join[ $Packages, Wolfram`Chatbook`$ChatbookContexts ],
Protect @ $Packages
]
]
,
WithCleanup[
PreemptProtect[
Expand Down
6 changes: 6 additions & 0 deletions Source/Chatbook/Main.wl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ BeginPackage[ "Wolfram`Chatbook`" ];
(*Declare Symbols*)
`$AvailableTools;
`$ChatAbort;
`$ChatbookContexts;
`$ChatHandlerData;
`$ChatPost;
`$ChatPre;
Expand Down Expand Up @@ -131,6 +132,11 @@ Protect[
WriteChatOutputCell
];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Subcontexts*)
$ChatbookContexts = Select[ Contexts[ "Wolfram`Chatbook`*" ], StringFreeQ[ "`Private`" ] ];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Package Footer*)
Expand Down

0 comments on commit 8922d2d

Please sign in to comment.