Initial Commit
[packages] / xemacs-packages / oo-browser / info-brows.el
1 ;;!emacs
2 ;;
3 ;; FILE:         info-brows.el
4 ;; SUMMARY:      Support routines for Info inheritance browsing and error parsing.
5 ;; USAGE:        GNU Emacs Lisp Library
6 ;; KEYWORDS:     docs, help, hypermedia
7 ;;
8 ;; AUTHOR:       Bob Weiner
9 ;; ORG:          BeOpen.com
10 ;;
11 ;; ORIG-DATE:     7-Dec-89
12 ;; LAST-MOD:     10-May-01 at 12:52:49 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 `info-browse' to invoke the Info 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 '(info br-start br br-info))
31
32 ;;; ************************************************************************
33 ;;; Public functions
34 ;;; ************************************************************************
35
36 ;;;###autoload
37 (defun info-browse (&optional env-file no-ui)
38   "Invoke the Info OO-Browser.
39 This allows browsing through Info 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 info-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 info-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 info-env-file env-file)
56                        (and (null env-file)
57                             (or info-lib-search-dirs info-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       (info-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      ;;
71      ;; Create default Environment file specification if needed and none
72      ;; exists.
73      ;;
74      (t (or env-file (file-exists-p info-env-file)
75             (br-env-create info-env-file info-lang-prefix))
76         (or env-file (setq env-file info-env-file))
77         ;;
78         ;; Start browsing a new Environment.
79         ;;
80         (info-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                   info-env-file br-env-file
85                   info-env-name br-env-name
86                   info-sys-search-dirs br-sys-search-dirs
87                   info-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 "(info-browse): You must build the Environment to browse it.")))))
95
96 ;; Don't filter Environment classes when listed.
97 (defalias 'info-class-list-filter 'br-class-list-identity)
98
99 (defun info-class-definition-regexp (class)
100   "Return regexp to uniquely match the definition of CLASS name."
101   (concat info-class-name-before (regexp-quote class)
102           info-class-name-after))
103
104 ;;; ************************************************************************
105 ;;; Internal functions
106 ;;; ************************************************************************
107
108 (defun info-find-nd-name ()
109   (let ((end))
110     (save-excursion
111       (skip-chars-forward info-identifier-chars)
112       (setq end (point))
113       (skip-chars-backward info-identifier-chars)
114       (skip-chars-forward " \n\r")
115       (br-buffer-substring (point) end))))
116
117 (defun info-browse-setup (env-file)
118   "Setup language-dependent functions for OO-Browser."
119   (br-setup-functions)
120   (defalias 'br-lang-mode 'Info-mode)
121   (defalias 'br-find-class-name 'info-find-nd-name)
122   (br-setup-constants env-file))
123
124 (provide 'info-browse)