emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs.py: catch all errors in eargs()


From: Slawomir Nowaczyk
Subject: emacs.py: catch all errors in eargs()
Date: Wed, 30 Aug 2006 19:06:37 +0200

Hello,

The following patch ensures that _emacs_out sentinel is *always*
printed, regardless of what "name" could be. This is necessary for
proper handling of eldoc-mode in python.el

Current code hangs emacs on my machine when I enable eldoc-mode and put
point over non-function like "print".

BTW, shouldn't it *always* be possible to interrupt emacs by C-g? In my
case even C-g doesn't work, I have to kill emacs... I assume
accept-process-output is to be blamed, since emacs doesn't consume CPU
so a loop is unlikely? Or is
      (while (progn
               (accept-process-output proc 5)
               (null python-preoutput-result)))
construct unsafe?

The changes below fix the immediate problem for me, so it is not an
important issue, but one sure wishes emacs itself to be more robust in
handling such cases.

**********************************************************************

ChangeLog entry: 

2006-08-30  Slawomir Nowaczyk  <address@hidden>

        * emacs.py: (eargs) Make sure the _emacs_out sentinel is always
          printed while exceptions are always caught

**********************************************************************

--- m:/EmacsCVS/EmacsCVS/etc/emacs.py   2006-08-20 20:00:54.471734400 +0200
+++ c:/Emacs/etc/emacs.py       2006-08-30 17:40:38.220960000 +0200
@@ -44,28 +44,34 @@

 def eargs (name, imports):
     "Get arglist of NAME for Eldoc &c."
+    res = None
     try:
-       if imports: exec imports
-       parts = name.split ('.')
-       if len (parts) > 1:
-           exec 'import ' + parts[0] # might fail
-       func = eval (name)
-       if inspect.isbuiltin (func):
-           doc = func.__doc__
-           if doc.find (' ->') != -1:
-               print '_emacs_out', doc.split (' ->')[0]
-           elif doc.find ('\n') != -1:
-               print '_emacs_out', doc.split ('\n')[0]
-           return
-       if inspect.ismethod (func):
-           func = func.im_func
-       if not inspect.isfunction (func): return
-       (args, varargs, varkw, defaults) = inspect.getargspec (func)
-       # No space between name and arglist for consistency with builtins.
-       print '_emacs_out', \
-           func.__name__ + inspect.formatargspec (args, varargs, varkw,
-                                                  defaults)
-    except: pass
+        try:
+            if imports: exec imports
+            parts = name.split ('.')
+            if len (parts) > 1:
+                exec 'import ' + parts[0] # might fail
+            func = eval (name)
+            if inspect.isbuiltin (func):
+                doc = func.__doc__
+                if doc.find (' ->') != -1:
+                    res= '_emacs_out %s' % doc.split (' ->')[0]
+                elif doc.find ('\n') != -1:
+                    res= '_emacs_out %s' % doc.split ('\n')[0]
+                return
+            if inspect.ismethod (func):
+                func = func.im_func
+            if not inspect.isfunction (func): return
+            (args, varargs, varkw, defaults) = inspect.getargspec (func)
+            # No space between name and arglist for consistency with builtins.
+            res= '_emacs_out %s' % \
+                func.__name__ + inspect.formatargspec (args, varargs, varkw,
+                                                       defaults)
+        except: pass
+    finally: # make sure we *always* output sentinel
+        if res is None:
+            res= '_emacs_out ()'
+        print res

 def all_names (object):
     """Return (an approximation to) a list of all possible attribute

**********************************************************************

-- 
 Best wishes,
   Slawomir Nowaczyk
     ( address@hidden )

Does a clean house indicate that there is a broken computer in it?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]