Here's an improved version of the patch.

- It uses the idle hook instead of QTimer

- The buffer will flush either on the idle hook or when > 10 messages
are in the buffer.  This is a compromise between the "real-time",
performance intensive updating of the old es, and the delayed, but
more responsive buffered es.

- I fixed a bug where newlines were being inserted improperly in some
cases.

- Cleaned up the code a bit here and there.

=== modified file 'leo/core/leoGlobals.py'
--- leo/core/leoGlobals.py      2009-04-23 16:38:51 +0000
+++ leo/core/leoGlobals.py      2009-04-28 06:23:10 +0000
@@ -3093,18 +3093,109 @@
         log.putnl(tabName)
 #...@-node:ekr.20031218072017.1474:g.enl, ecnl & ecnls
 #...@+node:ekr.20070626132332:g.es & minitest
-def es(*args,**keys):
-
+#@<< class: EsObject >>
+...@+node:jca.20090427013120.1:<< class: EsObject >>
+class EsObject:
+    def __init__(self, args, kwargs):
+        self.args = list(args)
+        self.kwargs = kwargs
+
+    def equals(self, other):
+        return self.kwargs == other.kwargs
+
+    def append(self, other):
+        if self.args != [] and (not isinstance(self.args[-1],
basestring) or
+                                    not self.args[-1].endswith
('\n')):
+            self.args.append('\n')
+        self.args += other.args
+...@-node:jca.20090427013120.1:<< class: EsObject >>
+...@nl
+
+#@<< buffered es >>
+...@+node:jca.20090427013120.2:<< buffered es >>
+def es(*args, **keys):
+    #@    << handle no log or no app >>
+    #...@+node:jca.20090427013120.3:<< handle no log or no app >>
+    log = app.log
+    if app.killed: return
+
+    if not log or log.isNull:
+        return
+    #...@nonl
+    #...@-node:jca.20090427013120.3:<< handle no log or no app >>
+    #...@nl
+
+    #@    << create buffer and register flush >>
+    #...@+node:jca.20090427013120.4:<< create buffer and register flush
>>
+    global es_buffer, flush_timer
+
+    if "es_buffer" not in globals():
+        es_buffer = []
+
+        import leo.core.leoPlugins as leoPlugins
+        leoPlugins.registerHandler("idle", g.flush)
+    #...@-node:jca.20090427013120.4:<< create buffer and register flush
>>
+    #...@nl
+
+    es_buffer.append(EsObject(args, keys))
+
+    if len(es_buffer) > 10:
+        g.flush(None, None)
+...@nonl
+...@-node:jca.20090427013120.2:<< buffered es >>
+...@nl
+
+#@<< def: flush >>
+...@+node:jca.20090427013120.6:<< def: flush >>
+
+def flush(tag, keywords):
+    global es_buffer
+
+    if not es_buffer:
+        return
+
+    #@    << Break into chunks >>
+    #...@+node:jca.20090427013120.7:<< Break into chunks >>
+
+    chunks = []
+    first_item = es_buffer.pop(0)
+    while es_buffer:
+        second_item = es_buffer.pop(0)
+        if first_item.equals(second_item):
+            first_item.append(second_item)
+        else:
+            chunks.append(first_item)
+            first_item = second_item
+    chunks.append(first_item)
+    #...@nonl
+    #...@-node:jca.20090427013120.7:<< Break into chunks >>
+    #...@nl
+
+    #@    << Print chunks >>
+    #...@+node:jca.20090427131836.10:<< Print chunks >>
+
+    for chunk in chunks:
+        g.original_es(*chunk.args, **chunk.kwargs)
+    #...@nonl
+    #...@-node:jca.20090427131836.10:<< Print chunks >>
+    #...@nl
+...@nonl
+...@-node:jca.20090427013120.6:<< def: flush >>
+...@nl
+
+#@<< def: original_es >>
+...@+node:jca.20090427013120.8:<< def: original_es >>
+def original_es(*args, **keys):
     '''Put all non-keyword args to the log pane.
     The first, third, fifth, etc. arg translated by
g.translateString.
     Supports color, comma, newline, spaces and tabName keyword
arguments.
     '''

     log = app.log
-    if app.killed: return

     # Compute the effective args.
-    d =
{'color':'black','commas':False,'newline':True,'spaces':True,'tabName':
'Log'}
+    d = {'color':'black', 'commas':False, 'newline':True,
'spaces':True,
+           'tabName':'Log'}
     d = g.doKeywordArgs(keys,d)
     color = d.get('color')
     if color == 'suppress': return # New in 4.3.
@@ -3135,6 +3226,8 @@
             app.logWaiting.append((s+'\n',color),)
         else:
             app.logWaiting.append((s,color),)
+...@-node:jca.20090427013120.8:<< def: original_es >>
+...@nl
 #...@+node:ekr.20071024101611:mini test of es
 #@@nocolor
 #@@first
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to