aboutsummaryrefslogtreecommitdiffhomepage
path: root/generic/pg-xhtml.el
blob: cdd84f8f0ae7ab57d139d0b72b80f7fa690f56de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;; pg-xhtml.el	 XHTML goal display for Proof General
;;
;; Copyright (C) 2002 LFCS Edinburgh. 
;; Author:     David Aspinall <David.Aspinall@ed.ac.uk>
;; License:    GPL (GNU GENERAL PUBLIC LICENSE)
;;
;; $Id$
;;
;; NB: THIS FILE NOT YET USED: once required by PG,
;; must be added to main dist by editing Makefile.devel

(require 'pg-xml)

;;
;; Names for temporary files
;;
(defvar pg-xhtml-dir nil
  "Default value for XHTML directory.")

(defun pg-xhtml-dir ()
  "Temporary directory for storing XHTML files."
  (or pg-xhtml-dir
      (setq pg-xhtml-dir
	    (concat (if proof-running-on-win32
			"c:\\windows\\temp\\" ;; temp dir from env?
		      (or (concat (getenv "TMP") "/") "/tmp/"))
		    "pg"
		    (getenv "USER")
		    (int-to-string (emacs-pid))
		    (char-to-string directory-sep-char)))))

(defvar pg-xhtml-file-count 0
  "Counter for generating XHTML files.")

(defun pg-xhtml-next-file ()
  "Return new file name for XHTML storage."
  (concat 
   (pg-xhtml-dir)
   (int-to-string  (incf pg-xhtml-file-count))
   (if proof-running-on-win32 ".htm" ".html")))


;;
;; Writing an XHMTL file
;;

(defvar pg-xhtml-header 
  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN
http://www.w3.org/TR/xhtml11/DTD/xhtml11-strict.dtd\">\n
<!-- This file was automatically generated by Proof General -->\n\n"
  "Header for XHTML files.")

(defmacro pg-xhtml-write-tempfile (&rest body)
  "Write a new temporary XHTML file, returning its location.
BODY should contain a sequence of pg-xml writing commands."
  (let ((dir (pg-xhtml-dir))
	(file (pg-xhtml-next-file)))
    ;; 
    (or (eq (car-safe (file-attributes dir)) 't)
	(if (not (file-attributes dir))
	    (make-directory (pg-xhtml-dir) t)
	  (error "pg-xhtml-write-tempfile: cannot open temp dir " 
		 (pg-xhtml-dir))))
    `(with-temp-file ,file
      (pg-xml-begin-write t)
      (pg-xml-add-text pg-xhtml-header)
      ,@body
      (insert (pg-xml-doc))
      ,file)))

(defun pg-xhtml-cleanup-tempdir ()
  "Cleanup temporary directory used for XHTML files."
  (delete-directory (pg-xhtml-dir)))
    
(defvar pg-mozilla-prog-name 
  "/usr/bin/mozilla"
  "Command name of browser to use with XHTML display.")

(defun pg-xhtml-display-file-mozilla (file)
  "Display FILENAME in netscape/mozilla."
  (shell-command (concat pg-mozilla-prog-name
			 " -remote \"openURL(" file ")\"")))

(defalias 'pg-xhtml-display-file 'pg-xhtml-display-file-mozilla)

; Test doc
;(pg-xhtml-display-file-mozilla
;(pg-xhtml-write-tempfile
;  (pg-xml-openelt 'root)
;  (pg-xml-openelt 'a '((class . "1B")))
;  (pg-xml-writetext "text a")
;  (pg-xml-closeelt)
;  (pg-xml-closeelt)))


(provide 'pg-xhtml)
;; End of pg-xhtml