Mercurial > emacs
comparison etc/emacs.py @ 55397:a828ab1b3079
Changes largely merged in from Dave Love's code. Doc fixes.
(python-mode-map): Add python-complete-symbol.
(python-comment-line-p, python-beginning-of-string): Use syntax-ppss.
(python-comment-indent, python-complete-symbol)
(python-symbol-completions, python-partial-symbol)
(python-try-complete): New.
(python-indent-line): Remove optional arg. Use python-block-end-p.
(python-check): Bind compilation-error-regexp-alist.
(inferior-python-mode): Use rx. Move keybindings to top level.
Set comint-input-filter.
(python-preoutput-filter): Use rx.
(python-input-filter): Re-introduce.
(python-proc): Start new process if necessary.
Check python-buffer non-nil.
(view-return-to-alist): Defvar.
(python-send-receive): New.
(python-eldoc-function): Use it.
(python-mode-running): Don't defvar.
(python-mode): Set comment-indent-function.
Maybe update hippie-expand-try-functions-list.
(python-indentation-levels): Initialize differently.
(python-block-end-p): New.
(python-indent-line): Use it.
(python-compilation-regexp-alist): Augment.
(run-python): Import `emacs' module to Python rather than loading
code directly. Set python-buffer differently.
(python-send-region): Use emacs.eexecfile. Fix orig-start calculation.
Use python-proc.
(python-send-command): Go to end of comint buffer.
(python-load-file): Use python-proc, emacs.eimport.
(python-describe-symbol): Simplify interactive form.
Use emacs.help. Do use temp-buffer-show-hook.
Call print-help-return-message.
(hippie-exp): Require when compiling.
(python-preoutput-continuation): Use rx.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 06 May 2004 20:22:32 +0000 |
parents | |
children | f5a115d3c85e |
comparison
equal
deleted
inserted
replaced
55396:c6a13e95892c | 55397:a828ab1b3079 |
---|---|
1 """Definitions used by commands sent to inferior Python in python.el.""" | |
2 | |
3 # Copyright (C) 2004 Free Software Foundation, Inc. | |
4 # Author: Dave Love <d.love@dl.ac.uk> | |
5 | |
6 # This file is part of GNU Emacs. | |
7 | |
8 # GNU Emacs is free software; you can redistribute it and/or modify | |
9 # it under the terms of the GNU General Public License as published by | |
10 # the Free Software Foundation; either version 2, or (at your option) | |
11 # any later version. | |
12 | |
13 # GNU Emacs is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 # GNU General Public License for more details. | |
17 | |
18 # You should have received a copy of the GNU General Public License | |
19 # along with GNU Emacs; see the file COPYING. If not, write to the | |
20 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 # Boston, MA 02111-1307, USA. | |
22 | |
23 import os, sys, traceback, inspect, rlcompleter, __main__ | |
24 | |
25 __all__ = ["eexecfile", "args", "complete", "ehelp", "eimport"] | |
26 | |
27 def eexecfile (file): | |
28 """Execute FILE and then remove it. | |
29 If we get an exception, print a traceback with the top frame | |
30 (oursleves) excluded.""" | |
31 try: | |
32 try: execfile (file, globals (), globals ()) | |
33 except: | |
34 (type, value, tb) = sys.exc_info () | |
35 # Lose the stack frame for this location. | |
36 tb = tb.tb_next | |
37 if tb is None: # print_exception won't do it | |
38 print "Traceback (most recent call last):" | |
39 traceback.print_exception (type, value, tb) | |
40 finally: | |
41 os.remove (file) | |
42 | |
43 def eargs (name): | |
44 "Get arglist of NAME for Eldoc &c." | |
45 try: | |
46 parts = name.split ('.') | |
47 if len (parts) > 1: | |
48 exec 'import ' + parts[0] # might fail | |
49 func = eval (name) | |
50 if inspect.isbuiltin (func): | |
51 doc = func.__doc__ | |
52 if doc.find (' ->') != -1: | |
53 print '_emacs_out', doc.split (' ->')[0] | |
54 elif doc.find ('\n') != -1: | |
55 print '_emacs_out', doc.split ('\n')[0] | |
56 return | |
57 if inspect.ismethod (func): | |
58 func = func.im_func | |
59 if not inspect.isfunction (func): | |
60 return | |
61 (args, varargs, varkw, defaults) = inspect.getargspec (func) | |
62 # No space between name and arglist for consistency with builtins. | |
63 print '_emacs_out', \ | |
64 func.__name__ + inspect.formatargspec (args, varargs, varkw, | |
65 defaults) | |
66 except: pass | |
67 | |
68 def complete (text, namespace = None): | |
69 """Complete TEXT in NAMESPACE and print a Lisp list of completions. | |
70 NAMESPACE is currently not used.""" | |
71 if namespace is None: namespace = __main__.__dict__ | |
72 c = rlcompleter.Completer (namespace) | |
73 try: | |
74 if '.' in text: | |
75 matches = c.attr_matches (text) | |
76 else: | |
77 matches = c.global_matches (text) | |
78 print '_emacs_out (', | |
79 for elt in matches: | |
80 print '"%s"' % elt, | |
81 print ')' | |
82 except: | |
83 print '_emacs_out ()' | |
84 | |
85 def ehelp (name): | |
86 """Get help on string NAME. | |
87 First try to eval name for, e.g. user definitions where we need | |
88 the object. Otherwise try the string form.""" | |
89 try: help (eval (name)) | |
90 except: help (name) | |
91 | |
92 def eimport (mod, dir): | |
93 """Import module MOD with directory DIR at the head of the search path. | |
94 NB doesn't load from DIR if MOD shadows a system module.""" | |
95 path0 = sys.path[0] | |
96 sys.path[0] = dir | |
97 try: | |
98 try: | |
99 if globals().has_key(mod) and inspect.ismodule (eval (mod)): | |
100 reload(eval (mod)) | |
101 else: | |
102 globals ()[mod] = __import__ (mod) | |
103 except: | |
104 (type, value, tb) = sys.exc_info () | |
105 print "Traceback (most recent call last):" | |
106 traceback.print_exception (type, value, tb.tb_next) | |
107 finally: | |
108 sys.path[0] = path0 | |
109 | |
110 print '_emacs_ok' # ready for input and can call continuation |