Function: rng-validate-mode

rng-validate-mode is an autoloaded, interactive and byte-compiled function defined in rng-valid.el.gz.

Signature

(rng-validate-mode &optional ARG)

Documentation

Minor mode performing continual validation against a RELAX NG schema.

Checks whether the buffer is a well-formed XML 1.0 document, conforming to the XML Namespaces Recommendation and valid against a RELAX NG schema. The mode-line indicates whether it is or not. Any parts of the buffer that cause it not to be are considered errors and are highlighted with face rng-error. A description of each error is available as a tooltip. M-x rng-next-error (rng-next-error) goes to the next error after point. Clicking mouse-1 on the word Invalid in the mode-line goes to the first error in the buffer. If the buffer changes, then it will be automatically rechecked when Emacs becomes idle; the rechecking will be paused whenever there is input pending.

By default, uses a vacuous schema that allows any well-formed XML document. A schema can be specified explicitly using M-x rng-set-schema-file-and-validate (rng-set-schema-file-and-validate), or implicitly based on the buffer's file name or on the root element name. In each case the schema must be a RELAX NG schema using the compact schema (such schemas conventionally have a suffix of .rnc). The variable rng-schema-locating-files specifies files containing rules to use for finding the schema.

This is a minor mode. If called interactively, toggle the Rng-Validate mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable rng-validate-mode(var)/rng-validate-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/nxml/rng-valid.el.gz
;;;###autoload
(define-minor-mode rng-validate-mode
  "Minor mode performing continual validation against a RELAX NG schema.

Checks whether the buffer is a well-formed XML 1.0 document,
conforming to the XML Namespaces Recommendation and valid against a
RELAX NG schema.  The mode-line indicates whether it is or not.  Any
parts of the buffer that cause it not to be are considered errors and
are highlighted with face `rng-error'.  A description of each error is
available as a tooltip.  \\[rng-next-error] goes to the next error
after point.  Clicking mouse-1 on the word `Invalid' in the mode-line
goes to the first error in the buffer.  If the buffer changes, then it
will be automatically rechecked when Emacs becomes idle; the
rechecking will be paused whenever there is input pending.

By default, uses a vacuous schema that allows any well-formed XML
document.  A schema can be specified explicitly using
\\[rng-set-schema-file-and-validate], or implicitly based on the buffer's
file name or on the root element name.  In each case the schema must
be a RELAX NG schema using the compact schema \(such schemas
conventionally have a suffix of `.rnc').  The variable
`rng-schema-locating-files' specifies files containing rules
to use for finding the schema."
  :global nil
  (save-restriction
    (widen)
    (with-silent-modifications
      (rng-clear-cached-state (point-min) (point-max)))
    ;; 1+ to clear empty overlays at (point-max)
    (rng-clear-overlays (point-min) (1+ (point-max)))
    (setq rng-validate-up-to-date-end (point-min)))
  (rng-clear-conditional-region)
  (setq rng-error-count 0)
  ;; do this here to avoid infinite loop if we set the schema
  (remove-hook 'rng-schema-change-hook #'rng-validate-clear t)
  (cond (rng-validate-mode
	 (unwind-protect
	     (save-excursion
	       ;; An error can change the current buffer
	       (when (or (not rng-current-schema)
			 (eq rng-current-schema rng-any-element))
		 (rng-auto-set-schema t)))
	   (unless rng-current-schema (rng-set-schema-file-1 nil))
	   (add-hook 'rng-schema-change-hook #'rng-validate-clear nil t)
	   (add-hook 'after-change-functions #'rng-after-change-function nil t)
	   (add-hook 'kill-buffer-hook #'rng-kill-timers nil t)
	   (add-hook 'echo-area-clear-hook #'rng-echo-area-clear-function nil t)
	   (add-hook 'post-command-hook #'rng-maybe-echo-error-at-point nil t)
	   (rng-match-init-buffer)
	   (rng-activate-timers)
	   ;; Start validating right away if the buffer is visible.
	   ;; If it's not visible, don't do this, because the user
	   ;; won't get any progress indication. When the user finds
	   ;; a new file, then the buffer won't be visible
	   ;; when this is invoked.
	   (when (get-buffer-window (current-buffer) 'visible)
	     (rng-validate-while-idle (current-buffer)))))
	(t
	 (rng-cancel-timers)
	 (remove-hook 'kill-buffer-hook #'rng-cancel-timers t)
	 (remove-hook 'post-command-hook #'rng-maybe-echo-error-at-point t)
	 (remove-hook 'echo-area-clear-hook #'rng-echo-area-clear-function t)
	 (remove-hook 'after-change-functions #'rng-after-change-function t))))