;;; nxhtml-loader.el --- Loading of nxhtml/nxml
;;
;; Author: Lennart Borgman
;; Maintainer:
;; Created: Fri Dec 15 16:56:15 2006
;; Version:
;; Last-Updated: 2008-01-20T01:20:56+0100 Sun
;; Keywords:
;; Compatibility:
;;
;; Features that might be required by this library:
;;
;;   None
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(defconst nxhtml-loader-dir (file-name-directory
                             (if load-file-name load-file-name buffer-file-name)))

(defun nxhtml-load-nxhtml-from-emacsw32()
  "Load nxml-mode and nxhtml-mode.
Those are both loaded from the EmacsW32 installation which comes
with those."
  (unless (fboundp 'nxhtml-mode)
    (let* ((nxml-dir (file-name-as-directory
                      (expand-file-name "../nxml" nxhtml-loader-dir)))
           (auto (expand-file-name "autostart" nxml-dir)))
      (if (not (file-directory-p nxml-dir))
          (lwarn '(nxml) :error
                 "%s is not a directory, could not load nxhtml/nxml." nxml-dir)
        (load auto)))))

(defvar nxhtml-load-set nil)
(defcustom nxhtml-load nil
  "Set this to use nxhtml and nxml.
Setting this variable to a non-nil value through customize will
will tell Emacs to use xml-mode for XML and nxhtml-mode
for (X)HTML files.

This is done by setting `auto-mode-alist' and
`magic-mode-alist'.

When setting this to nil the list above is reset to default
values if they were changed before by setting this variable."
;; Fix-me: Something better to do when resetting?
  :type 'boolean
  :set (lambda (symbol value)
         (set-default symbol value)
         (if value
             (progn
               (nxhtml-load-nxhtml-from-emacsw32)
               (setq nxhtml-load-set t))
           (when nxhtml-load-set
             (fmode-replace-default-mode 'nxhtml-mode 'html-mode)
             (fmode-replace-default-mode 'nxml-mode 'xml-mode))))
  :group 'xml
  :group 'nxhtml
  :group 'languages
  )

(provide 'nxhtml-loader)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; nxhtml-loader.el ends here
