1 ;;; schema-path-patch.el --- Patch schema paths
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2008-08-08T20:21:31+0200 Fri
6 ;; Last-Updated: 2008-08-19T00:21:25+0200 Mon
11 ;; Features that might be required by this library:
13 ;; Cannot open load file: schema-path-patch.
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; Schemas here may include parts from nxml and need to know the path.
20 ;; This file can be used to patch the paths.
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; This program is free software; you can redistribute it and/or
30 ;; modify it under the terms of the GNU General Public License as
31 ;; published by the Free Software Foundation; either version 2, or
32 ;; (at your option) any later version.
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 ;; General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING. If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 (defvar rncpp-this-dir
49 (file-name-as-directory
51 (if load-file-name load-file-name buffer-file-name))))
53 (defun rncpp-get-nxml-schema-dir ()
54 ;; First look for nxml-mode included with Emacs
55 (let ((schema-dir (file-name-as-directory
56 (expand-file-name "schema" data-directory))))
57 (unless (file-directory-p schema-dir)
58 ;; This is an old nxml-mode, look for its schemas dir.
59 (let ((nxml-mode-dir (file-name-as-directory
60 (file-name-directory (locate-library "nxml-mode")))))
61 (setq schema-dir (file-name-as-directory
62 (expand-file-name "schema" nxml-mode-dir)))))
63 (unless (file-directory-p schema-dir)
64 (error "Can't find schema-dir=%s" schema-dir))
67 ;; Use xhtml-loader.rnc (an idea from Bryan Waite):
68 (defun rncpp-patch-xhtml-loader ()
69 "Patch xhtml-loader.rnc so genshi and mjt rnc files works."
71 (let* ((default-directory rncpp-this-dir)
72 (loader-path (expand-file-name "xhtml-loader.rnc"))
73 (loader-buf (find-buffer-visiting loader-path))
74 (schema-dir (rncpp-get-nxml-schema-dir))
75 (schema-relative-dir (file-relative-name schema-dir))
76 (loader-string (concat "include \""
79 (when loader-buf (kill-buffer loader-buf))
80 (setq loader-buf (find-file-noselect loader-path))
81 (with-current-buffer loader-buf
82 (unless (file-exists-p loader-path)
83 (insert loader-string))
85 (if (string= (buffer-substring-no-properties (point-min) (point-max))
87 (message "xhtml-loader.rnc was ok")
88 (message "Patching xhtml-loader.rnc")
89 (delete-region (point-min) (point-max))
90 (insert loader-string))
92 (kill-buffer (current-buffer)))))
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
95 ;;; schema-path-patch.el ends here