[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 524af9b: * lisp/nxml/rng-valid.el: Use define-minor

From: Stefan Monnier
Subject: [Emacs-diffs] master 524af9b: * lisp/nxml/rng-valid.el: Use define-minor-mode
Date: Sun, 29 Sep 2019 18:16:01 -0400 (EDT)

branch: master
commit 524af9b8334387a17ed890c96355e4adb3f12122
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * lisp/nxml/rng-valid.el: Use define-minor-mode
    Remove redundant `:group`s.
    (rng-validate-mode): Use define-minor-mode.
    (rng-validate-clear): Let-bind rng-current-schema instead of passing
    a `no-change-schema` argument.
 lisp/nxml/rng-valid.el | 72 ++++++++++++++++++++++----------------------------
 1 file changed, 31 insertions(+), 41 deletions(-)

diff --git a/lisp/nxml/rng-valid.el b/lisp/nxml/rng-valid.el
index 6c1ca51..8cffbc3 100644
--- a/lisp/nxml/rng-valid.el
+++ b/lisp/nxml/rng-valid.el
@@ -106,34 +106,29 @@
   :group 'languages)
 (defface rng-error '((t (:inherit font-lock-warning-face)))
-  "Face for highlighting XML errors."
-  :group 'relax-ng)
+  "Face for highlighting XML errors.")
 (defcustom rng-state-cache-distance 2000
   "Distance in characters between each parsing and validation state cache."
-  :type 'integer
-  :group 'relax-ng)
+  :type 'integer)
 (defcustom rng-validate-chunk-size 8000
   "Number of characters in a RELAX NG validation chunk.
 A validation chunk will be the smallest chunk that is at least this
 size and ends with a tag.  After validating a chunk, validation will
 continue only if Emacs is still idle."
-  :type 'integer
-  :group 'relax-ng)
+  :type 'integer)
 (defcustom rng-validate-delay 1.5
   "Time in seconds that Emacs must be idle before starting a full validation.
 A full validation continues until either validation is up to date
 or Emacs is no longer idle."
-  :type 'number
-  :group 'relax-ng)
+  :type 'number)
 (defcustom rng-validate-quick-delay 0.3
   "Time in seconds that Emacs must be idle before starting a quick validation.
 A quick validation validates at most one chunk."
-  :type 'number
-  :group 'relax-ng)
+  :type 'number)
 ;; Global variables
@@ -208,14 +203,11 @@ See the variable `rng-conditional-up-to-date-start'.")
   "Non-nil means we are currently parsing just to compute the state.
 Should be dynamically bound.")
-(defvar rng-validate-mode nil)
-(make-variable-buffer-local 'rng-validate-mode)
 (defvar rng-dtd nil)
 (make-variable-buffer-local 'rng-dtd)
-(defun rng-validate-mode (&optional arg no-change-schema)
+(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,
@@ -237,11 +229,7 @@ be a RELAX NG schema using the compact schema \(such 
 conventionally have a suffix of `.rnc').  The variable
 `rng-schema-locating-files' specifies files containing rules
 to use for finding the schema."
-  (interactive "P")
-  (setq rng-validate-mode
-       (if (null arg)
-           (not rng-validate-mode)
-         (> (prefix-numeric-value arg) 0)))
+  :global nil
@@ -252,21 +240,20 @@ to use for finding the schema."
   (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)
+  (remove-hook 'rng-schema-change-hook #'rng-validate-clear t)
   (cond (rng-validate-mode
               ;; An error can change the current buffer
               (when (or (not rng-current-schema)
-                        (and (eq rng-current-schema rng-any-element)
-                             (not no-change-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)
+          (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)
           ;; Start validating right away if the buffer is visible.
@@ -278,11 +265,10 @@ to use for finding the schema."
             (rng-validate-while-idle (current-buffer)))))
-        (force-mode-line-update)
-        (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))))
+        (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))))
 (defun rng-set-schema-file-and-validate (filename)
   "Sets the schema and turns on `rng-validate-mode' if not already on.
@@ -389,16 +375,20 @@ The schema is set like `rng-auto-set-schema'."
       (setq rng-validate-timer
            (run-with-idle-timer rng-validate-delay
-                                'rng-validate-while-idle
+                                #'rng-validate-while-idle
       (setq rng-validate-quick-timer
            (run-with-idle-timer rng-validate-quick-delay
-                                'rng-validate-quick-while-idle
+                                #'rng-validate-quick-while-idle
 (defun rng-validate-clear ()
-  (rng-validate-mode 1 t))
+  (if (eq rng-current-schema rng-any-element)
+      ;; Prevent rng-validate-mode from trying to find another schema.
+      (let ((rng-current-schema (copy-sequence rng-current-schema)))
+        (rng-validate-mode))
+    (rng-validate-mode)))
 ;; These two variables are dynamically bound and used
 ;; to pass information between rng-validate-while-idle
@@ -432,7 +422,7 @@ The schema is set like `rng-auto-set-schema'."
       (if rng-validate-mode
           (if (let ((rng-validate-display-point (point))
                     (rng-validate-display-modified-p (buffer-modified-p)))
-                (rng-do-some-validation 'rng-validate-while-idle-continue-p))
+                (rng-do-some-validation #'rng-validate-while-idle-continue-p))
         ;; Must have done kill-all-local-variables.
@@ -1109,7 +1099,7 @@ as empty-element."
 (defun rng-mark-start-tag-close (&rest args)
   (when (not (eq xmltok-type 'partial-start-tag))
-    (rng-mark-invalid (apply 'format args)
+    (rng-mark-invalid (apply #'format args)
                      (- (point)
                         (if (eq xmltok-type 'empty-element)
@@ -1285,19 +1275,19 @@ as empty-element."
          ((memq nil contents) nil)
          ((not (cdr contents))
           (rng-segment-string (car contents)))
-         (t (apply 'concat
-                   (nreverse (mapcar 'rng-segment-string
+         (t (apply #'concat
+                   (nreverse (mapcar #'rng-segment-string
 (defun rng-segment-string (segment)
   (or (car segment)
-      (apply 'buffer-substring-no-properties
+      (apply #'buffer-substring-no-properties
             (cdr segment))))
 (defun rng-segment-blank-p (segment)
   (if (car segment)
       (rng-blank-p (car segment))
-    (apply 'rng-region-blank-p
+    (apply #'rng-region-blank-p
           (cdr segment))))
 (defun rng-contents-region ()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]