無證功能Internal`HandlerBlock
(uncovered由馬克西姆Rytin)這裏是適用的:
Off[FindMaximum::"nrnum"]
Internal`HandlerBlock[{"Message", Print},
Message[FindMaximum::"nrnum", arg1, arg2, arg3]]
(* => Hold[Message[FindMaximum::nrnum,arg1,arg2,arg3],False]*)
另一個處理程序類型是 「MessageTextFilter」。爲每個生成的消息調用「消息」爲 ,並將形式爲Hold [..., ...]的一個參數傳遞給處理程序函數,第二個元素設置爲False以獲取 靜音消息。對於 實際打印的消息調用「MessageTextFilter」,並使用三個參數調用該函數。
馬克西姆Rytin
另一種可能性是修改$MessagePrePrint
以這樣的方式,這將打印包含在系細胞與可擴展到關於評價全參數截斷參數消息。它可以與Interpretation
做到:
truncatingRules = {lst : {x_, y__} /;
MatrixQ[lst, NumberQ] && Length[lst] > 3 :>
{x /. v : {a_, b__} /; Length[v] > 3 :>
{a,
Interpretation[Style[Skeleton[Length[{b}]], Gray],
Sequence @@ {b}]},
Interpretation[Style[Skeleton[Length[{y}]], Gray],
Sequence @@ {y}]},
lst : {x_, y__} /; VectorQ[lst, NumberQ] && Length[lst] > 3 :>
{x, Interpretation[Style[Skeleton[Length[{y}]], Gray],
Sequence @@ {y}]}};
InlineCellInsideMessage[expr_] :=
Style[DisplayForm[
Cell[BoxData[MakeBoxes[expr, StandardForm]], "Input"]],
FontWeight -> Bold, FontFamily -> "Courier", Background -> Yellow,
FontColor -> Red, FontSize -> 12, StripOnInput -> True,
AutoNumberFormatting -> True, ShowStringCharacters -> True]
$MessagePrePrint =
Function[expr,
If[TrueQ[ByteCount[Unevaluated[expr]] < $OutputSizeLimit/20.],
InlineCellInsideMessage[expr],
InlineCellInsideMessage[expr /. truncatingRules]
]]
當然的$MessagePrePrint
以上版本僅僅是一個草案,但它說明了主要的想法。
我不認爲它保存了關閉的消息(至少不是那些使用`Off []`機制的消息)。看到我的評論如下。 – Simon 2010-11-25 04:17:58
@Simon未公開的函數``Internal`HandlerBlock``允許捕獲已關閉的消息。請參閱下面的答案。 – 2011-08-17 05:37:01