;;; editor_driver.el --- drive the Emacs editor units over fixtures -*- lexical-binding: t; -*-

;; Usage:
;;   emacs --batch -L EMACSDIR -l klammertext-mode -l klammertext-indent
;;         -l klammertext-align -l editor_driver.el MODE INFILE OUTFILE ...
;;
;; MODE is "indent" or "align"; each triple applies that tool to INFILE and
;; writes the result to OUTFILE.  Called by editor_test.sh.

(let ((args command-line-args-left))
  (setq command-line-args-left nil)     ; keep batch Emacs from visiting them
  (while args
    (let ((mode (pop args))
          (in (pop args))
          (out (pop args)))
      (with-temp-buffer
        (insert-file-contents in)
        (klammertext-mode)
        (cond
         ((string= mode "indent")
          (indent-region (point-min) (point-max)))
         ((string= mode "align")
          (goto-char (point-min))
          (when (search-forward "|" nil t)
            (goto-char (1- (point))))
          (klammertext-align-table))
         (t (error "editor_driver.el: unknown mode %s" mode)))
        (write-region (point-min) (point-max) out nil 'silent)))))

;;; editor_driver.el ends here
