blob: 31ab871c6a12e6226ba9ac16e8ecfe81019bb04b (
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
;;; iso-html.el --- Translating HTML to ISO-8859/1 while editing a file
;;*****************************************************************************
;; $Id: iso-html.el,v 1.1 1994/10/27 10:18:55 gerd Exp gerd $
;;*****************************************************************************
;;
;; Description:
;; When using HTML it is highly desirable to display national
;; characters contained in the ISO-8859/1 character set. Editing
;; files with ISO-8859/1 characters is enabled in GNU Emacs since
;; version 19.
;;
;; The solution is iso-html.el. The extended
;; character set is used only temporarily during editing of a
;; file in Emacs. The HTML file contains pure ASCII
;; representations of the extended characters.
;;
;; iso-html.el provides a minor mode which anchors itself in
;; various hooks to perform translations when reading or writing
;; files.
;;
;; No provisions are made to insert ISO-8859/1 characters since
;; other packages are availlable for this purpose.
;;
;;
;; Installation:
;; 1. Ensure that iso-html.el is on the load-path.
;; 2. For efficiency it might be desirable to byte-compile
;; iso-html.el.
;; 3. Put the following in your .emacs file or a similar place
;; where it is loaded when needed.
;;
;; (autoload 'iso-html-minor-mode
;; "iso-html"
;; "Translate HTML to ISO 8859/1 while visiting a file."
;; t)
;;
;; 4. Enable the iso-html minor mode for the appropriate
;; files. This depends on the major mode you use for editing
;; HTML files. For this purpose you can use the entry hook
;; of this mode. E.g.
;;
;; (setq html-mode-hook
;; (function (lambda () (interactive)
;; (iso-html-minor-mode 1)
;; ; and other initializations
;; ; ...
;; )))
;;
;; Bugs and Problems:
;;
;; - There might be problems when saving a narrowed buffer.
;; - Point might not be restored properly.
;;
;; - Writing of a region is not supported. There seems to be no
;; appropriate hook.
;;
;;
;; To do:
;; - iso-html can be used for a wider range of translations when
;; reading and writing. Maybe it's worth extracting those
;; routines which are more general and make iso-html a sample
;; instance of the general routines.
;;
;;
;; Changes:
;; - Extracted from iso-tex.el
;;
;; Author:
;; Gerd Neugebauer
;; Ödenburger Str. 16
;; 64295 Darmstadt (Germany)
;;
;; Net: gerd@imn.th-leipzig.de
;;
;;*****************************************************************************
;; LCD Archive Entry:
;; iso-html|Gerd Neugebauer|gerd@imn.th-leipzig.de|
;; Translating HTML to ISO-8859/1 while editing a file.|
;; $Date: 1994/10/27 10:18:55 $|$Revision: 1.1 $||
;;*****************************************************************************
;;
;; Copyright (C) 1994 Gerd Neugebauer
;;
;; iso-html.el is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY. No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing. Refer to the GNU General Public
;; License for full details.
;;
;; Everyone is granted permission to copy, modify and redistribute
;; iso-html.el, but only under the conditions described in the
;; GNU General Public License. A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities. It should be in a
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
;;
;;;----------------------------------------------------------------------------
;;; Variable definitions and initializations
(defvar iso-html-minor-mode nil
"Variable indicating when iso-html-minor-mode is active.")
(or (assq 'iso-html-minor-mode minor-mode-alist)
(setq minor-mode-alist (cons '(iso-html-minor-mode " ISO-HTML")
minor-mode-alist)))
(defvar iso-html-minor-mode-initialized nil
"Variable indicating if iso-html-minor-mode is already initialized in this
buffer. This variable is buffer local.")
(make-variable-buffer-local 'iso-html-minor-mode-initialized)
(defvar html-2-iso-regex
"&[a-zA-Z]*;"
"Regular expression to pre-select substrings to be translated by html-2-iso.")
(defvar iso-2-html-regex "[¡-ÿ]"
"Regular expression to pre-select substrings to be translated by iso-2-html.")
(defvar iso-2-html-alist nil
"Alist of CHAR.STRING pairs used by iso-2-html.")
(defvar html-2-iso-alist nil
"Alist of STRING.ISO-CHAR pairs used by html-2-iso.")
(defun define-iso-html (char &optional string &rest names)
"Define a translation between ISO-8859/1 characters and Html sequences.
CHAR is the ISO-8859/1 character code as a single letter string.
If STRING is non nil then it is used as representation of CHAR.
The optional remaining arguments are used to translate Html sequences to
characters."
(if string (setq iso-2-html-alist (cons
(cons (string-to-char char) string)
iso-2-html-alist)))
(while names
(setq html-2-iso-alist (cons (cons (car names) char)
html-2-iso-alist))
(setq names (cdr names))
)
)
(if (null iso-2-html-alist)
(progn
; (define-iso-html "¡" "" "" )
; (define-iso-html "¢" "" "" )
; (define-iso-html "£" "" "" )
; (define-iso-html "¤" "" "" )
; (define-iso-html "¥" "" "" )
; (define-iso-html "¦" "" "" )
; (define-iso-html "§" "" "" )
; (define-iso-html "¨" "" "" )
; (define-iso-html "©" "" "" )
; (define-iso-html "ª" "" "" )
; (define-iso-html "«" "" "" )
; (define-iso-html "¬" "" "" )
; (define-iso-html "" "" "" )
; (define-iso-html "®" "" "" )
; (define-iso-html "¯" "" "" )
; (define-iso-html "°" "" "" )
; (define-iso-html "±" "" "" )
; (define-iso-html "²" "" "" )
; (define-iso-html "³" "" "" )
; (define-iso-html "´" "" "" )
; (define-iso-html "µ" "" "" )
; (define-iso-html "¶" "" "" )
; (define-iso-html "·" "" "" )
; (define-iso-html "¸" "" "" )
; (define-iso-html "¹" "" "" )
; (define-iso-html "º" "" "" )
; (define-iso-html "»" "" "" )
; (define-iso-html "¼" "" "" )
; (define-iso-html "½" "" "" )
; (define-iso-html "¾" "" "" )
; (define-iso-html "¿" "" "" )
(define-iso-html "À" "À" "À" )
(define-iso-html "Á" "Á" "Á" )
(define-iso-html "Â" "Â" "Â" )
(define-iso-html "Ã" "Ã" "Ã" )
(define-iso-html "Ä" "Ä" "Ä" )
(define-iso-html "Å" "Å" "Å" )
(define-iso-html "Æ" "Æ" "Æ" )
(define-iso-html "Ç" "Ç" "Ç" )
(define-iso-html "È" "È" "È" )
(define-iso-html "É" "É" "É" )
(define-iso-html "Ê" "Ê" "Ê" )
(define-iso-html "Ë" "Ë" "Ë" )
(define-iso-html "Ì" "Ì" "Ì" )
(define-iso-html "Í" "Í" "Í" )
(define-iso-html "Î" "Î" "Î" )
(define-iso-html "Ï" "Ï" "Ï" )
(define-iso-html "Ð" "Ð" "Ð" )
(define-iso-html "Ñ" "Ñ" "Ñ" )
(define-iso-html "Ò" "Ò" "Ò" )
(define-iso-html "Ó" "Ó" "Ó" )
(define-iso-html "Ô" "Ô" "Ô" )
(define-iso-html "Õ" "Õ" "Õ" )
(define-iso-html "Ö" "Ö" "Ö" )
; (define-iso-html "×" "" "" )
(define-iso-html "Ø" "Ø" "Ø" )
(define-iso-html "Ù" "Ù" "Ù" )
(define-iso-html "Ú" "Ú" "Ú" )
(define-iso-html "Û" "Û" "Û" )
(define-iso-html "Ü" "Ü" "Ü" )
(define-iso-html "Ý" "Ý" "Ý" )
(define-iso-html "Þ" "Þ" "Þ" )
(define-iso-html "ß" "ß" "ß" )
(define-iso-html "à" "à" "à" )
(define-iso-html "á" "á" "á" )
(define-iso-html "â" "â" "â" )
(define-iso-html "ã" "ã" "ã" )
(define-iso-html "ä" "ä" "ä" )
(define-iso-html "å" "å" "å" )
(define-iso-html "æ" "æ" "æ" )
(define-iso-html "ç" "ç" "ç" )
(define-iso-html "è" "è" "è" )
(define-iso-html "é" "é" "é" )
(define-iso-html "ê" "ê" "ê" )
(define-iso-html "ë" "ë" "ë" )
(define-iso-html "ì" "ì" "ì" )
(define-iso-html "í" "í" "í" )
(define-iso-html "î" "î" "î" )
(define-iso-html "ï" "ï" "ï" )
(define-iso-html "ð" "ð" "ð" )
(define-iso-html "ñ" "ñ" "ñ" )
(define-iso-html "ò" "ò" "ò" )
(define-iso-html "ó" "ó" "ó" )
(define-iso-html "ô" "ô" "ô" )
(define-iso-html "õ" "õ" "õ" )
(define-iso-html "ö" "ö" "ö" )
; (define-iso-html "÷" "" "" )
(define-iso-html "ø" "ø" "ø" )
(define-iso-html "ù" "ù" "ù" )
(define-iso-html "ú" "ú" "ú" )
(define-iso-html "û" "û" "û" )
(define-iso-html "ü" "ü" "ü" )
(define-iso-html "ý" "ý" "ý" )
(define-iso-html "þ" "þ" "þ" )
(define-iso-html "ÿ" "ÿ" "ÿ" )
))
;;;----------------------------------------------------------------------------
;;; Definition of the minor mode
(defun iso-html-minor-mode (&optional arg)
"Minor mode to translate HTML sequences into ISO 8859/1 characters while
visiting a file.
Provisions are made to translate them back when writing."
(interactive)
(if (null iso-html-minor-mode-initialized)
(progn
(setq iso-html-minor-mode-initialized t)
(add-hook 'write-contents-hooks 'iso-html-write)
;;
(make-local-variable 'after-save-hook)
(add-hook 'after-save-hook 'iso-html-after-write)
;; There seem to be two versions of this hook around
;; Horrible to use such undocumented features :-)
(make-local-variable 'after-save-hooks)
(add-hook 'after-save-hooks 'iso-html-after-write)
;;
(make-local-variable 'iso-html-minor-mode)
)
)
(setq iso-html-minor-mode
(if (null arg) (not iso-html-minor-mode)
(> (prefix-numeric-value arg) 0)))
(if iso-html-minor-mode (html-2-iso) (iso-2-html) )
)
(defun iso-html-write ()
"Function anchored in the local-write-file-hooks. It is not removed but
disabled with the iso-html-minor-mode."
(if iso-html-minor-mode (iso-2-html))
)
(defun iso-html-after-write ()
"Function anchored in the after-save-hooks. It is not removed but
disabled whith the iso-html-minor-mode."
(if iso-html-minor-mode (html-2-iso))
)
(defun iso-2-html ()
"Translate ISO-8859/1 extended characters into Html sequences.
The variable iso-2-html-regex is used to preselect a character which is then
translated using the variable iso-2-html-alist.
Use the function define-iso-html instead of setting iso-2-html-alist."
(let ((buffer-read-only nil)
(state (buffer-modified-p)))
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp iso-2-html-regex (point-max) t)
(let ((new (assq (string-to-char
(buffer-substring
(- (point) 1)
(point)))
iso-2-html-alist)))
(if new (progn (delete-backward-char 1)
(insert (cdr new)) )
)
)
)
)
(set-buffer-modified-p state)
)
nil
)
(defun html-2-iso ()
"Translate Html sequences into ISO-8859/1 extended characters.
The variable html-2-iso-regex is used to preselect a character which is then
translated using the variable html-2-iso-alist.
Use the function define-iso-html instead of setting html-2-iso-alist."
(let ((buffer-read-only nil)
(state (buffer-modified-p)))
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp html-2-iso-regex (point-max) t)
(let ((hit (buffer-substring (match-beginning 0) (match-end 0)))
(b (match-beginning 0))
(e (match-end 0)) )
(setq hit (assoc hit html-2-iso-alist))
(if hit
(progn
(delete-region b e)
(insert (cdr hit))
)
)
)
)
)
(set-buffer-modified-p state)
)
nil
)
; ¡¢£¤¥¦§
; ¨©ª«¬®¯
; °±²³´µ¶·
; ¸¹º»¼½¾¿
; ÀÁÂÃÄÅÆÇ
; ÈÉÊËÌÍÎÏ
; ÐÑÒÓÔÕÖ×
; ØÙÚÛÜÝÞß
; àáâãäåæç
; èéêëìíîï
; ðñòóôõö÷
; øùúûüýþÿ
|