annotate etc/emacs.py @ 75654:8f0016c7d0b9

Fix file local variables c-file-style specification.
author Glenn Morris <rgm@gnu.org>
date Sat, 03 Feb 2007 21:58:55 +0000
parents 3d45362f1d38
children a995e0466061
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 """Definitions used by commands sent to inferior Python in python.el."""
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
75348
3d45362f1d38 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73713
diff changeset
3 # Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
4 # Author: Dave Love <fx@gnu.org>
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 # This file is part of GNU Emacs.
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
7
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8 # GNU Emacs is free software; you can redistribute it and/or modify
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9 # it under the terms of the GNU General Public License as published by
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10 # the Free Software Foundation; either version 2, or (at your option)
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11 # any later version.
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 # GNU Emacs is distributed in the hope that it will be useful,
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16 # GNU General Public License for more details.
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19 # along with GNU Emacs; see the file COPYING. If not, write to the
64083
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 55401
diff changeset
20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 55401
diff changeset
21 # Boston, MA 02110-1301, USA.
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
23 import os, sys, traceback, inspect, __main__
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
24 from sets import Set
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
26 __all__ = ["eexecfile", "eargs", "complete", "ehelp", "eimport", "modpath"]
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28 def eexecfile (file):
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 """Execute FILE and then remove it.
72456
044730770048 (eexecfile): Use the __main__ rather than `emacs' namespace.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
30 Execute the file within the __main__ namespace.
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31 If we get an exception, print a traceback with the top frame
72456
044730770048 (eexecfile): Use the __main__ rather than `emacs' namespace.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
32 (ourselves) excluded."""
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33 try:
72456
044730770048 (eexecfile): Use the __main__ rather than `emacs' namespace.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
34 try: execfile (file, __main__.__dict__)
044730770048 (eexecfile): Use the __main__ rather than `emacs' namespace.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68640
diff changeset
35 except:
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
36 (type, value, tb) = sys.exc_info ()
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
37 # Lose the stack frame for this location.
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 tb = tb.tb_next
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 if tb is None: # print_exception won't do it
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40 print "Traceback (most recent call last):"
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41 traceback.print_exception (type, value, tb)
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
42 finally:
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43 os.remove (file)
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
45 def eargs (name, imports):
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46 "Get arglist of NAME for Eldoc &c."
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47 try:
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
48 if imports: exec imports
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 parts = name.split ('.')
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
50 if len (parts) > 1:
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
51 exec 'import ' + parts[0] # might fail
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52 func = eval (name)
73713
aa6d5e310367 (eargs) Provide eldoc message for builtin types.
Chong Yidong <cyd@stupidchicken.com>
parents: 73456
diff changeset
53 if inspect.isbuiltin (func) or type(func) is type:
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54 doc = func.__doc__
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 if doc.find (' ->') != -1:
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56 print '_emacs_out', doc.split (' ->')[0]
73713
aa6d5e310367 (eargs) Provide eldoc message for builtin types.
Chong Yidong <cyd@stupidchicken.com>
parents: 73456
diff changeset
57 else:
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 print '_emacs_out', doc.split ('\n')[0]
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 return
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 if inspect.ismethod (func):
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 func = func.im_func
73456
8ac53fe6c9dc * emacs.py (eargs): Return expected _emacs_out string even if
Chong Yidong <cyd@stupidchicken.com>
parents: 72458
diff changeset
62 if not inspect.isfunction (func):
8ac53fe6c9dc * emacs.py (eargs): Return expected _emacs_out string even if
Chong Yidong <cyd@stupidchicken.com>
parents: 72458
diff changeset
63 print '_emacs_out '
8ac53fe6c9dc * emacs.py (eargs): Return expected _emacs_out string even if
Chong Yidong <cyd@stupidchicken.com>
parents: 72458
diff changeset
64 return
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65 (args, varargs, varkw, defaults) = inspect.getargspec (func)
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 # No space between name and arglist for consistency with builtins.
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 print '_emacs_out', \
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68 func.__name__ + inspect.formatargspec (args, varargs, varkw,
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 defaults)
73456
8ac53fe6c9dc * emacs.py (eargs): Return expected _emacs_out string even if
Chong Yidong <cyd@stupidchicken.com>
parents: 72458
diff changeset
70 except:
8ac53fe6c9dc * emacs.py (eargs): Return expected _emacs_out string even if
Chong Yidong <cyd@stupidchicken.com>
parents: 72458
diff changeset
71 print "_emacs_out "
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
73 def all_names (object):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
74 """Return (an approximation to) a list of all possible attribute
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
75 names reachable via the attributes of OBJECT, i.e. roughly the
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
76 leaves of the dictionary tree under it."""
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
77
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
78 def do_object (object, names):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
79 if inspect.ismodule (object):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
80 do_module (object, names)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
81 elif inspect.isclass (object):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
82 do_class (object, names)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
83 # Might have an object without its class in scope.
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
84 elif hasattr (object, '__class__'):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
85 names.add ('__class__')
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
86 do_class (object.__class__, names)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
87 # Probably not a good idea to try to enumerate arbitrary
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
88 # dictionaries...
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
89 return names
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
90
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
91 def do_module (module, names):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
92 if hasattr (module, '__all__'): # limited export list
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
93 names.union_update (module.__all__)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
94 for i in module.__all__:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
95 do_object (getattr (module, i), names)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
96 else: # use all names
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
97 names.union_update (dir (module))
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
98 for i in dir (module):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
99 do_object (getattr (module, i), names)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
100 return names
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
101
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
102 def do_class (object, names):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
103 ns = dir (object)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
104 names.union_update (ns)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
105 if hasattr (object, '__bases__'): # superclasses
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
106 for i in object.__bases__: do_object (i, names)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
107 return names
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
108
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
109 return do_object (object, Set ([]))
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
110
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
111 def complete (name, imports):
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112 """Complete TEXT in NAMESPACE and print a Lisp list of completions.
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
113 Exec IMPORTS first."""
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
114 import __main__, keyword
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
115
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
116 def class_members(object):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
117 names = dir (object)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
118 if hasattr (object, '__bases__'):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
119 for super in object.__bases__:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
120 names = class_members (super)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
121 return names
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
122
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
123 names = Set ([])
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
124 base = None
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 try:
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
126 dict = __main__.__dict__.copy()
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
127 if imports: exec imports in dict
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
128 l = len (name)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
129 if not "." in name:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
130 for list in [dir (__builtins__), keyword.kwlist, dict.keys()]:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
131 for elt in list:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
132 if elt[:l] == name: names.add(elt)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
133 else:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
134 base = name[:name.rfind ('.')]
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
135 name = name[name.rfind('.')+1:]
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
136 try:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
137 object = eval (base, dict)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
138 names = Set (dir (object))
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
139 if hasattr (object, '__class__'):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
140 names.add('__class__')
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
141 names.union_update (class_members (object))
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
142 except: names = all_names (dict)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
143 except: return []
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
144 l = len(name)
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
145 print '_emacs_out (',
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
146 for n in names:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
147 if name == n[:l]:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
148 if base: print '"%s.%s"' % (base, n),
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
149 else: print '"%s"' % n,
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
150 print ')'
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
151
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
152 def ehelp (name, imports):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
153 """Get help on string NAME.
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
154 First try to eval name for, e.g. user definitions where we need
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
155 the object. Otherwise try the string form."""
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
156 locls = {}
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
157 if imports:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
158 try: exec imports in locls
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
159 except: pass
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
160 try: help (eval (name, globals(), locls))
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
161 except: help (name)
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163 def eimport (mod, dir):
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 """Import module MOD with directory DIR at the head of the search path.
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 NB doesn't load from DIR if MOD shadows a system module."""
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
166 from __main__ import __dict__
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
167
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168 path0 = sys.path[0]
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 sys.path[0] = dir
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 try:
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 try:
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
172 if __dict__.has_key(mod) and inspect.ismodule (__dict__[mod]):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
173 reload (__dict__[mod])
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 else:
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
175 __dict__[mod] = __import__ (mod)
55397
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176 except:
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 (type, value, tb) = sys.exc_info ()
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 print "Traceback (most recent call last):"
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 traceback.print_exception (type, value, tb.tb_next)
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
180 finally:
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 sys.path[0] = path0
a828ab1b3079 Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182
72458
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
183 def modpath (module):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
184 """Return the source file for the given MODULE (or None).
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
185 Assumes that MODULE.py and MODULE.pyc are in the same directory."""
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
186 try:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
187 path = __import__ (module).__file__
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
188 if path[-4:] == '.pyc' and os.path.exists (path[0:-1]):
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
189 path = path[:-1]
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
190 print "_emacs_out", path
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
191 except:
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
192 print "_emacs_out ()"
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
193
18443633d75d Update to Dave Love's latest version.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72456
diff changeset
194 # print '_emacs_ok' # ready for input and can call continuation
55401
f5a115d3c85e Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 55397
diff changeset
195
f5a115d3c85e Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 55397
diff changeset
196 # arch-tag: d90408f3-90e2-4de4-99c2-6eb9c7b9ca46