all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* emacs.py: catch all errors in eargs()
@ 2006-08-30 17:06 Slawomir Nowaczyk
  2006-08-30 21:11 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Slawomir Nowaczyk @ 2006-08-30 17:06 UTC (permalink / raw)


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  <slawek@cs.lth.se>

	* 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
     ( slawomir.nowaczyk.847@student.lu.se )

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-08-31 11:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-30 17:06 emacs.py: catch all errors in eargs() Slawomir Nowaczyk
2006-08-30 21:11 ` Stefan Monnier
2006-08-31 11:19   ` Slawomir Nowaczyk

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.