Redirect the warning stream to the shell during the ScriptBinding check of user code
and format the warning similarly to an exception for both that check and for
warnings raised in the subprocess.

M NEWS.txt
M Pyshell.py
M ScriptBinding.py
M run.py
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 96da459..98b8c13 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -1,5 +1,6 @@
 import sys
 import os
+import linecache
 import time
 import socket
 import traceback
@@ -17,6 +18,22 @@
 
 LOCALHOST = '127.0.0.1'
 
+try:
+    import warnings
+except ImportError:
+    pass
+else:
+    def idle_formatwarning_subproc(message, category, filename, lineno):
+        """Format warnings the IDLE way"""
+        s = "\nWarning (from warnings module):\n"
+        s += '  File \"%s\", line %s\n' % (filename, lineno)
+        line = linecache.getline(filename, lineno).strip()
+        if line:
+            s += "    %s\n" % line
+        s += "%s: %s\n" % (category.__name__, message)
+        return s
+    warnings.formatwarning = idle_formatwarning_subproc
+
 # Thread shared globals: Establish a queue between a subthread (which handles
 # the socket) and the main thread (which runs user code), plus global
 # completion and exit flags: