annotate lisp/psgml/psgml-charent.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-charent.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Last edited: Mon Nov 28 22:18:09 1994 by lenst@lysistrate (Lennart Staflin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; $Id: psgml-charent.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
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Copyright (C) 1994 Lennart Staflin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Author: Steinar Bang, Falch Hurtigtrykk as., Oslo, 940711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Lennart Staflin <lenst@lysator.liu.se>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; This program is free software; you can redistribute it and/or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; modify it under the terms of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; as published by the Free Software Foundation; either version 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; of the License, or (at your option) any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Functions to convert character entities into displayable characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; and displayable characters back into character entities.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (provide 'psgml-charent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;;; Variable declarations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defvar sgml-display-char-list-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (expand-file-name sgml-data-directory "iso88591.map")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 "*Name of file holding relations between character codes and character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 names of displayable characters")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defvar sgml-display-char-alist-cache nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;;; Function declarations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (defun sgml-display-char-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 "Return the current display character alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 Alist with entity name as key and display character as content."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (unless (file-exists-p sgml-display-char-list-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (error "No display char file: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 sgml-display-char-list-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (sgml-cache-catalog sgml-display-char-list-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 'sgml-display-char-alist-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (function sgml-read-display-char-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defun sgml-read-display-char-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (let (key disp-char alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (while (re-search-forward "^\\([0-9]+\\)[ \t]+\\(.+\\)$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (setq key (buffer-substring (match-beginning 2) (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (setq disp-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (string-to-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (buffer-substring (match-beginning 1) (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (push (cons key disp-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defun sgml-charent-to-dispchar-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "Association list to hold relations of the type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (CHARACTER-NAME . CHARACTER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 CHARACTER-NAME is a string holding a character name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 CHARACTER is a string holding a single displayable character"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (sgml-need-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (let ((display-chars (sgml-display-char-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (alist nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (sgml-map-entities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (lambda (entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (let ((char (cdr (assoc (sgml-entity-text entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 display-chars))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (when char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (push (cons (sgml-entity-name entity) char) alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (sgml-dtd-entities sgml-dtd-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun sgml-charent-to-display-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Replace character entities with their display character equivalents"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (let ((charent-to-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (sgml-charent-to-dispchar-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 charent replacement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (while (re-search-forward "&\\(\\w\\(\\w\\|\\s_\\)+\\);?" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq charent (buffer-substring (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if (setq replacement (cdr (assoc charent charent-to-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (replace-match replacement t t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun sgml-display-char-to-charent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "Replace displayable characters with their character entity equivalents"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (loop for pair in (sgml-charent-to-dispchar-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 do (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (while (search-forward (cdr pair) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (replace-match (concat "&" (car pair) ";") t t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (require 'psgml-parse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;; psgml-charent.el ends here