
(message "loaded d-htmlize target=%s" target)

(defun message (format-string &rest args) (interactive))

;;(checkpoint 123)
;;(checkpoint "123")
;;(checkpoint (format "abc=%s" (point)))
(defun checkpoint (x) (message "*** checkpoint %s" x))

(if (not (string-match "/dlisp/" (car load-path)))
    (if (file-exists-p "/media/www/C1TB/home/dlisp/imported-stuff/htmlize.el")
        (progn
          (setq load-path (cons "/media/www/C1TB/home/dlisp/" load-path)))
      (setq load-path (cons "~www/dlisp" load-path))
      ))

(if (file-exists-p "~/dlisp/emergency-bindings.el")
    (load-file "~/dlisp/emergency-bindings.el"))

(d-emergency-set-load-path)

(load-file (concat (car load-path) "/imported-stuff/htmlize.el"))

(setq prefs-home-emacs-p t)
;;(setq prefs-lcd-emacs-p nil)
;;(setq prefs-advanced-user-p nil)
;;(setq prefs-windows-bindings-p nil)
(setq prefs-font-p t)
(setq prefs-font-libd-p t)
(setq prefs-font-xtra-p t)
;;(message "%s" 123)

;;(load-file (concat (car load-path) "/emergency-bindings.el"))
(checkpoint 1)
(load-file (concat (car load-path) "/diagnose.el"))
(checkpoint 2)
(load-file (concat (car load-path) "/d-make-faces.el"))
(checkpoint 3)
(load-file (concat (car load-path) "/d-flock.el"))
(checkpoint 3.5)
(load-file (concat (car load-path) "/d-flock-private.el"))
(checkpoint 4)
(load-file (concat (car load-path) "/jtw-mode.el"))
(checkpoint 5)
(load-file (concat (car load-path) "/d-auto-mode-alist.el"))
(checkpoint 6)
(load-file (concat (car load-path) "/d-php-mode.el"))
(checkpoint 7)

(defun htmlize--splat (old-text new-text)
  (save-match-data
    (save-excursion
      (goto-char (point-min))
      (while (search-forward old-text nil t)
        (replace-match new-text nil nil)))))

;; (setq filename "a.cc")
(defun d-htmlize (filename)
  (interactive "fEnter filename: ")
  ;;(find-file filename)
  ;;(jtw-mode)
  ;;(message "*** major-mode=%s" major-mode)
  (checkpoint 8)
  (message "*** before concat filename=%s" filename)
  (setq filename (concat (file-name-directory default-directory) filename))
  (message "*** after concat filename=%s" filename)
  ;;(find-file filename)
  (checkpoint 9)
  (message "*** before saving")
  ;;(htmlize-buffer (find-file filename))
  (htmlize-file filename)
  (save-some-buffers 'NO-QUESTIONS)
  (kill-buffer)
  (message "*** after saving")
  (checkpoint 10)
  (checkpoint "dh-6")
  ;;(debug)
  (setq filename-2 (concat filename ".html"))
  (checkpoint 11)
  (find-file filename-2)
  (checkpoint "dh-6")
  (checkpoint 12)
  (read-only-mode -1)
  (message "filename-2=%s" filename-2)
  (checkpoint 11)
  (progn
    (goto-char (point-min))
    (re-search-forward "<pre>" nil t)
    (beginning-of-line)
    (delete-region (point-min) (point)))
  (checkpoint "dh-7")
  (progn
    (goto-char (point-min))
    (re-search-forward "</pre>" nil t)
    (beginning-of-line)
    (forward-line 1)
    (delete-region (point) (point-max))
    )
  (save-buffer)
  (kill-buffer nil)
  (checkpoint "dh-8")
  (checkpoint 12)
  (d-quote
   (goto-char (point-min))
   (insert "<html>\n")
   (insert "<head>\n")
   (insert "   <link rel=\"stylesheet\" href=\"stylesheet10.css\" type=\"text/css\">\n")
   (insert "</head>\n")
   (insert "<body>\n")
   (goto-char (point-max))
   (insert "</body></html>\n"))
  ;;
  ;; NOTE: removal of extra fontification
  ;;
  ;; WARNING: not robust in the case of NOTE: inside strings
  ;;
  ;;(htmlize--splat "class=\"d-face-special-reference\"" "class=\"flcf\"")
  ;;(htmlize--splat "class=\"fgXwhite\"" "class=\"flcf\"")
  (checkpoint 13)
  (d-quote
   (save-excursion
     (find-file filename-2)
     (message "*** file %s has the following line count %s"
              filename-2
              (count-lines-region (point-min) (point-max)))
     (message "*** BEGINNING OF PRINTOUT")
     (goto-char (point-min))
     (setq count 0)
     (while (not (eobp))
       (message "* LINE %d: %s" count (d-current-line-as-string))
       (forward-line 1)
       (beginning-of-line)
       (incf count))
     (message "*** END OF PRINTOUT")))
  )

;;(setq target "a.cc")
;;(setq target "a.jtw")
;; (setq target "/d/home/hairy-lemon/src/davin")
(checkpoint "dh-3")

;; (setq target "c:/a/bc.txt")
(defun canonicalise (target)
  (progn
    (if (not (string-match "^\\([a-z]\\):/" target))
        (progn
          ;;(message "foo")
          target)
      (setq drive (substring target (match-beginning 1) (match-end 1)))
      (setq sub (substring target (match-end 0)))
      (concat drive ":/" sub))))

(checkpoint "dh-4")

;;(message "target=%s" target)

(message "target pre-canonicalise=%s" target)

(setq target (canonicalise target))

(message "target post-canonicalise=%s" target)

(checkpoint "dh-4b")

(message "target=%s" target)

(checkpoint "dh-pre")

(tde)

(d-htmlize target)

(checkpoint "dh-post")

(provide 'd-htmlize)
;;; d-htmlize.el ends here
