Initial Commit
[packages] / xemacs-packages / oo-browser / br-init.el
1 ;;!emacs
2 ;;
3 ;; FILE:         br-init.el
4 ;; SUMMARY:      OO-Browser per Emacs session initialization.
5 ;; USAGE:        GNU Emacs Lisp Library
6 ;; KEYWORDS:     oop, tools
7 ;;
8 ;; AUTHOR:       Bob Weiner
9 ;; ORG:          BeOpen.com
10 ;;
11 ;; ORIG-DATE:    18-May-90
12 ;; LAST-MOD:      3-Aug-99 at 22:55:53 by Bob Weiner
13 ;;
14 ;; Copyright (C) 1990-1995, 1997, 1998 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 ;; DESCRIP-END.
21
22 ;;; ************************************************************************
23 ;;; Personal Variable Defaults
24 ;;; ************************************************************************
25
26 ;; >>> If you wish to edit classes displayed by the browser in an editor
27 ;;     other than Emacs, set the `br-editor-cmd' variable to the command you
28 ;;     want to edit with.  Arguments to the command should be placed in
29 ;;     `br-ed[1-9], with one string argument per variable'.  Keep in
30 ;;     mind that the command must generate a new window under your
31 ;;     window system.  For example, to run vi under X, one needs to use the
32 ;;     command line "xterm -e vi", the settings would then be:
33 ;;
34 ;;         (setq br-editor-cmd "xterm" br-ed1 "-e" 
35 ;;               br-ed2 "vi")
36 ;;
37 ;;     This editor will only be used when the browser is run under a window
38 ;;     system external to Emacs, like X.  (In such a case, the variable
39 ;;     `hyperb:window-system' will be non-nil).
40 ;;
41 ;;
42 (defvar br-editor-cmd nil
43   "When non-nil, the OO-Browser uses a non-standard command for editing files.
44 This may be either a string to invoke an external program or an Emacs
45 Lisp function which takes a single file argument.")
46
47 (setq br-ed1 nil br-ed2 nil br-ed3 nil br-ed4 nil br-ed5 nil
48         br-ed6 nil br-ed7 nil br-ed8 nil br-ed9 nil)
49
50 ;;
51 ;; >>> If you want to view classes in a read-only fashion outside of Emacs,
52 ;;     set the following `br-viewer-cmd' and `br-vw[1-9]' variables in a
53 ;;     similar manner as you did for the editor variables above.
54 ;;
55 ;;     For example, to use "xmore", an X-compatible version of more, as your
56 ;;     viewer, use the following settings:
57 ;;
58 ;;         (setq br-viewer-cmd "xmore")
59 ;;
60 (defvar br-viewer-cmd nil
61   "When non-nil, the OO-Browser uses a non-standard command for viewing files.
62 This may be either a string to invoke an external program or an Emacs
63 Lisp function which takes a single file argument.")
64
65 (setq br-vw1 nil br-vw2 nil br-vw3 nil br-vw4 nil br-vw5 nil
66         br-vw6 nil br-vw7 nil br-vw8 nil br-vw9 nil)
67
68 ;;
69 ;;
70 (defvar br-skip-dir-regexps
71   (if (eq system-type 'next-mach)
72       ;; .E is an Eiffel system directory
73       '("^CVS$" "^RCS$" "^SCCS$" "\\.lproj$" "^obj$" "\\.E$")
74     '("^CVS$" "^RCS$" "^SCCS$" "\\.E$"))
75   "*List of regexps matching the subdirectories that the OO-Browser will not descend when scanning source code.")
76
77 ;;; ************************************************************************
78 ;;; Public functions
79 ;;; ************************************************************************
80
81 (or (fboundp 'frame-width)  (defalias 'frame-width 'screen-width))
82 (or (fboundp 'frame-height) (defalias 'frame-width 'screen-height))
83 (or (fboundp 'selected-frame)
84     (cond ((fboundp 'selected-screen)
85            (defalias 'selected-frame 'selected-screen))
86           (t
87             (defun selected-frame ()
88               "Always return t since current frame is always selected."
89               t))))
90
91 (defun br-after-term-init ()
92   (let ((hypb (expand-file-name "hypb/" br-directory)))
93     (or (featurep 'hyperbole)
94         ;; br-site.el should have already loaded "hversion.el" if a full
95         ;; Hyperbole system is available.
96         (load "hyperbole" t t)
97         ;; Use Hyperbole mouse and keyboard handlers included with the
98         ;; OO-Browser since Hyperbole is not available on this system.
99         (progn (or (br-member hypb load-path)
100                    (setq load-path (cons hypb load-path)))
101                ;;
102                ;; Necessary to prevent action-key and assist-key from
103                ;; trying to load this Hyperbole library.
104                (provide 'hsite)
105                ;;
106                (if (boundp 'hmouse-bindings)
107                    ;; Mouse support has been initialized, possibly by Hyperbole.
108                    nil
109                  (require 'hmouse-key)
110                  ;; See the documentation for this function for instructions on how to
111                  ;; setup shifted or unshifted Action and Assist mouse buttons.
112                  (hmouse-shift-buttons))
113                ;;
114                (defvar hkey-init t
115                  "*A non-nil value (default) at system load time binds the Action and Assist Keyboard Keys.
116 {M-RET} invokes the Action Key and {C-u M-RET} invokes the Assist Key.
117 Additionally, {C-h A} shows what the Action Key will do in the current
118 context (wherever point is).  {C-u C-h A} shows what the Assist Key will do.")
119                ;;
120                (and hkey-init
121                     (require 'hmouse-key)
122                     (not (global-key-binding "\M-\C-m"))
123                     (global-set-key "\M-\C-m" 'hkey-either))
124                ;;
125                ;; Bind a key, {C-h A}, for Action Key help and {C-u C-h A}
126                ;; for Assist key help.
127                (and hkey-init
128                     (not (where-is-internal 'hkey-help))
129                     (define-key help-map "A" 'hkey-help))
130                
131                (defvar hkey-value nil
132                  "Communicates a value between a Smart Key predicate and its actions.")
133
134                ;; Setup Action and Assist keys to perform only
135                ;; browser-related actions.
136                (defvar hkey-alist
137                  '(
138                    ((and (not (eobp))
139                          (or (eolp) (and selective-display
140                                          (eq (following-char) ?\r)))) .
141                                          ((smart-scroll-up) . (smart-scroll-down)))
142                    ;;
143                    ;; If click in the minibuffer and reading an argument,
144                    ;; accept argument or give completion help.
145                    ((and (> (minibuffer-depth) 0)
146                          (eq (selected-window) (minibuffer-window))
147                          (not (eq hargs:reading-p 'hmenu))) .
148                          ((exit-minibuffer) . (smart-completion-help)))
149                    ;;
150                    ;; If reading a Hyperbole menu item or a Hyperbole completion-based
151                    ;; argument, allow selection of an item at point.
152                    ((if (> (minibuffer-depth) 0) (setq hkey-value (hargs:at-p))) .
153                     ((hargs:select-p hkey-value) .
154                      (hargs:select-p hkey-value 'assist)))
155                    ;;
156                    ;;
157                    ;; Within an OOBR-FTR buffer, an *Implementors* listing buffer, or
158                    ;; an Element signatures listing buffer from the OO-Browser.
159                    ((or (string-equal (buffer-name) "*Implementors*")
160                         (string-match "-Elements\\'" (buffer-name))
161                         (and (boundp 'br-feature-tags-file)
162                              (stringp br-feature-tags-file)
163                              (equal br-feature-tags-file buffer-file-name))) .
164                              ((smart-element) . (hkey-help)))
165                    ;;
166                    ;; Restore window config and hide help buffer when click
167                    ;; at buffer end.
168                    ((if (= (point) (point-max))
169                         (string-match "^\\*Help\\|Help\\*$" (buffer-name))) .
170                     ((hkey-help-hide) . (hkey-help-hide)))
171                    ;;
172                    ((and (memq major-mode '(c-mode c++-c-mode))
173                          buffer-file-name (smart-c-at-tag-p)) .
174                          ((smart-c) . (smart-c nil 'next-tag)))
175                    ;;
176                    ((if (smart-lisp-mode-p) (smart-lisp-at-tag-p)) .
177                     ((smart-lisp) . (smart-lisp 'next-tag)))
178                    ;;
179                    ((and (eq major-mode 'java-mode) buffer-file-name
180                          (or (smart-java-at-tag-p)
181                              ;; Also handle Java @see cross-references.
182                              (looking-at "@see[ \t]+")
183                              (save-excursion
184                                (and (re-search-backward "[@\n\r\f]" nil t)
185                                     (looking-at "@see[ \t]+"))))) .
186                                     ((smart-java) . (smart-java nil 'next-tag)))
187                    ;;
188                    ((and (eq major-mode 'c++-mode) buffer-file-name
189                          ;; Don't use smart-c++-at-tag-p here since it will prevent #include
190                          ;; lines from matching.
191                          (smart-c-at-tag-p)) .
192                          ((smart-c++) . (smart-c++ nil 'next-tag)))
193                    ;;
194                    ((and (eq major-mode 'objc-mode) buffer-file-name
195                          (smart-objc-at-tag-p)) .
196                          ((smart-objc) . (smart-objc nil 'next-tag)))
197                    ;;
198                    ((eq major-mode 'Buffer-menu-mode) .
199                     ((smart-buffer-menu) . (smart-buffer-menu-assist)))
200                    ;;
201                    ((eq major-mode 'dired-mode) . 
202                     ((smart-dired) . (smart-dired-assist)))
203                    ;;
204                    ((eq major-mode 'tar-mode) . 
205                     ((smart-tar) . (smart-tar-assist)))
206                    ;;
207                    ((or (br-in-browser) (eq major-mode 'br-mode)) .
208                     ((smart-br-dispatch) . (smart-br-assist-dispatch)))
209                    ;;
210                    (buffer-read-only . ((scroll-up) . (scroll-down)))
211                    )
212                  "Alist of predicates and form-conses for Action and Assist Keys.
213 When the Action or Assist Key is pressed, the first or second form,
214 respectively, associated with the first non-nil predicate is evaluated.")
215                ;;
216                ;; This next line must come after the definition of hkey-alist
217                ;; or the wrong definition will be used and an error will
218                ;; ensue when the {M-RET} key is pressed.
219                (require 'hui-mouse))))
220   ;;
221   (if (stringp br-editor-cmd)
222       (let ((br-editor-cmd (downcase br-editor-cmd)))
223         (and (string-match "emacs" br-editor-cmd)
224              (setq br-editor-cmd nil))))
225   (if (stringp br-viewer-cmd)
226       (let ((br-viewer-cmd (downcase br-viewer-cmd)))
227         (and (string-match "emacs" br-viewer-cmd)
228              (setq br-viewer-cmd nil))))
229   ;;
230   ;; Loads menus under non-tty InfoDock, XEmacs or Emacs19; does nothing
231   ;; otherwise.
232   (and (not (featurep 'br-menu)) hyperb:window-system
233        (or hyperb:xemacs-p hyperb:emacs19-p) (require 'br-menu))
234   ;;
235   (require 'br)
236   (require 'hmouse-br)
237   (require 'hmouse-drv)
238   (br-init-autoloads))
239
240 (defun br-init-autoloads ()
241   "Setup OO-Browser autoloaded functions."
242 ;  (autoload 'br-add-class-file "br" "Add file to OO-Browser Environment" t) 
243   (autoload 'br-env-browse "br-env" "Browse an existing OO-Browser Environment" t)
244   (autoload 'br-env-load  "br-env" "Load a new OO-Browser Environment" t)
245   (autoload 'br-to-from-viewer  "br" "Move between list and viewer windows" t)
246   ;;
247   (autoload 'hmail:compose      "hmail"
248     "Compose mail with ADDRESS and evaluation of EXPR." t)
249   (autoload 'hypb:configuration "hypb"
250     "Insert Emacs configuration information into OUT-BUF or current buffer." nil)
251   (autoload 'hypb:display-file-with-logo "hypb" "Display FILE with BeOpen.com logo." nil)
252   ;;
253   ;; Menu items could call this function before Info is loaded.
254   (autoload 'Info-goto-node     "info" "Jump to specific Info node."  t)
255   ;;
256   (autoload 'c++-browse  "c++-browse" "C++/C OO-Browser" t)
257   (autoload 'clos-browse "clos-brows" "Common Lisp OO-Browser" t)
258   (autoload 'eif-browse  "eif-browse" "Eiffel OO-Browser" t)
259   (autoload 'info-browse "info-brows" "Info OO-Browser" t)
260   (autoload 'java-browse "java-brows" "Java OO-Browser" t)
261   (autoload 'objc-browse "objc-brows" "Objective-C OO-Browser" t)
262   (autoload 'python-browse "pyth-brows" "Python OO-Browser" t)
263   (autoload 'smt-browse  "smt-browse" "Smalltalk OO-Browser" t)
264   ;;
265   ;; Hyperbole tag-related functions
266   (autoload 'smart-asm-at-tag-p "hmouse-tag" "Return assembly tag name that point is within, else nil." nil nil)
267   (autoload 'smart-c-at-tag-p "hmouse-tag" "Return C tag name that point is within, else nil." nil nil)
268   (autoload 'smart-c++ "hmouse-tag" "Jumps to the definition of optional C++ IDENTIFIER or the one at point.
269 Optional second arg NEXT means jump to next matching C++ tag.
270
271 It assumes that its caller has already checked that the key was pressed in an
272 appropriate buffer and has moved the cursor to the selected buffer.
273
274 If:
275  (1) on a `#include' statement, the include file is displayed;
276      Look for include file in directory lists `smart-c-cpp-include-dirs'
277      and `smart-c-include-dirs'.
278  (2) on a C++ identifier, the identifier definition is displayed,
279      assuming the identifier is found within an `etags' generated tag file
280      in the current directory or any of its ancestor directories.
281  (3) if `smart-c-use-lib-man' is non-nil, the C++ identifier is
282      recognized as a library symbol, and a man page is found for the
283      identifier, then the man page is displayed." t nil)
284   (autoload 'smart-c++-tag "hmouse-tag" nil nil nil)
285   (autoload 'smart-fortran-at-tag-p "hmouse-tag" "Jumps to Fortran identifier definitions.")
286   (autoload 'smart-java "hmouse-tag" "Jumps to the definition of optional Java IDENTIFIER or the one at point.
287 Optional second arg NEXT means jump to next matching Java tag.
288
289 It assumes that its caller has already checked that the key was pressed in an
290 appropriate buffer and has moved the cursor to the selected buffer.
291
292 If:
293  (1) within a commented @see cross-reference, the referent is displayed;
294  (2) on a `package' or `import' statement, the referent is displayed;
295      Look for referent files in the directory list `smart-java-package-dirs'.
296  (3) on a Java identifier, the identifier definition is displayed,
297      assuming the identifier is found within an `etags' generated tag file
298      in the current directory or any of its ancestor directories." t nil)
299   (autoload 'smart-java-tag "hmouse-tag" nil nil nil)
300   (autoload 'smart-java-at-tag-p "hmouse-tag" "Return Java tag name that point is within, else nil." nil nil)
301   (autoload 'smart-lisp-mode-p "hmouse-tag" "Return t if in a mode which uses Lisp symbols." nil nil)
302   (autoload 'smart-objc "hmouse-tag" "Jumps to the definition of optional Objective-C IDENTIFIER or the one at point.
303 Optional second arg NEXT means jump to next matching Objective-C tag.
304
305 It assumes that its caller has already checked that the key was pressed in an
306 appropriate buffer and has moved the cursor to the selected buffer.
307
308 If:
309  (1) on a `#include' statement, the include file is displayed;
310      Look for include file in directory lists `smart-c-cpp-include-dirs'
311      and `smart-c-include-dirs'.
312  (2) on an Objective-C identifier, the identifier definition is displayed,
313      assuming the identifier is found within an `etags' generated tag file
314      in the current directory or any of its ancestor directories.
315  (3) if `smart-c-use-lib-man' is non-nil, the Objective-C identifier is
316      recognized as a library symbol, and a man page is found for the
317      identifier, then the man page is displayed." t nil)
318   (autoload 'smart-objc-tag "hmouse-tag" nil nil nil)
319   (autoload 'smart-tags-file-list "hmouse-tag" "Return list of appropriate tags files for optional CURR-DIR-OR-FILENAME or for `default-directory'.
320 Optional NAME-OF-TAGS-FILE is the literal filename for which to look." nil nil)
321   (autoload 'smart-tags-file-path "hmouse-tag" "Expand relative FILE name by looking it up within appropriate tags files.
322 Return FILE unchanged if it exists relative to the current directory or
323 cannot be expanded via a tags file." nil nil)
324   )
325
326 ;;; ************************************************************************
327 ;;; Internal functions
328 ;;; ************************************************************************
329
330 (provide 'br-init)