annotate etc/emacs2.py @ 110321:4b26adbef9a2

Major code cleanup. Split tramp.el into tramp.el and tramp-sh.el. * Makefile.in (TRAMP_SRC): Remove tramp-fish.el. Add tramp-sh.el. * net/tramp.el (top): Don't show loading message. Require just 'tramp-compat, everything else is required there. Use `ignore-errors' where appropriate. (tramp-inline-compress-start-size, tramp-copy-size-limit) (tramp-terminal-type, tramp-end-of-output) (tramp-initial-end-of-output, tramp-completion-function-alist-rsh) (tramp-completion-function-alist-ssh) (tramp-completion-function-alist-telnet) (tramp-completion-function-alist-su) (tramp-completion-function-alist-putty, tramp-remote-path) (tramp-remote-process-environment, tramp-sh-extra-args) (tramp-actions-before-shell, tramp-uudecode) (tramp-perl-file-truename, tramp-perl-file-name-all-completions) (tramp-perl-file-attributes) (tramp-perl-directory-files-and-attributes) (tramp-perl-encode-with-module, tramp-perl-decode-with-module) (tramp-perl-encode, tramp-perl-decode) (tramp-vc-registered-read-file-names, tramp-file-mode-type-map) (tramp-file-name-handler-alist, tramp-make-tramp-temp-file) (tramp-handle-make-symbolic-link, tramp-handle-load) (tramp-handle-file-name-as-directory) (tramp-handle-file-name-directory) (tramp-handle-file-name-nondirectory, tramp-handle-file-truename) (tramp-handle-file-exists-p, tramp-handle-file-attributes) (tramp-do-file-attributes-with-ls) (tramp-do-file-attributes-with-perl) (tramp-do-file-attributes-with-stat) (tramp-handle-set-visited-file-modtime) (tramp-handle-verify-visited-file-modtime) (tramp-handle-set-file-modes, tramp-handle-set-file-times) (tramp-set-file-uid-gid, tramp-remote-selinux-p) (tramp-handle-file-selinux-context) (tramp-handle-set-file-selinux-context) (tramp-handle-file-executable-p, tramp-handle-file-readable-p) (tramp-handle-file-newer-than-file-p, tramp-handle-file-modes) (tramp-handle-file-directory-p, tramp-handle-file-regular-p) (tramp-handle-file-symlink-p, tramp-handle-file-writable-p) (tramp-handle-file-ownership-preserved-p) (tramp-handle-directory-file-name, tramp-handle-directory-files) (tramp-handle-directory-files-and-attributes) (tramp-do-directory-files-and-attributes-with-perl) (tramp-do-directory-files-and-attributes-with-stat) (tramp-handle-file-name-all-completions) (tramp-handle-file-name-completion, tramp-handle-add-name-to-file) (tramp-handle-copy-file, tramp-handle-copy-directory) (tramp-handle-rename-file, tramp-do-copy-or-rename-file) (tramp-do-copy-or-rename-file-via-buffer) (tramp-do-copy-or-rename-file-directly) (tramp-do-copy-or-rename-file-out-of-band) (tramp-handle-make-directory, tramp-handle-delete-directory) (tramp-handle-delete-file) (tramp-handle-dired-recursive-delete-directory) (tramp-handle-dired-compress-file, tramp-handle-dired-uncache) (tramp-handle-insert-directory) (tramp-handle-unhandled-file-name-directory) (tramp-handle-expand-file-name) (tramp-handle-substitute-in-file-name) (tramp-handle-executable-find, tramp-process-sentinel) (tramp-handle-start-file-process, tramp-handle-process-file) (tramp-handle-call-process-region, tramp-handle-shell-command) (tramp-handle-file-local-copy, tramp-handle-file-remote-p) (tramp-handle-insert-file-contents) (tramp-handle-insert-file-contents-literally) (tramp-handle-find-backup-file-name) (tramp-handle-make-auto-save-file-name, tramp-handle-write-region) (tramp-vc-registered-file-names, tramp-handle-vc-registered) (tramp-sh-file-name-handler, tramp-vc-file-name-handler) (tramp-maybe-send-script, tramp-set-auto-save, tramp-run-test) (tramp-run-test2, tramp-find-executable, tramp-set-remote-path) (tramp-find-file-exists-command, tramp-open-shell) (tramp-find-shell, tramp-barf-if-no-shell-prompt) (tramp-open-connection-setup-interactive-shell) (tramp-local-coding-commands, tramp-remote-coding-commands) (tramp-find-inline-encoding, tramp-call-local-coding-command) (tramp-inline-compress-commands, tramp-find-inline-compress) (tramp-compute-multi-hops, tramp-maybe-open-connection) (tramp-send-command , tramp-wait-for-output) (tramp-send-command-and-check, tramp-barf-unless-okay) (tramp-send-command-and-read, tramp-mode-string-to-int) (tramp-convert-file-attributes, tramp-check-cached-permissions) (tramp-file-mode-from-int, tramp-file-mode-permissions) (tramp-shell-case-fold, tramp-make-copy-program-file-name) (tramp-method-out-of-band-p, tramp-local-host-p) (tramp-get-remote-path, tramp-get-remote-tmpdir) (tramp-get-ls-command, tramp-get-ls-command-with-dired) (tramp-get-test-command, tramp-get-test-nt-command) (tramp-get-file-exists-command, tramp-get-remote-ln) (tramp-get-remote-perl, tramp-get-remote-stat) (tramp-get-remote-readlink, tramp-get-remote-trash) (tramp-get-remote-id, tramp-get-remote-uid, tramp-get-remote-gid) (tramp-get-local-uid, tramp-get-local-gid) (tramp-get-inline-compress, tramp-get-inline-coding, ): Move to tramp-sh.el. (tramp-methods, tramp-default-method-alist) (tramp-default-user-alist, tramp-foreign-file-name-handler-alist): Move initialization to tramp-sh.el. (tramp-temp-name-prefix): Make it a defconst. (tramp-dissect-file-name): Don't check anymore for multi-hop methods. (tramp-debug-outline-regexp): Add a docstring. (tramp-debug-outline-level): Renamed from `tramp-outline-level'. (tramp-get-debug-buffer): Use it. * net/tramp-cache.el (top): Set tramp-autoload cookie for initialization forms. (tramp-set-connection-property): Don't protect `tramp-message' call, it isn't necessary any longer. (tramp-dump-connection-properties): Use `ignore-errors'. * net/tramp-compat.el (top): Require 'advice, 'format-spec, 'password-cache and 'auth-source. * net/tramp-gvfs.el (top): * net/tramp-smb.el (top): Require 'tramp-sh. * net/tramp-gw.el (tramp-gw-open-network-stream): Use `ignore-errors'. * net/tramp-sh.el: New file, derived from tramp.el. (top): Initialize `tramp-methods', `tramp-default-method-alist', `tramp-default-user-alist', tramp-foreign-file-name-handler-alist. Remove "scp1_old", "scp2_old", "ssh1_old", "ssh2_old". Use `ignore-errors' where appropriate. (tramp-sh-file-name-handler-alist): Renamed from `tramp-file-name-handler-alist'. (tramp-send-command-and-check): Return t or nil. Remove all `zerop' checks, where called. (tramp-handle-set-file-modes) (tramp-do-copy-or-rename-file-directly) (tramp-handle-delete-directory, tramp-handle-delete-file) (tramp-maybe-send-script, ): Use `tramp-barf-unless-okay'. (tramp-sh-file-name-handler, tramp-send-command-and-check) (tramp-get-remote-ln): Set tramp-autoload cookie. * net/tramp-fish.el: Remove file.
author Michael Albinus <michael.albinus@gmx.de>
date Mon, 13 Sep 2010 17:17:01 +0200
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84821
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 """Definitions used by commands sent to inferior Python in python.el."""
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100972
diff changeset
3 # Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
84821
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4 # Author: Dave Love <fx@gnu.org>
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 # This file is part of GNU Emacs.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7
95004
cbf5528cf447 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
8 # GNU Emacs is free software: you can redistribute it and/or modify
84821
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9 # it under the terms of the GNU General Public License as published by
95004
cbf5528cf447 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
cbf5528cf447 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
11 # (at your option) any later version.
84821
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 # GNU Emacs is distributed in the hope that it will be useful,
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 # GNU General Public License for more details.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
95004
cbf5528cf447 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
19 # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
84821
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 import os, sys, traceback, inspect, __main__
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 set
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 except:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 from sets import Set as set
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 __all__ = ["eexecfile", "eargs", "complete", "ehelp", "eimport", "modpath"]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 def format_exception (filename, should_remove_self):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 type, value, tb = sys.exc_info ()
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 sys.last_type = type
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 sys.last_value = value
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 sys.last_traceback = tb
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 if type is SyntaxError:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 try: # parse the error message
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 msg, (dummy_filename, lineno, offset, line) = value
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 except:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 pass # Not the format we expect; leave it alone
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 else:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 # Stuff in the right filename
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 value = SyntaxError(msg, (filename, lineno, offset, line))
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 sys.last_value = value
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 res = traceback.format_exception_only (type, value)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 # There are some compilation errors which do not provide traceback so we
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 # should not massage it.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 if should_remove_self:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 tblist = traceback.extract_tb (tb)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 del tblist[:1]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 res = traceback.format_list (tblist)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 if res:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 res.insert(0, "Traceback (most recent call last):\n")
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 res[len(res):] = traceback.format_exception_only (type, value)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 # traceback.print_exception(type, value, tb)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 for line in res: print line,
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 def eexecfile (file):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 """Execute FILE and then remove it.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 Execute the file within the __main__ namespace.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 If we get an exception, print a traceback with the top frame
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 (ourselves) excluded."""
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 # We cannot use real execfile since it has a bug where the file stays
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 # locked forever (under w32) if SyntaxError occurs.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 # --- code based on code.py and PyShell.py.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 source = open (file, "r").read()
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 code = compile (source, file, "exec")
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 # Other exceptions (shouldn't be any...) will (correctly) fall
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 # through to "final".
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 except (OverflowError, SyntaxError, ValueError):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 # FIXME: When can compile() raise anything else than
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 # SyntaxError ????
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 format_exception (file, False)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 return
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 exec code in __main__.__dict__
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 except:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 format_exception (file, True)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 finally:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 os.remove (file)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 def eargs (name, imports):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 "Get arglist of NAME for Eldoc &c."
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 if imports: exec imports
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 parts = name.split ('.')
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 if len (parts) > 1:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89 exec 'import ' + parts[0] # might fail
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 func = eval (name)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 if inspect.isbuiltin (func) or type(func) is type:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 doc = func.__doc__
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 if doc.find (' ->') != -1:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 print '_emacs_out', doc.split (' ->')[0]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 else:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 print '_emacs_out', doc.split ('\n')[0]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 return
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 if inspect.ismethod (func):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 func = func.im_func
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 if not inspect.isfunction (func):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 print '_emacs_out '
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 return
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 (args, varargs, varkw, defaults) = inspect.getargspec (func)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 # No space between name and arglist for consistency with builtins.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 print '_emacs_out', \
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 func.__name__ + inspect.formatargspec (args, varargs, varkw,
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 defaults)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 except:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 print "_emacs_out "
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 def all_names (object):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 """Return (an approximation to) a list of all possible attribute
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 names reachable via the attributes of OBJECT, i.e. roughly the
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 leaves of the dictionary tree under it."""
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 def do_object (object, names):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 if inspect.ismodule (object):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 do_module (object, names)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 elif inspect.isclass (object):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 do_class (object, names)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 # Might have an object without its class in scope.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 elif hasattr (object, '__class__'):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 names.add ('__class__')
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 do_class (object.__class__, names)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 # Probably not a good idea to try to enumerate arbitrary
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 # dictionaries...
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 return names
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 def do_module (module, names):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 if hasattr (module, '__all__'): # limited export list
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 names.update(module.__all__)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 for i in module.__all__:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 do_object (getattr (module, i), names)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 else: # use all names
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 names.update(dir (module))
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 for i in dir (module):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 do_object (getattr (module, i), names)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138 return names
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 def do_class (object, names):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 ns = dir (object)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 names.update(ns)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 if hasattr (object, '__bases__'): # superclasses
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 for i in object.__bases__: do_object (i, names)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 return names
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 return do_object (object, set([]))
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 def complete (name, imports):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 """Complete TEXT in NAMESPACE and print a Lisp list of completions.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 Exec IMPORTS first."""
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 import __main__, keyword
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 def class_members(object):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 names = dir (object)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 if hasattr (object, '__bases__'):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 for super in object.__bases__:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 names = class_members (super)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 return names
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 names = set([])
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 base = None
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 dict = __main__.__dict__.copy()
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 if imports: exec imports in dict
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 l = len (name)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 if not "." in name:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 for src in [dir (__builtins__), keyword.kwlist, dict.keys()]:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 for elt in src:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 if elt[:l] == name: names.add(elt)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 else:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 base = name[:name.rfind ('.')]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 name = name[name.rfind('.')+1:]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 object = eval (base, dict)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 names = set(dir (object))
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 if hasattr (object, '__class__'):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 names.add('__class__')
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 names.update(class_members (object))
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 except: names = all_names (dict)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181 except:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 print sys.exc_info()
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 names = []
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 l = len(name)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 print '_emacs_out (',
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 for n in names:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 if name == n[:l]:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 if base: print '"%s.%s"' % (base, n),
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 else: print '"%s"' % n,
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 print ')'
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 def ehelp (name, imports):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 """Get help on string NAME.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 First try to eval name for, e.g. user definitions where we need
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 the object. Otherwise try the string form."""
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 locls = {}
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198 if imports:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 try: exec imports in locls
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 except: pass
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 try: help (eval (name, globals(), locls))
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 except: help (name)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 def eimport (mod, dir):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 """Import module MOD with directory DIR at the head of the search path.
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 NB doesn't load from DIR if MOD shadows a system module."""
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 from __main__ import __dict__
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 path0 = sys.path[0]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 sys.path[0] = dir
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 if __dict__.has_key(mod) and inspect.ismodule (__dict__[mod]):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 reload (__dict__[mod])
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 else:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 __dict__[mod] = __import__ (mod)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 except:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (type, value, tb) = sys.exc_info ()
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 print "Traceback (most recent call last):"
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 traceback.print_exception (type, value, tb.tb_next)
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 finally:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 sys.path[0] = path0
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 def modpath (module):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 """Return the source file for the given MODULE (or None).
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226 Assumes that MODULE.py and MODULE.pyc are in the same directory."""
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 try:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228 path = __import__ (module).__file__
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229 if path[-4:] == '.pyc' and os.path.exists (path[0:-1]):
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230 path = path[:-1]
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231 print "_emacs_out", path
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
232 except:
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 print "_emacs_out ()"
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 # print '_emacs_ok' # ready for input and can call continuation
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236
fa7f4408009f Adam Hupp <adam at hupp.org>
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237 # arch-tag: d90408f3-90e2-4de4-99c2-6eb9c7b9ca46