Initial Commit
[packages] / xemacs-packages / oo-browser / smt-browse.el
1 ;;!emacs
2 ;;
3 ;; FILE:         smt-browse.el
4 ;; SUMMARY:      Smalltalk source code browser.
5 ;; USAGE:        GNU Emacs Lisp Library
6 ;; KEYWORDS:     oop, tools
7 ;;
8 ;; AUTHOR:       Bob Weiner
9 ;; ORG:          BeOpen.com
10 ;;
11 ;; ORIG-DATE:    26-Jul-90
12 ;; LAST-MOD:     10-May-01 at 12:54:27 by Bob Weiner
13 ;;
14 ;; Copyright (C) 1990-1995, 1997  BeOpen.com
15 ;; See the file BR-COPY for license information.
16 ;;
17 ;; This file is part of the OO-Browser.
18 ;;
19 ;; DESCRIPTION:  
20 ;;
21 ;;    Use `smt-browse' to invoke the Smalltalk OO-Browser.  Prefix arg
22 ;;    prompts for name of Environment file.
23 ;;
24 ;; DESCRIP-END.
25
26 ;;; ************************************************************************
27 ;;; Other required Elisp libraries
28 ;;; ************************************************************************
29
30 (mapcar 'require '(br-start br br-smt))
31
32 ;;; ************************************************************************
33 ;;; Public functions
34 ;;; ************************************************************************
35
36 ;;;###autoload
37 (defun smt-browse (&optional env-file no-ui)
38   "Invoke the Smalltalk OO-Browser.
39 This allows browsing through Smalltalk library and system class hierarchies.
40 With an optional non-nil prefix argument ENV-FILE, prompt for Environment
41 file to use.  Alternatively, a string value of ENV-FILE is used as the
42 Environment file name.  See also the file \"br-help\"."
43   (interactive "P")
44   (let ((same-lang (equal br-lang-prefix smt-lang-prefix))
45         (load-succeeded t)
46         same-env)
47     (if same-lang
48         nil
49       ;; Save other language Environment in memory
50       (if br-lang-prefix (br-env-copy nil))
51       (setq br-lang-prefix smt-lang-prefix
52             *br-save-wconfig* nil))
53     ;; `same-env' non-nil means the new Env is the previous Env or the most
54     ;; recent previous Env of the same language as the new Env
55     (setq same-env (or (equal smt-env-file env-file)
56                        (and (null env-file)
57                             (or smt-lib-search-dirs smt-sys-search-dirs))))
58     (cond
59      (same-env
60       ;; If we just switched languages, restore the cached data for the new
61       ;; Environment.
62       (if same-lang nil (br-env-copy t))
63       ;; Environment may appear to be the same but its loading may have
64       ;; been interrupted, so ensure all variables are initialized properly.
65       (smt-browse-setup env-file)
66       (if (or (null br-paths-htable) (equal br-paths-htable br-empty-htable))
67           (setq load-succeeded
68                 (br-env-try-load (or env-file br-env-file) br-env-file))))
69      ;;
70      ;; Create default Environment file specification if needed and none
71      ;; exists.
72      ;;
73      (t (or env-file (file-exists-p smt-env-file)
74             (br-env-create smt-env-file smt-lang-prefix))
75         (or env-file (setq env-file smt-env-file))
76         ;;
77         ;; Start browsing a new Environment.
78         ;;
79         (smt-browse-setup env-file)
80         (setq load-succeeded (br-env-init env-file same-lang nil))
81         (if load-succeeded
82             (setq *br-save-wconfig* nil
83                   smt-env-file br-env-file
84                   smt-env-name br-env-name
85                   smt-sys-search-dirs br-sys-search-dirs
86                   smt-lib-search-dirs br-lib-search-dirs))))
87     (cond (load-succeeded
88            (if no-ui
89                nil
90              (br-browse)
91              (or (and same-lang same-env) (br-refresh))))
92           (no-ui nil)
93           (t (message "(smt-browse): You must build the Environment to browse it.")))))
94
95 ;; Don't filter Environment classes when listed.
96 (defalias 'smt-class-list-filter 'br-class-list-identity)
97
98 (defun smt-class-definition-regexp (class)
99   "Return regexp to uniquely match the definition of CLASS name."
100   (concat smt-class-name-before (regexp-quote class)
101           smt-class-name-after))
102
103 ;;; ************************************************************************
104 ;;; Internal functions
105 ;;; ************************************************************************
106
107 (defun smt-browse-setup (env-file)
108   "Setup language-dependent functions for OO-Browser."
109   (br-setup-functions)
110   (defalias 'br-lang-mode
111         (cond ((featurep 'smalltalk-mode) 'smalltalk-mode)
112               ((load "st" 'missing-ok 'nomessage)
113                (provide 'smalltalk-mode))
114               (t 'fundamental-mode)))
115   (br-setup-constants env-file))
116
117 (provide 'smt-browse)