annotate lisp/psgml/psgml-api.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; psgml-api.el --- Extra API functions for PSGML
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; $Id: psgml-api.el,v 1.1.1.1 1996/12/18 03:35:18 steve Exp $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1994 Lennart Staflin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Lennart Staflin <lenst@lysator.liu.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This program is free software; you can redistribute it and/or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; modify it under the terms of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; as published by the Free Software Foundation; either version 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; of the License, or (at your option) any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Provides some extra functions for the API to PSGML.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (provide 'psgml-api)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (require 'psgml)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (require 'psgml-parse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;;; Mapping: map and modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defun sgml-map-element-modify (el-fun element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 "Apply EL-FUN to ELEMENT and the elements in its content.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 The EL-FUN may change the buffer. But if it changes the buffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 leaves the element with no start-tag some elements may be ignored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (let ((level ; level in the element tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (tick ; change counter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (buffer-modified-tick)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (while element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (funcall el-fun element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; If the function has modified the buffer, a fresh parse is needed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (when (/= tick (buffer-modified-tick))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq element (sgml-find-element-of (sgml-element-start element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq tick (buffer-modified-tick)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Map content if any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ((setq next (sgml-element-content element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (incf level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; If in a sub-tree, move to next element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (while (and (> level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (null (setq next (sgml-element-next element))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (setq element (sgml-element-parent element))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (decf level))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (setq element next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;;; Map content
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defun sgml-map-content (element element-fun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 &optional data-fun pi-fun entity-fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "Map content of ELEMENT, calling ELEMENT-FUN for every element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Also calling DATA-FUN, if non-nil, with data in content."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (sgml-pop-all-entities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (sgml-need-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (sgml-element-end element) ; Make sure all content is parsed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (sgml-set-parse-state element 'start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (when (eobp) (sgml-pop-entity))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (when (eolp) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (sgml-parse-data (point-max) data-fun pi-fun entity-fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (let ((c (sgml-tree-content element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (while c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (sgml-pop-all-entities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (funcall element-fun c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (sgml-set-parse-state c 'after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (sgml-parse-data (point-max) data-fun pi-fun entity-fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (setq c (sgml-tree-next c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (sgml-pop-all-entities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defun sgml-parse-data (sgml-goal sgml-data-function sgml-pi-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 sgml-entity-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (let ((sgml-throw-on-element-change 'el-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (catch sgml-throw-on-element-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (sgml-parser-loop nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;;; Entity management
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defun sgml-push-to-string (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "Create an entity from STRING and push it on the top of the entity stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 After this the current buffer will be a scratch buffer containing the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 of the new entity with point at the first character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 Use `sgml-pop-entity' to exit from this buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (sgml-push-to-entity (sgml-make-entity "#STRING" 'text string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; psgml-api.el ends here