4 ;; SUMMARY: Python source code browser.
5 ;; USAGE: GNU Emacs Lisp Library
6 ;; KEYWORDS: oop, tools, python
8 ;; AUTHOR: Harri Pasanen / Bob Weiner
9 ;; based on Smalltalk and C++ OO-Browsers
12 ;; ORIG-DATE: 5-Apr-96
13 ;; LAST-MOD: 10-May-01 at 12:47:52 by Bob Weiner
15 ;; Copyright (C) 1996, 1997, 1998 BeOpen.com
16 ;; See the file BR-COPY for license information.
18 ;; This file is part of the OO-Browser.
22 ;; Use 'python-browse' to invoke the Python OO-Browser. Prefix arg
23 ;; prompts for name of Environment file.
27 ;;; ************************************************************************
28 ;;; Other required Elisp libraries
29 ;;; ************************************************************************
31 (mapcar 'require '(br-start br br-python-ft))
33 ;;; ************************************************************************
35 ;;; ************************************************************************
38 (defun python-browse (&optional env-file no-ui)
39 "Invoke the Python OO-Browser.
40 This allows browsing through Python library and system class hierarchies.
41 With an optional non-nil prefix argument ENV-FILE, prompt for Environment
42 file to use. Alternatively, a string value of ENV-FILE is used as the
43 Environment file name. See also the file \"br-help\"."
45 (let ((same-lang (equal br-lang-prefix python-lang-prefix))
50 ;; Save other language Environment in memory
51 (if br-lang-prefix (br-env-copy nil))
52 (setq br-lang-prefix python-lang-prefix
53 *br-save-wconfig* nil))
54 ;; `same-env' non-nil means the new Env is the previous Env or the most
55 ;; recent previous Env of the same language as the new Env
56 (setq same-env (or (equal python-env-file env-file)
58 (or python-lib-search-dirs python-sys-search-dirs))))
61 ;; If we just switched languages, restore the cached data for the new
63 (if same-lang nil (br-env-copy t))
64 ;; Environment may appear to be the same but its loading may have
65 ;; been interrupted, so ensure all variables are initialized properly.
66 (python-browse-setup env-file)
67 (if (or (null br-paths-htable) (equal br-paths-htable br-empty-htable))
69 (br-env-try-load (or env-file br-env-file) br-env-file))))
71 ;; Create default Environment file specification if needed and none
74 (t (or env-file (file-exists-p python-env-file)
75 (br-env-create python-env-file python-lang-prefix))
76 (or env-file (setq env-file python-env-file))
78 ;; Start browsing a new Environment.
80 (python-browse-setup env-file)
81 (setq load-succeeded (br-env-init env-file same-lang nil))
83 (setq *br-save-wconfig* nil
84 python-env-file br-env-file
85 python-env-name br-env-name
86 python-sys-search-dirs br-sys-search-dirs
87 python-lib-search-dirs br-lib-search-dirs))))
92 (or (and same-lang same-env) (br-refresh))))
94 (t (message "(python-browse): You must build the Environment to browse it.")))))
96 ;; Don't filter Environment classes when listed.
97 (defalias 'python-class-list-filter 'br-class-list-identity)
99 (defun python-lang-mode ()
100 "Invoke normal-mode for programming language buffers and python-mode for any others."
102 (if (not (memq major-mode '(python-mode c-mode c++-mode java-mode)))
105 (defun python-mode-setup ()
106 "Load best available Python major mode and set 'br-lang-mode' to the function that invokes it."
107 (defalias 'br-lang-mode 'python-lang-mode))
109 ;;; ************************************************************************
110 ;;; Internal functions
111 ;;; ************************************************************************
113 (defun python-browse-setup (env-file)
114 "Setup language-dependent functions for OO-Browser."
117 (br-setup-constants env-file)
118 ;; Setup to add default classes to system class table after building it.
119 ;; This must come after br-setup-constants call since it clears these
121 (if (fboundp 'add-hook)
122 (add-hook 'br-after-build-sys-hook 'python-add-default-classes)
123 (setq br-after-build-sys-hook '(python-add-default-classes))))
125 (provide 'pyth-brows)