Initial Commit
[packages] / xemacs-packages / oo-browser / c++-browse.el
1 ;;!emacs
2 ;;
3 ;; FILE:         c++-browse.el
4 ;; SUMMARY:      C++ source code browser.
5 ;; USAGE:        GNU Emacs Lisp Library
6 ;; KEYWORDS:     c, oop, tools
7 ;;
8 ;; AUTHOR:       Bob Weiner
9 ;; ORG:          BeOpen.com
10 ;;
11 ;; ORIG-DATE:    12-Dec-89
12 ;; LAST-MOD:     10-May-01 at 12:49:26 by Bob Weiner
13 ;;
14 ;; Copyright (C) 1989-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 `c++-browse' to invoke the C++ OO-Browser.  Prefix arg prompts for
22 ;;    name of Environment file.
23 ;;
24 ;; DESCRIP-END.
25
26 ;; ************************************************************************
27 ;; Other required Elisp libraries
28 ;; ************************************************************************
29
30 (mapcar 'require '(br-start br br-c++-ft))
31
32 ;;; ************************************************************************
33 ;;; Public functions
34 ;;; ************************************************************************
35
36 ;;;###autoload
37 (defun c++-browse (&optional env-file no-ui)
38   "Invoke the C++ OO-Browser.
39 This allows browsing through C++ library and system class hierarchies.  With
40 an optional non-nil prefix argument ENV-FILE, prompt for Environment file to
41 use.  Alternatively, a string value of ENV-FILE is used as the Environment
42 file name.  See also the file \"br-help\"."
43   (interactive "P")
44   (let ((same-lang (equal br-lang-prefix c++-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 c++-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 c++-env-file env-file)
56                        (and (null env-file)
57                             (or c++-lib-search-dirs c++-sys-search-dirs)
58                             t)))
59     (cond
60      (same-env
61       ;; If we just switched languages, restore the cached data for the new
62       ;; Environment.
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       (c++-browse-setup env-file)
67       (if (or (null br-paths-htable) (equal br-paths-htable br-empty-htable))
68           (setq load-succeeded
69                 (br-env-try-load (or env-file br-env-file) br-env-file))))
70      ;;
71      ;; Create default Environment file specification if needed and none
72      ;; exists.
73      ;;
74      (t (or env-file (file-exists-p c++-env-file)
75             (br-env-create c++-env-file c++-lang-prefix))
76         (or env-file (setq env-file c++-env-file))
77         ;;
78         ;; Start browsing a new Environment.
79         ;;
80         (c++-browse-setup env-file)
81         (setq load-succeeded (br-env-init env-file same-lang nil))
82         (if load-succeeded
83             (setq *br-save-wconfig* nil
84                   c++-env-file br-env-file
85                   c++-env-name br-env-name
86                   c++-sys-search-dirs br-sys-search-dirs
87                   c++-lib-search-dirs br-lib-search-dirs))))
88     (cond (load-succeeded
89            (if no-ui
90                nil
91              (br-browse)
92              (or (and same-lang same-env) (br-refresh))))
93           (no-ui nil)
94           (t (message "(c++-browse): You must build the Environment to browse it.")))))
95
96 ;; Don't filter Environment classes when listed.
97 (defalias 'c++-class-list-filter 'br-class-list-identity)
98
99 (defun c++-mode-setup ()
100   "Load best available C++ major mode and set `br-lang-mode' to the function that invokes it."
101   (defalias 'br-lang-mode
102         (cond ((or (featurep 'cc-mode) (featurep 'c++-mode))
103                'c++-mode)
104               ((load "cc-mode" 'missing-ok 'nomessage)
105                (provide 'c++-mode))
106               ((load "c++-mode" 'missing-ok 'nomessage)
107                (provide 'c++-mode))
108               ((featurep 'c-mode) 'c-mode)
109               ((load "c-mode" nil 'nomessage)
110                (provide 'c-mode))))
111   (condition-case ()
112       (progn (require 'cc-mode)
113              (c-initialize-cc-mode))
114     (error nil)))
115
116 ;;; ************************************************************************
117 ;;; Internal functions
118 ;;; ************************************************************************
119
120 (defun c++-browse-setup (env-file)
121   "Setup language-dependent functions for OO-Browser."
122   (br-setup-functions)
123   (c++-mode-setup)
124   (br-setup-constants env-file)
125   ;; Setup to add default classes to system class table after building it.
126   ;; This must come after br-setup-constants call since it clears these
127   ;; hooks.
128   (if (fboundp 'add-hook)
129       (add-hook 'br-after-build-sys-hook 'c++-add-default-classes)
130     (setq br-after-build-sys-hook '(c++-add-default-classes))))
131
132 (provide 'c++-browse)