1 ;;; hversion.el --- Hyperbole version, system and load path information.
3 ;; Copyright (C) 1994, 1995, 2004, 2005, 2006, 2007, 2008 Free
4 ;; Software Foundation, Inc. Developed with support from Motorola
7 ;; Author: Bob Weiner, Brown U.
8 ;; Maintainer: Mats Lidell <matsl@contactor.se>
9 ;; Keywords: hypermedia
11 ;; This file is part of GNU Hyperbole.
13 ;; GNU Hyperbole is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 3, or (at
16 ;; your option) any later version.
18 ;; GNU Hyperbole is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
36 (defconst hyperb:version "5.0.5" "Hyperbole revision number.")
38 ;;; Support button highlighting and flashing under XEmacs.
40 (defvar hyperb:xemacs-p
41 (let ((case-fold-search t))
42 (if (string-match "XEmacs" emacs-version)
44 "Version string under XEmacs (not Lucid Emacs) or nil")
46 ;;; Support mouse handling under GNU Emacs V19 and beyond.
48 (defvar hyperb:emacs19-p
49 (and (not hyperb:xemacs-p)
50 (string-match "^\\(19\\|2[0-9]\\)\\." emacs-version)
52 "Version string under GNU Emacs 19 or nil")
54 ;;; Support button highlighting and flashing under obsolete Epoch.
56 (defvar hyperb:epoch-p
57 (if (and (boundp 'epoch::version)
58 (stringp epoch::version))
59 (if (string< epoch::version "Epoch 4") "V3" "V4"))
60 "Simplified version string under Epoch, e.g. \"V4\", or nil")
62 ;; Koutlines work only with specific versions of Emacs 19 and XEmacs.
63 (defconst hyperb:kotl-p
65 ;; Only works for XEmacs 19.9 and above.
66 (emacs-version>= 19 9)
68 "Non-nil iff this Emacs version supports the Hyperbole outliner.")
70 ;; Used by OO-Browser (Deprecated!?)
71 (defconst hyperb:microcruft-os-p
72 (memq system-type '(windows-nt ms-dos))
73 "T iff Hyperbole is running under Windows or DOS.")
75 (defun sm-window-sys-term ()
76 "Returns the first part of the term-type if running under a window system, else nil.
77 Where a part in the term-type is delimited by a '-' or an '_'."
78 (let ((term (cond ((memq window-system '(x gtk ns dps pm mswindows))
79 ;; X11, NEXTSTEP (DPS), or OS/2 Presentation Manager (PM)
80 (cond (hyperb:emacs19-p "emacs19")
81 (hyperb:xemacs-p "xemacs")
82 (hyperb:epoch-p "epoch")
84 ((or (featurep 'eterm-fns)
85 (equal (getenv "TERM") "NeXT")
86 (equal (getenv "TERM") "eterm"))
87 ;; NEXTSTEP add-on support to Emacs
90 (featurep 'sun-mouse) (featurep 'apollo))
93 (substring term 0 (string-match "[-_]" term)))))
95 (defconst hyperb:window-system (sm-window-sys-term)
96 "String name for window system or term type under which Emacs was run.
97 If nil, no window system or mouse support is available.")
100 ;;; Public functions to dynamically compute Hyperbole directory.
103 (defvar hyperb:automount-prefixes
104 (if (and (boundp 'automount-dir-prefix) (stringp automount-dir-prefix))
107 "*Regexp to match any automounter prefix in a pathname."))
109 (defun hyperb:stack-frame (function-list &optional debug-flag)
110 "Return the nearest Emacs Lisp stack frame which called any function symbol from FUNCTION-LIST or nil if no match.
111 If FUNCTION-LIST contains 'load, 'autoload or 'require, detect
112 autoloads not visible within the Lisp level stack frames.
114 With optional DEBUG-FLAG non-nil, if no matching frame is found, return list
115 of stack frames (from innermost to outermost)."
118 (load-flag (or (memq 'load function-list)
119 (memq 'autoload function-list)
120 (memq 'require function-list)))
124 (or (catch 'hyperb:stack-frame
125 (while (setq frame (backtrace-frame count))
126 (if debug-flag (setq frame-list (cons frame frame-list)))
127 (setq count (1+ count)
128 fsymbol (nth 1 frame))
129 (and (eq fsymbol 'command-execute)
130 (not (memq 'command-execute function-list))
131 ;; Use command being executed instead because it might not
132 ;; show up in the stack anywhere else, e.g. if it is an
133 ;; autoload under Emacs 19.
134 (setq fsymbol (nth 2 frame)))
135 (cond ((and load-flag (symbolp fsymbol)
137 (listp (setq fbody (symbol-function fsymbol)))
138 (eq (car fbody) 'autoload))
139 (setq frame (list (car frame) 'load
141 nil noninteractive nil))
142 (throw 'hyperb:stack-frame frame))
143 ((memq fsymbol function-list)
144 (throw 'hyperb:stack-frame frame))))
146 (if debug-flag (nreverse frame-list)))))
148 (defun hyperb:path-being-loaded ()
149 "Return the full pathname used by the innermost `load' or 'require' call.
150 Removes any matches for `hyperb:automount-prefixes' before returning
152 (let* ((frame (hyperb:stack-frame '(load require)))
153 (function (nth 1 frame))
155 (cond ((eq function 'load)
156 (setq file (nth 2 frame)
157 nosuffix (nth 5 frame)))
158 ((eq function 'require)
159 (setq file (or (nth 3 frame) (symbol-name (nth 2 frame))))))
161 (setq nosuffix (or nosuffix
163 "\\.\\(elc?\\|elc?\\.gz\\|elc?\\.Z\\)$"
165 file (substitute-in-file-name file)
166 file (locate-file file load-path
167 (if (null nosuffix) '(".elc" ".el" ".el.gz" ".el.Z"))
168 ;; accept any existing file
170 file (if (and (stringp file)
171 (string-match hyperb:automount-prefixes file))
172 (substring file (1- (match-end 0)))
175 (if (fboundp 'locate-file)
177 (defun locate-file (file dir-list &optional suffixes unused)
178 "Search for FILE in DIR-LIST.
179 If optional SUFFIXES is provided, it should be a list of suffixes to append to file name when searching."
180 (if (and (file-name-absolute-p file) (file-readable-p file))
181 file;; file exists without suffix addition, so return it
182 (if (file-name-absolute-p file) (setq dir-list '(nil)))
183 (if (equal file "") (error "(locate-file): Empty file argument"))
184 (let (suffxs pathname)
185 ;; Search dir-list for a matching, readable file.
188 (setq suffxs (or suffixes '(nil)))
190 (setq pathname (expand-file-name
191 (concat file (car suffxs))
193 (if (file-readable-p pathname)
194 (throw 'found pathname))
195 (setq suffxs (cdr suffxs)))
196 (setq dir-list (cdr dir-list))))))))
199 ;;; Public functions used by pulldown and popup menus
202 (if (not (fboundp 'id-browse-file))
203 (fset 'id-browse-file 'find-file-read-only))
205 (if (not (fboundp 'id-info))
206 (defun id-info (node)
207 (if (br-in-browser) (br-to-view-window))
208 (Info-goto-node node)))
210 (if (not (fboundp 'id-tool-quit)) (fset 'id-tool-quit 'eval))
212 (if (not (fboundp 'id-tool-invoke))
213 (defun id-tool-invoke (sexp)
215 (call-interactively sexp)
220 ;;; hversion.el ends here