Mercurial > emacs
annotate etc/emacs.py @ 71501:021c1400e746
[!TARGET_API_MAC_CARBON]: Don't include FixMath.h or Scrap.h.
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> |
---|---|
date | Wed, 28 Jun 2006 08:29:54 +0000 |
parents | e8a3fb527b77 |
children | 044730770048 |
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 |
68640
e8a3fb527b77
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65673
diff
changeset
|
3 # Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. |
55397
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4 # Author: Dave Love <d.love@dl.ac.uk> |
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 | 20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
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 |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 import os, sys, traceback, inspect, rlcompleter, __main__ |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 __all__ = ["eexecfile", "args", "complete", "ehelp", "eimport"] |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 def eexecfile (file): |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 """Execute FILE and then remove it. |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 If we get an exception, print a traceback with the top frame |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 (oursleves) excluded.""" |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 try: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 try: execfile (file, globals (), globals ()) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 except: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 (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
|
35 # Lose the stack frame for this location. |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 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
|
40 finally: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 os.remove (file) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 def eargs (name): |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 "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
|
45 try: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 parts = name.split ('.') |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 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
|
48 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
|
49 func = eval (name) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 if inspect.isbuiltin (func): |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 doc = func.__doc__ |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 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
|
53 print '_emacs_out', doc.split (' ->')[0] |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 elif doc.find ('\n') != -1: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 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
|
56 return |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 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
|
58 func = func.im_func |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 if not inspect.isfunction (func): |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 return |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (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
|
62 # 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
|
63 print '_emacs_out', \ |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 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
|
65 defaults) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 except: pass |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 def complete (text, namespace = None): |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 """Complete TEXT in NAMESPACE and print a Lisp list of completions. |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 NAMESPACE is currently not used.""" |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 if namespace is None: namespace = __main__.__dict__ |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 c = rlcompleter.Completer (namespace) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 try: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 if '.' in text: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 matches = c.attr_matches (text) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 else: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 matches = c.global_matches (text) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 print '_emacs_out (', |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 for elt in matches: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 print '"%s"' % elt, |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 print ')' |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 except: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 print '_emacs_out ()' |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 |
65673
df079883ac40
(ehelp): Add g and l to arg list, and use them in the call to `help'.
Eli Zaretskii <eliz@gnu.org>
parents:
65088
diff
changeset
|
85 def ehelp (name, g, l): |
df079883ac40
(ehelp): Add g and l to arg list, and use them in the call to `help'.
Eli Zaretskii <eliz@gnu.org>
parents:
65088
diff
changeset
|
86 """Get help on string NAME using globals G and locals L. |
55397
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 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
|
88 the object. Otherwise try the string form.""" |
65673
df079883ac40
(ehelp): Add g and l to arg list, and use them in the call to `help'.
Eli Zaretskii <eliz@gnu.org>
parents:
65088
diff
changeset
|
89 try: help (eval (name, g, l)) |
55397
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 except: help (name) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 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
|
93 """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
|
94 NB doesn't load from DIR if MOD shadows a system module.""" |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 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
|
96 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
|
97 try: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 try: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 if globals().has_key(mod) and inspect.ismodule (eval (mod)): |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 reload(eval (mod)) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 else: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 globals ()[mod] = __import__ (mod) |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 except: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (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
|
105 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
|
106 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
|
107 finally: |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 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
|
109 |
a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 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
|
111 |
f5a115d3c85e
Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents:
55397
diff
changeset
|
112 # arch-tag: d90408f3-90e2-4de4-99c2-6eb9c7b9ca46 |