summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/etc/schema/schema-path-patch.el
blob: a6d59fc432cafa9164b01d2ccd47f9c5a28fb454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;;; schema-path-patch.el --- Patch schema paths
;;
;; Author: Lennart Borgman (lennart O borgman A gmail O com)
;; Created: 2008-08-08T20:21:31+0200 Fri
;; Version: 0.2
;; Last-Updated: 2008-08-19T00:21:25+0200 Mon
;; URL:
;; Keywords:
;; Compatibility:
;;
;; Features that might be required by this library:
;;
;;   Cannot open load file: schema-path-patch.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Schemas here may include parts from nxml and need to know the path.
;; This file can be used to patch the paths.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; 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., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(defvar rncpp-this-dir
  (file-name-as-directory
   (file-name-directory
    (if load-file-name load-file-name buffer-file-name))))

(defun rncpp-get-nxml-schema-dir ()
  ;; First look for nxml-mode included with Emacs
  (let ((schema-dir (file-name-as-directory
                     (expand-file-name "schema" data-directory))))
    (unless (file-directory-p schema-dir)
      ;; This is an old nxml-mode, look for its schemas dir.
      (let ((nxml-mode-dir (file-name-as-directory
                            (file-name-directory (locate-library "nxml-mode")))))
        (setq schema-dir (file-name-as-directory
                          (expand-file-name "schema" nxml-mode-dir)))))
    (unless (file-directory-p schema-dir)
      (error "Can't find schema-dir=%s" schema-dir))
    schema-dir))

;; Use xhtml-loader.rnc (an idea from Bryan Waite):
(defun rncpp-patch-xhtml-loader ()
  "Patch xhtml-loader.rnc so genshi and mjt rnc files works."
  ;;(interactive)
  (let* ((default-directory rncpp-this-dir)
         (loader-path (expand-file-name "xhtml-loader.rnc"))
         (loader-buf (find-buffer-visiting loader-path))
         (schema-dir (rncpp-get-nxml-schema-dir))
         (schema-relative-dir (file-relative-name schema-dir))
         (loader-string (concat "include \""
                                schema-relative-dir
                                "xhtml.rnc\"\n")))
    (when loader-buf (kill-buffer loader-buf))
    (setq loader-buf (find-file-noselect loader-path))
    (with-current-buffer loader-buf
      (unless (file-exists-p loader-path)
        (insert loader-string))
      ;; Test if correct
      (if (string= (buffer-substring-no-properties (point-min) (point-max))
                       loader-string)
          (message "xhtml-loader.rnc was ok")
        (message "Patching xhtml-loader.rnc")
        (delete-region (point-min) (point-max))
        (insert loader-string))
      (basic-save-buffer)
      (kill-buffer (current-buffer)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; schema-path-patch.el ends here