initial commit
[emacs-init.git] / nxhtml / autostart.el
1 ;;; autostart.el --- Load nxhtml
2 ;;
3 ;; Author: By: Lennart Borgman
4 ;; Created: Fri Dec 15 2006
5 ;; Version:
6 ;; Last-Updated: 2009-04-30 Thu
7 ;; Keywords:
8 ;; Compatibility:
9 ;;
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ;;
12 ;;; Commentary:
13 ;;
14 ;;
15 ;;
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;
18 ;;; Change log:
19 ;;
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;
23 ;; This program is free software; you can redistribute it and/or modify
24 ;; it under the terms of the GNU General Public License as published by
25 ;; the Free Software Foundation; either version 2, or (at your option)
26 ;; any later version.
27 ;;
28 ;; This program is distributed in the hope that it will be useful,
29 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
30 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 ;; GNU General Public License for more details.
32 ;;
33 ;; You should have received a copy of the GNU General Public License
34 ;; along with this program; see the file COPYING.  If not, write to the
35 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
36 ;; Boston, MA 02111-1307, USA.
37 ;;
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;;
40 ;;; Code:
41
42 ;; Fix-me: Split out the definitions from this file so it can be
43 ;; loaded during byte compilation.
44
45 ;;(eval-when-compile (require 'web-vcs nil t))
46 ;;(eval-when-compile (require 'nxhtml-web-vcs nil t))
47
48 (message "Nxml/Nxhtml Autostart.el loading ...")
49
50 (defconst nxhtml-autostart-trace nil)
51 (defsubst nxhtml-autostart-trace (format-string &rest args)
52   (when nxhtml-autostart-trace
53     (apply 'message format-string args)))
54
55 (defconst nxhtml-load-time-start (float-time))
56
57 ;; Add this dir to load-path
58 (add-to-list 'load-path
59              (file-name-directory (or load-file-name
60                                       (when (boundp 'bytecomp-filename) bytecomp-filename)
61                                       buffer-file-name)))
62
63 (require 'nxhtml-base)
64 (eval-and-compile (when (fboundp 'nxml-mode)
65                      (load (expand-file-name "etc/schema/schema-path-patch"
66                                              nxhtml-install-dir))))
67
68 ;; (defun nxhtml-custom-load-and-get-value (symbol)
69 ;;   (custom-load-symbol symbol)
70 ;;   (symbol-value symbol))
71
72 (defun nxhtml-list-loaded-features (use-message)
73   (interactive (list t))
74   (let ((buf (when use-message ;(called-interactively-p)
75                (get-buffer-create "*nXhtml loaded features*"))))
76     (if buf
77         (with-current-buffer buf (erase-buffer))
78       (message "")
79       (message "=== Loaded at nxhtml/autostart.el end:"))
80     (dolist (feature '(
81                        as-external
82                        html-chklnk
83                        html-imenu
84                        html-move
85                        html-pagetoc
86                        html-quote
87                        html-site
88                        html-toc
89                        html-upl
90                        html-wtoc
91                        inlimg
92                        mumamo
93                        nxhtml-bug
94                        nxhtml-menu
95                        nxhtml-mode
96                        nxhtml-mumamo
97                        nxhtml-strval
98                        nxhtml
99                        nxhtml-js
100                        nxml-where
101                        outline-magic
102                        rngalt
103                        tidy-xhtml
104                        xhtml-help
105                        ))
106       (when (featurep feature)
107         (if buf
108             (with-current-buffer buf
109               (insert (format "(feature '%s)=%s\n" feature (featurep feature))))
110           (message "(feature '%s)=%s" feature (featurep feature)))))
111     (if buf
112         (display-buffer buf)
113       (message ""))))
114
115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
116 ;;; Code that will run on loading this file
117
118 (if (< emacs-major-version 23)
119     (unless (featurep 'autostart22)
120       (load (expand-file-name "autostart22" nxhtml-install-dir)))
121   ;; Check that the nxml-mode included with Emacs is used. There
122   ;; has been some problems on Debian with this.
123   (let ((nxml-mode-file (locate-library "nxml-mode"))
124         (help-file      (locate-library "help")))
125     (unless (string= (expand-file-name ".." help-file)
126                      (expand-file-name "../.." nxml-mode-file))
127       (error "Wrong nxml-mode=%s used, please use the one that comes with Emacs" nxml-mode-file))))
128
129 (let* ((util-dir (file-name-as-directory (expand-file-name "util" nxhtml-install-dir)))
130        (related-dir (file-name-as-directory (expand-file-name "related" nxhtml-install-dir)))
131        (nxhtml-dir (file-name-as-directory (expand-file-name "nxhtml" nxhtml-install-dir)))
132        ;;(company-dir (file-name-as-directory (expand-file-name "util/nxhtml-company-mode" nxhtml-install-dir)))
133        (tests-dir (file-name-as-directory (expand-file-name "tests" nxhtml-install-dir))))
134   (add-to-list 'load-path nxhtml-dir)
135   (add-to-list 'load-path related-dir)
136   (add-to-list 'load-path util-dir)
137   (add-to-list 'load-path nxhtml-install-dir)
138   ;;(add-to-list 'load-path company-dir)
139   (add-to-list 'load-path tests-dir)
140
141   (nxhtml-autostart-trace "... nXhtml loading %.1f seconds elapsed ..." (- (float-time) nxhtml-load-time-start))
142
143   ;; Autoloading etc
144   ;; (unless (featurep 'web-vcs)
145   ;;   (load (expand-file-name "web-vcs" nxhtml-install-dir) (not nxhtml-autoload-web)))
146
147   ;; (when (catch 'miss
148   ;;         (dolist (file nxhtml-basic-files)
149   ;;           (let ((dl-file (expand-file-name file nxhtml-install-dir)))
150   ;;             (unless (file-exists-p dl-file)
151   ;;               (throw 'miss t))))
152   ;;         nil)
153   ;;   (nxhtml-setup-auto-download nxhtml-install-dir))
154
155   (unless (featurep 'web-autoload)
156     (load (expand-file-name "web-autoload" nxhtml-install-dir) (not nxhtml-autoload-web)))
157
158   (when nxhtml-autoload-web
159     (ad-activate 'require t))
160
161   ;; Fix-me: Why must as-external be loaded? Why doesn't it work in batch?
162   ;;(unless noninteractive (require 'as-external))
163
164   (unless (featurep 'nxhtml-loaddefs)
165     (load (expand-file-name "nxhtml-loaddefs" nxhtml-install-dir) nxhtml-autoload-web))
166   (nxhtml-autostart-trace "... nXhtml loading %.1f seconds elapsed ..." (- (float-time) nxhtml-load-time-start))
167
168   ;; Turn on `nxhtml-menu-mode' unconditionally
169   (nxhtml-autostart-trace "Turn on `nxhtml-menu-mode' unconditionally")
170   (nxhtml-menu-mode 1)
171   (nxhtml-autostart-trace "... nXhtml loading %.1f seconds elapsed ..." (- (float-time) nxhtml-load-time-start))
172
173   ;; Patch the rnc include paths
174   (when (fboundp 'rncpp-patch-xhtml-loader) (rncpp-patch-xhtml-loader))
175   (nxhtml-autostart-trace "... nXhtml loading %.1f seconds elapsed ..." (- (float-time) nxhtml-load-time-start))
176
177   ;; Load nXhtml
178   (unless (featurep 'nxhtml-autoload)
179     (load (expand-file-name "nxhtml/nxhtml-autoload" nxhtml-install-dir))))
180 (nxhtml-autostart-trace "... nXhtml loading %.1f seconds elapsed ..." (- (float-time) nxhtml-load-time-start))
181
182
183 (unless (featurep 'nxhtml-autostart)
184   ;; Provide the feature here to avoid loading looping on error.
185   (provide 'nxhtml-autostart)
186
187   ;; Tell what have been loaded of nXhtml:
188   (when nxhtml-autostart-trace (nxhtml-list-loaded-features nil))
189
190   ;; How long time did it all take?
191   (message "Nxml/Nxhtml Autostart.el loaded in %.1f seconds" (- (float-time) nxhtml-load-time-start)))
192
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
194 ;;; autostart.el ends here