annotate lisp/psgml/psgml-charent.el @ 151:59463afc5666 r20-3b2

Import from CVS: tag r20-3b2
author cvs
date Mon, 13 Aug 2007 09:37:19 +0200
parents b980b6286996
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-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)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 70
diff changeset
3 ;;; $Id: psgml-charent.el,v 1.2 1997/04/24 04:00:12 steve Exp $
0
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)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
34 (require 'psgml-parse)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;;; Variable declarations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defvar sgml-display-char-list-filename
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents: 70
diff changeset
40 (expand-file-name "sgml/iso88591.map" data-directory)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 "*Name of file holding relations between character codes and character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 names of displayable characters")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvar sgml-display-char-alist-cache nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;;; Function declarations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defun sgml-display-char-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "Return the current display character alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 Alist with entity name as key and display character as content."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (unless (file-exists-p sgml-display-char-list-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (error "No display char file: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 sgml-display-char-list-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (sgml-cache-catalog sgml-display-char-list-filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 'sgml-display-char-alist-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (function sgml-read-display-char-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defun sgml-read-display-char-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (let (key disp-char alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (while (re-search-forward "^\\([0-9]+\\)[ \t]+\\(.+\\)$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (setq key (buffer-substring (match-beginning 2) (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (setq disp-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (char-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (string-to-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (buffer-substring (match-beginning 1) (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (push (cons key disp-char)
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 alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defun sgml-charent-to-dispchar-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "Association list to hold relations of the type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (CHARACTER-NAME . CHARACTER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 CHARACTER-NAME is a string holding a character name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 CHARACTER is a string holding a single displayable character"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (sgml-need-dtd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (let ((display-chars (sgml-display-char-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (alist nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (sgml-map-entities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (lambda (entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (let ((char (cdr (assoc (sgml-entity-text entity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 display-chars))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (when char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (push (cons (sgml-entity-name entity) char) alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (sgml-dtd-entities sgml-dtd-info))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun sgml-charent-to-display-char ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "Replace character entities with their display character equivalents"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (let ((charent-to-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (sgml-charent-to-dispchar-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 charent replacement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (sgml-with-parser-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (while (re-search-forward "&\\(\\w\\(\\w\\|\\s_\\)+\\);?" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq charent (buffer-substring (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (if (setq replacement (cdr (assoc charent charent-to-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (replace-match replacement t t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defun sgml-display-char-to-charent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "Replace displayable characters with their character entity equivalents"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (loop for pair in (sgml-charent-to-dispchar-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 do (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (while (search-forward (cdr pair) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (replace-match (concat "&" (car pair) ";") t t))))))
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 ;;; psgml-charent.el ends here