From feaac5b6f5c6831871953bca16e3c4f39c1adc21 Mon Sep 17 00:00:00 2001 From: Rick Hennigan Date: Tue, 2 Jan 2024 11:35:32 -0500 Subject: [PATCH] Do not proceed with chat evaluation for chat inputs that are excluded --- Source/Chatbook/Actions.wl | 7 +++++-- Source/Chatbook/ChatHistory.wl | 30 +++++++++++++++++------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Source/Chatbook/Actions.wl b/Source/Chatbook/Actions.wl index 0eef2b55..625b84ee 100644 --- a/Source/Chatbook/Actions.wl +++ b/Source/Chatbook/Actions.wl @@ -392,7 +392,10 @@ EvaluateChatInput // beginDefinition; EvaluateChatInput[ ] := EvaluateChatInput @ rootEvaluationCell[ ]; EvaluateChatInput[ evalCell_CellObject? chatInputCellQ ] := - EvaluateChatInput[ evalCell, parentNotebook @ evalCell ]; + If[ chatExcludedQ @ evalCell, + Null, + EvaluateChatInput[ evalCell, parentNotebook @ evalCell ] + ]; EvaluateChatInput[ source: _CellObject | $Failed ] := With[ { evalCell = rootEvaluationCell @ source }, @@ -1034,7 +1037,7 @@ SendChat // beginDefinition; SendChat[ ] := SendChat @ rootEvaluationCell[ ]; -SendChat[ evalCell_CellObject, ___ ] /; MemberQ[ CurrentValue[ evalCell, CellStyle ], "ChatExcluded" ] := Null; +SendChat[ evalCell_CellObject? chatExcludedQ, ___ ] := Null; SendChat[ evalCell_CellObject ] := SendChat[ evalCell, parentNotebook @ evalCell ]; diff --git a/Source/Chatbook/ChatHistory.wl b/Source/Chatbook/ChatHistory.wl index 56225c0f..5f8d41c8 100644 --- a/Source/Chatbook/ChatHistory.wl +++ b/Source/Chatbook/ChatHistory.wl @@ -6,6 +6,7 @@ BeginPackage[ "Wolfram`Chatbook`ChatHistory`" ]; HoldComplete[ `accentIncludedCells; + `chatExcludedQ; `extraCellHeight; `filterChatCells; `getCellsInChatHistory; @@ -172,24 +173,27 @@ selectChatHistoryCells // endDefinition; (* ::**************************************************************************************************************:: *) (* ::Subsection::Closed:: *) -(*filterChatCells*) -filterChatCells // beginDefinition; +(*chatExcludedQ*) +chatExcludedQ // beginDefinition; -filterChatCells[ cellInfo: { ___Association } ] := Enclose[ - Module[ { styleExcluded, tagExcluded, cells }, +chatExcludedQ[ cell_CellObject ] := chatExcludedQ @ cellInformation @ cell; - styleExcluded = DeleteCases[ cellInfo, KeyValuePattern[ "Style" -> $$chatIgnoredStyle ] ]; +chatExcludedQ[ Cell[ __, $$chatIgnoredStyle, ___ ] ] := True; +chatExcludedQ[ Cell[ __, TaggingRules -> tags_, ___ ] ] := chatExcludedQ @ tags; +chatExcludedQ[ Cell[ ___ ] ] := False; - tagExcluded = DeleteCases[ - styleExcluded, - KeyValuePattern[ "ChatNotebookSettings" -> KeyValuePattern[ "ExcludeFromChat" -> True ] ] - ]; +chatExcludedQ[ KeyValuePattern[ "Style" -> $$chatIgnoredStyle ] ] := True; +chatExcludedQ[ KeyValuePattern[ "ChatNotebookSettings" -> settings_ ] ] := chatExcludedQ @ settings; +chatExcludedQ[ KeyValuePattern[ "ExcludeFromChat" -> exclude_ ] ] := TrueQ @ exclude; +chatExcludedQ[ KeyValuePattern[ { } ] ] := False; - tagExcluded - ], - throwInternalFailure[ filterChatCells @ cellInfo, ## ] & -]; +chatExcludedQ // endDefinition; +(* ::**************************************************************************************************************:: *) +(* ::Subsection::Closed:: *) +(*filterChatCells*) +filterChatCells // beginDefinition; +filterChatCells[ cellInfo: { ___Association } ] := Select[ cellInfo, Not @* chatExcludedQ ]; filterChatCells // endDefinition; (* ::**************************************************************************************************************:: *)