Function: xsdre-gen-categories

xsdre-gen-categories is an interactive and byte-compiled function defined in xsd-regexp.el.gz.

Signature

(xsdre-gen-categories FILE)

Documentation

Use a UnicodeData file to generate code to initialize Unicode categories.

Code is inserted into the current buffer.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/nxml/xsd-regexp.el.gz
(defun xsdre-gen-categories (file)
  "Use a UnicodeData file to generate code to initialize Unicode categories.
Code is inserted into the current buffer."
  (interactive "fUnicodeData file: ")
  (with-current-buffer (find-file-noselect file)
    (goto-char (point-min))
    (mapc (lambda (x) (put x 'xsdre-ranges nil)) xsdre-gen-categories)
    (while (re-search-forward "^\\([[:xdigit:]]*\\);[^;]*;\\([A-Z][a-z]\\);"
			      nil
			      t)
      (let* ((sym (intern (match-string-no-properties 2)))
	     (code (string-to-number (match-string-no-properties 1)
				     16))
	     (ranges (get sym 'xsdre-ranges))
	     (last-range (car ranges))
	     (forced-range (string= (buffer-substring-no-properties
				     (- (match-beginning 2) 6)
				     (1- (match-beginning 2)))
				    "Last>")))
	(cond ((and (integerp last-range)
		    (or forced-range
			(eq code (1+ last-range))))
	       (put sym
		    'xsdre-ranges
		    (cons (cons last-range code)
			  (cdr ranges))))
	      ((and (consp last-range)
		    (or forced-range
			(eq code (1+ (cdr last-range)))))
	       (put sym
		    'xsdre-ranges
		    (cons (cons (car last-range) code)
			  (cdr ranges))))
	      (t
	       (put sym 'xsdre-ranges (cons code ranges))))))
    (mapc (lambda (x)
            (put x
                 'xsdre-ranges
                 (nreverse (get x 'xsdre-ranges)))
            nil)
          xsdre-gen-categories))
  (mapc (lambda (x)
          (let ((start (point)))
            (pp (list 'xsdre-def-primitive-category
                      (list 'quote x)
                      (list 'quote (get x 'xsdre-ranges)))
                (current-buffer))
            (save-excursion
              (goto-char start)
              (down-list 2)
              (while (condition-case nil
                         (progn
                           (forward-sexp)
                           t)
                       (error nil))
                (when (and (< 70 (current-column))
                           (not (looking-at ")")))
                  (insert "\n")
                  (lisp-indent-line))))))
        xsdre-gen-categories))