annotate lisp/psgml/psgml-api.el @ 149:538048ae2ab8 r20-3b1

Import from CVS: tag r20-3b1
author cvs
date Mon, 13 Aug 2007 09:36:16 +0200
parents 131b0175ea99
children
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 2
diff changeset
2 ;; $Id: psgml-api.el,v 1.1.1.1 1996/12/18 22:43:36 steve Exp $
0
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
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
73 (let ((main-buffer-max (point-max)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
74 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
75 (sgml-set-parse-state element 'start)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
76 (when (eobp) (sgml-pop-entity))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
77 (when (eolp) (forward-char 1))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 (sgml-parse-data main-buffer-max data-fun pi-fun entity-fun)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
79 (let ((c (sgml-tree-content element)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
80 (while c
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
81 (sgml-pop-all-entities)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
82 (funcall element-fun c)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
83 (sgml-set-parse-state c 'after)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
84 (sgml-parse-data main-buffer-max data-fun pi-fun entity-fun)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
85 (setq c (sgml-tree-next c)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
86 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (sgml-pop-all-entities))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun sgml-parse-data (sgml-goal sgml-data-function sgml-pi-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 sgml-entity-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (let ((sgml-throw-on-element-change 'el-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (catch sgml-throw-on-element-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (sgml-parser-loop nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;;; Entity management
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun sgml-push-to-string (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 "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
100 After this the current buffer will be a scratch buffer containing the text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 of the new entity with point at the first character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 Use `sgml-pop-entity' to exit from this buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (sgml-push-to-entity (sgml-make-entity "#STRING" 'text string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;;; psgml-api.el ends here