summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/util/nxml-mode-os-additions.el
blob: 0765acfd19417d7c7100ad52cd974e0c2bbb497e (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
96
97
98
99
;;; nxml-mode-os-additions.el --- additional functions for nxml-mode

;; Copyright (C) 2004 by Oliver Steele

;; Author: Oliver Steele <steele@osteele.com>
;; Version: 1.0 (2004-08-08)
;; Homepage: http://osteele.com/sources/nxml-mode-os-additions.el
;; Keywords: XML

;; 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 of
;; the License, 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; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
;; MA 02111-1307 USA

;;; Description:

;; nxml-mode-os-additions defines additional functions for using
;; James Clark's nxml-mode:
;; - reload the current buffer's schema
;; - edit the current buffer's schema

;;; Installation:
;;
;; To use nxml-mode-os-additions.el, put it in your load-path and add
;; the following to your .emacs:
;;
;;   (load-library "nxml-mode-os-additions")

;; Configuration:
;;
;; To make it easier to use, assign the commands to some keys.
;; Once nxml-mode has been loaded, you can define keys on nxml-mode-map.
;; The function rng-mode-os-additions-set-key-bindings illustrates
;; this.
;;
;; Alternatively, you can place the following in your .emacs:
;;  (add-hook 'nxml-mode-hook 'rng-mode-os-additions-set-key-bindings)

;;; ChangeLog:
;;
;; 2004-08-08 (version 1.0):
;;   * Initial public release

;; Added require rng-valid (Lennart Borgman)

;;; Code:

(require 'nxml-mode)
(eval-and-compile (require 'rng-valid))

(defun rng-mode-os-additions-set-key-bindings ()
  (define-key nxml-mode-map "\C-c\C-s\C-r" 'rng-reload-schema-file)
  ; move the rng-set-schema-file-and-validate to another key binding
  ;(define-key nxml-mode-map "\C-c\C-s\C-s" 'rng-set-schema-file-and-validate)
  (define-key nxml-mode-map "\C-c\C-sf" 'rng-find-schema-file)
  )

(defun rng-reload-schema-file ()
  "Reloads the current schema file."
  (interactive)
  (let ((schema-filename rng-current-schema-file-name))
    (when schema-filename
      (setq rng-current-schema (rng-load-schema schema-filename))
      (run-hooks 'rng-schema-change-hook)
      (message "Reloaded schema %s" schema-filename))
    (unless schema-filename
      (rng-set-schema-and-validate))))

;; Helper function for rng-find-schema-file*
(defun rng-apply-find-schema-file (fn)
  (let ((schema-filename rng-current-schema-file-name))
    (unless schema-filename
      (error "This file is not associated with a schema file."))
    (funcall fn schema-filename)))

(defun rng-find-schema-file ()
  "Edit the current schema file."
  (interactive)
  (rng-apply-find-schema-file 'find-file))

(defun rng-find-schema-file-other-frame ()
  "Edit the current schema in another frame."
  (interactive)
  (rng-apply-find-schema-file 'find-file-other-frame))

(defun rng-find-schema-file-other-window ()
  "Edit the current schema in another window."
  (interactive)
  (rng-apply-find-schema-file 'find-file-other-window))