4 ;; SUMMARY: Objective-C source code browser.
5 ;; USAGE: GNU Emacs Lisp Library
6 ;; KEYWORDS: c, oop, tools
11 ;; ORIG-DATE: 12-Dec-89
12 ;; LAST-MOD: 10-May-01 at 12:54:09 by Bob Weiner
14 ;; Copyright (C) 1989-1995, 1997 BeOpen.com
15 ;; See the file BR-COPY for license information.
17 ;; This file is part of the OO-Browser.
21 ;; Use 'objc-browse' to invoke the Objective-C OO-Browser. Prefix arg
22 ;; prompts for name of Environment file.
31 ;;; ************************************************************************
33 ;;; ************************************************************************
38 ;; Use default environment, objc-env-file
39 ;; if objc not loaded, load it
40 ;; if objc-env-file != br-env-file
47 ;; else if env != br-env
50 ;; env-file = filename
54 ;; objc-env-file = br-env-file
57 (defun objc-browse (&optional env-file no-ui)
58 "Invoke the Objective-C OO-Browser.
59 This allows browsing through Objective-C library and system class
60 hierarchies. With an optional non-nil prefix argument ENV-FILE, prompt for
61 Environment file to use. Alternatively, a string value of ENV-FILE is used
62 as the Environment file name. See also the file \"br-help\"."
64 (let ((same-lang (equal br-lang-prefix objc-lang-prefix))
69 ;; Save other language Environment in memory
70 (if br-lang-prefix (br-env-copy nil))
71 (setq br-lang-prefix objc-lang-prefix
72 *br-save-wconfig* nil))
73 ;; `same-env' non-nil means the new Env is the previous Env or the most
74 ;; recent previous Env of the same language as the new Env
75 (setq same-env (or (equal objc-env-file env-file)
77 (or objc-lib-search-dirs objc-sys-search-dirs))))
80 ;; If we just switched languages, restore the cached data for the new
82 (if same-lang nil (br-env-copy t))
83 ;; Environment may appear to be the same but its loading may have
84 ;; been interrupted, so ensure all variables are initialized properly.
85 (objc-browse-setup env-file)
86 (if (or (null br-paths-htable) (equal br-paths-htable br-empty-htable))
88 (br-env-try-load (or env-file br-env-file) br-env-file))))
90 ;; Create default Environment file specification if needed and none
93 (t (or env-file (file-exists-p objc-env-file)
94 (br-env-create objc-env-file objc-lang-prefix))
95 (or env-file (setq env-file objc-env-file))
97 ;; Start browsing a new Environment.
99 (objc-browse-setup env-file)
100 (setq load-succeeded (br-env-init env-file same-lang nil))
102 (setq *br-save-wconfig* nil
103 objc-env-file br-env-file
104 objc-env-name br-env-name
105 objc-sys-search-dirs br-sys-search-dirs
106 objc-lib-search-dirs br-lib-search-dirs))))
107 (cond (load-succeeded
111 (or (and same-lang same-env) (br-refresh))))
113 (t (message "(objc-browse): You must build the Environment to browse it.")))))
115 (defun objc-class-list-filter (class-list top-only-flag)
116 "Return CLASS-LIST sans any protocol or class category entries.
117 Used when Environment classes are listed in the initial listing buffer."
129 ((string-match "\(" class) nil)
130 ;; protocol / abstract class
131 ((string-match "\\`<" class)
132 (if br-protocols-with-classes-flag
133 (if (br-get-parents class)
136 (objc-class-list-filter
137 (br-get-children class) t)))
139 ;; Regular class; because of recursion
140 ;; from the above clause, we must ensure
141 ;; that this class has no concrete parents
142 (t (setq parents (br-get-parents class))
143 (if (or (null parents)
148 (not (string-match "\\`<" parent))))
152 (br-protocols-with-classes-flag class-list)
153 (t (delq nil (mapcar (function
155 (if (string-match "[\(\<]" class)
160 (defun objc-mode-setup ()
161 "Load best available Objective-C major mode and set 'br-lang-mode' to the function that invokes it."
162 (defalias 'br-lang-mode
163 (cond ((or (fboundp 'objc-mode) (featurep 'objc-mode)) 'objc-mode)
164 ((load "objc-mode" t 'nomessage) 'objc-mode)
165 ((featurep 'c-mode) 'c-mode)
166 ((load "cc-mode" 'missing-ok 'nomessage)
167 (if (fboundp 'objc-mode) 'objc-mode 'c-mode))
168 ((load "c-mode" nil 'nomessage)
171 (progn (require 'cc-mode)
172 (c-initialize-cc-mode))
175 ;;; ************************************************************************
176 ;;; Internal functions
177 ;;; ************************************************************************
179 (defun objc-browse-setup (env-file)
180 "Setup language-dependent functions for OO-Browser."
183 (br-setup-constants env-file)
184 ;; Setup to add default classes ([category] and [protocol]) to system class
185 ;; table after building it. This must come after br-setup-constants call
186 ;; since it clears these hooks.
187 (if (fboundp 'add-hook)
188 (add-hook 'br-after-build-sys-hook 'objc-add-default-classes)
189 (setq br-after-build-sys-hook '(objc-add-default-classes))))