Add arch taglines
[bpt/emacs.git] / lisp / international / ogonek.el
CommitLineData
ab87fc3d 1;;; ogonek.el --- change the encoding of Polish diacritics
12365826
RS
2
3;; Copyright (C) 1997 Free Software Foundation, Inc.
4
5;; Author: W{\l}odek Bzyl, Ryszard Kubiak
6;; Maintainer: rysiek@ipipan.gda.pl (Ryszard Kubiak)
7;; Keywords: i18n
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
26;;; Commentary:
27
28;; To use this library load it using
29;; M-x load-library [enter] ogonek
30;; Then, you may get a short info by calling one of
a1506d29 31;; M-x ogonek-jak -- in Polish
12365826
RS
32;; M-x ogonek-how -- in English "
33
3413eafa
SE
34;;; Code:
35
36(defgroup ogonek nil
37 "Change the encoding of Polish diacritic characters."
38 :prefix "ogonek-"
39 :group 'i18n)
40
12365826 41(defconst ogonek-name-encoding-alist
a1506d29
JB
42 '(("ascii" . (?A ?C ?E ?L ?N ?O ?S ?Z ?Z
43 ?a ?c ?e ?l ?n ?o ?s ?z ?z))
44 ("iso8859-2" . (161 198 202 163 209 211 166 172 175
45 177 230 234 179 241 243 182 188 191))
46 ("mazovia" . (143 149 144 156 165 163 152 160 161
12365826 47 134 141 145 146 164 162 158 166 167))
a1506d29 48 ("windows-EE" . (165 198 202 163 209 211 140 143 175
12365826 49 185 230 234 179 241 243 156 159 191))
a1506d29 50 ("windows-PL" . (165 198 202 163 209 211 140 143 175
12365826 51 185 230 234 179 241 243 156 159 191))
a1506d29 52 ("latin-2" . (164 143 168 157 227 224 151 141 189
12365826 53 165 134 169 136 228 162 152 171 190))
a1506d29 54 ("CP852" . (164 143 168 157 227 224 151 141 189
12365826 55 165 134 169 136 228 162 152 171 190))
a1506d29 56 ("MeX" . (129 130 134 138 139 211 145 153 155
12365826 57 161 162 166 170 171 243 177 185 187))
a1506d29 58 ("CorelDraw" . (197 242 201 163 209 211 255 225 237
12365826 59 229 236 230 198 241 243 165 170 186))
a1506d29 60 ("Amiga" . (194 202 203 206 207 211 212 218 219
12365826 61 226 234 235 238 239 243 244 250 251))
a1506d29 62 ("Mac" . (132 140 162 252 193 238 229 143 251
12365826 63 136 141 171 184 196 151 230 144 253))
a1506d29 64 )
12365826 65 "The constant `ogonek-name-encoding-alist' is a list of (NAME.LIST) pairs.
f23515e1
RS
66Each LIST contains codes for 18 Polish diacritic characters. The codes
67are given in the following order:
12365826
RS
68 Aogonek Cacute Eogonek Lslash Nacute Oacute Sacute Zacute Zdotaccent
69 aogonek cacute eogonek lslash nacute oacute sacute zacute zdotaccent.")
70
f23515e1 71;; ------ A Little Info in Polish ---------------
12365826
RS
72
73(defconst ogonek-informacja
f23515e1 74 " FUNKCJE INTERAKCYJNE UDOST/EPNIANE PRZEZ BIBLIOTEK/E `ogonek'.
12365826 75
f23515e1 76Je/sli czytasz ten tekst, to albo przegl/adasz plik /xr/od/lowy
a1506d29
JB
77biblioteki `ogonek.el', albo wywo/la/le/s polecenie `ogonek-jak'.
78W drugim przypadku mo/zesz usun/a/c tekst z ekranu, stosuj/ac
12365826
RS
79polecenie `M-x kill-buffer'.
80
f23515e1 81Niniejsza biblioteka dostarcza funkcji do zmiany kodowania polskich
12365826
RS
82znak/ow diakrytycznych. Funkcje te mo/zna pogrupowa/c nast/epuj/aco.
83
a1506d29
JB
84 1. `ogonek-recode-region' oraz `ogonek-recode-buffer'
85 przekodowuj/a zaznaczony fragment wzgl/ednie ca/ly buffor.
12365826 86 Po wywo/laniu interakcyjnym funkcji zadawane s/a
f23515e1 87 pytania o parametry przekodowania: nazw/e kodowania
a1506d29
JB
88 w tek/scie /xr/od/lowym i nazw/e kodowania docelowego.
89 Poni/zsze przyk/lady powinny wyja/sni/c, jakich parametr/ow
12365826
RS
90 oczekuj/a wymienione funkcje:
91
f23515e1 92 (ogonek-recode-region (poczatek-fragmentu) (koniec-fragmentu)
12365826 93 nazwa-kodowania-w-tekscie-zrodlowym nazwa-kodowania-docelowa)
a1506d29
JB
94 (ogonek-recode-buffer
95 nazwa-kodowania-w-tekscie-zrodlowym nazwa-kodowania-docelowa)
12365826 96
f23515e1
RS
97 2. `ogonek-prefixify-region' oraz `ogonek-prefixify-buffer'
98 s/lu/z/a do wprowadzania notacji prefiksowej.
12365826 99
f23515e1 100 (ogonek-prefixify-region (poczatek-fragmentu) (koniec-fragmentu)
12365826 101 nazwa-kodowania-w-tekscie-zrodlowym znak-prefiksu)
a1506d29
JB
102 (ogonek-prefixify-buffer
103 nazwa-kodowania-w-tekscie-zrodlowym znak-prefiksu)
12365826 104
a1506d29 105 3. `ogonek-deprefixify-region' oraz `ogonek-deprefixify-buffer'
f23515e1 106 s/lu/z/a do usuwania notacji prefiksowej.
a1506d29 107
f23515e1 108 (ogonek-deprefixify-region (poczatek-fragmentu) (koniec-fragmentu)
12365826 109 znak-prefiksu nazwa-kodowania-docelowa)
a1506d29
JB
110 (ogonek-prefixify-buffer
111 znak-prefiksu nazwa-kodowania-docelowa)
12365826
RS
112
113 U/zycie klawisza TAB w trybie interakcyjnym powoduje wy/swietlenie
f23515e1 114 listy dopuszczalnych nazw kod/ow, pami/etanych w sta/lej
a1506d29 115 `ogonek-name-encoding-alist'.
12365826 116
a1506d29 117 Funkcje biblioteki odwo/luj/a si/e do pi/eciu zmiennych, kt/ore
12365826 118 przechowuj/a podpowiedzi do zadawanych pyta/n. Nazwy tych zmiennych
a1506d29 119 oraz ich warto/sci domy/slne s/a nast/epuj/ace:
12365826
RS
120
121 ogonek-from-encoding iso8859-2
f23515e1 122 ogonek-to-encoding ascii
12365826
RS
123 ogonek-prefix-char /
124 ogonek-prefix-from-encoding iso8859-2
125 ogonek-prefix-to-encoding iso8859-2
126
127 Powy/zsze warto/sci domy/slne mo/zna zmieni/c przez umieszczenie w pliku
128 konfiguracyjnym `~/.emacs' odpowiednich przypisa/n, na przyk/lad:
129
f23515e1
RS
130 (setq ogonek-prefix-char ?/)
131 (setq ogonek-prefix-to-encoding \"iso8859-2\")
12365826
RS
132
133 Zamiast wczytywania ca/lej biblioteki `ogonek.el' mo/zna w pliku
a1506d29 134 `~/.emacs' za/z/ada/c wczytania wybranych funkcji, na dodatek dopiero
f23515e1 135 w chwili ich rzeczywistego u/zycia:
12365826 136
f23515e1
RS
137 (autoload 'ogonek-jak \"ogonek\")
138 (autoload 'ogonek-recode-region \"ogonek\")
139 (autoload 'ogonek-prefixify-region \"ogonek\")
140 (autoload 'ogonek-deprefixify-region \"ogonek\")
12365826
RS
141
142 Cz/esto wyst/epuj/ace kombinacje wywo/la/n funkcji mo/zna dla wygody
143 skr/oci/c i przypisa/c klawiszom. Oto praktyczne przyk/lady:
144
f23515e1
RS
145 (defun deprefixify-iso8859-2-region (start end)
146 (interactive \"*r\")
147 (ogonek-deprefixify-region start end ?/ \"iso8859-2\"))
148 (global-set-key \"\\C-cd\" 'deprefixify-iso8859-2-region) ; ctrl-c d
12365826 149
a1506d29 150 (defun mazovia-to-iso8859-2 (start end)
f23515e1
RS
151 (interactive \"*r\")
152 (ogonek-recode-region start end \"mazovia\" \"iso8859-2\"))
153 (global-set-key \"\\C-cr\" 'mazovia-to-iso8859-2) ; ctrl-c r
12365826 154
f23515e1
RS
155 (defun prefixify-iso8859-2-region (start end)
156 (interactive \"*r\")
157 (ogonek-prefixify-region start end \"iso8859-2\" ?/))
158 (global-set-key \"\\C-cp\" 'prefixify-iso8859-2-region) ; ctrl-c p
12365826
RS
159
160 Ka/zd/a operacj/e przekodowania mo/zna w ca/lo/sci odwo/la/c
161 przez wykonanie polecenia `undo'.")
162
163(defun ogonek-jak ()
f23515e1 164 "Display `ogonek-informacja' in an auxiliary *ogonek-jak* buffer."
12365826
RS
165 (interactive)
166 (set-buffer (get-buffer-create " *ogonek-jak*"))
167 (insert ogonek-informacja)
168 (switch-to-buffer " *ogonek-jak*")
169 (beginning-of-buffer))
170
f23515e1 171;; ------ A Little Info in English --------
12365826
RS
172
173(defconst ogonek-information
f23515e1 174 " THE INTERACTIVE FUNCTIONS PROVIDED BY THE LIBRARY `ogonek'.
12365826
RS
175
176If you read this text then you are either looking at the library's
f23515e1 177source text or you have called the `ogonek-how' command. In the
12365826
RS
178latter case you may remove this text using `M-x kill-buffer'.
179
180The library provides functions for changing the encoding of Polish
181diacritic characters, the ones with an `ogonek' below or above them.
f23515e1
RS
182The functions come in the following groups.
183
184 1. `ogonek-recode-region' and `ogonek-recode-buffer' to change
a1506d29
JB
185 between one-character encodings, such as `iso-8859-2', `mazovia',
186 plain `ascii' or `TeX'. As the names suggest you may recode
187 either the entire current buffer or just a marked region
188 in it. You may use the functions interactively as commands.
189 Once you call a command you will be asked about the code
190 currently used in your text and the target encoding, the one
191 you want to get. The following example shows a non-interactive
192 use of the functions in a program. This also illustrates what
f23515e1
RS
193 type of parameters the functions expect to be called with:
194
a1506d29 195 (ogonek-recode-region
f23515e1 196 (region-beginning) (region-end) from-code-name to-code-name)
a1506d29 197 (ogonek-recode-buffer from-code-name to-code-name)
12365826 198
a1506d29 199 2. `ogonek-prefixify-region' and `ogonek-prefixify-buffer' for
f23515e1 200 introducing prefix notation:
12365826 201
a1506d29 202 (ogonek-prefixify-region
f23515e1 203 (region-beginning) (region-end) from-code-name prefix-char)
a1506d29
JB
204 (ogonek-prefixify-buffer from-code-name prefix-char)
205
206 3. `ogonek-deprefixify-region' and `ogonek-deprefixify-buffer' for
f23515e1 207 removing prefix notation:
a1506d29
JB
208
209 (ogonek-deprefixify-region
f23515e1 210 (region-beginning) (region-end) prefix-char to-code-name)
a1506d29 211 (ogonek-prefixify-buffer prefix-char to-code-name)
12365826 212
f23515e1 213 The TAB character used in interactive mode makes `emacs'
a1506d29 214 display the list of encodings recognized by the library. The list
f23515e1 215 is stored in the constant `ogonek-name-encoding-alist'.
12365826 216
f23515e1 217 The `ogonek' functions refer to five variables in which the suggested
a1506d29 218 answers to dialogue questions are stored. The variables and their
f23515e1 219 default values are:
a1506d29 220
12365826 221 ogonek-from-encoding iso8859-2
f23515e1
RS
222 ogonek-to-encoding ascii
223 ogonek-prefix-char /
12365826
RS
224 ogonek-prefix-from-encoding iso8859-2
225 ogonek-prefix-to-encoding iso8859-2
226
a1506d29 227 The above default values can be changed by placing appropriate settings
12365826
RS
228 in the '~/.emacs' file:
229
f23515e1
RS
230 (setq ogonek-prefix-char ?/)
231 (setq ogonek-prefix-to-encoding \"iso8859-2\")
12365826 232
f23515e1
RS
233 Instead of loading the whole library `ogonek' it may be better to
234 autoload the needed functions, for example by placing in `~/.emacs':
12365826 235
f23515e1
RS
236 (autoload 'ogonek-how \"ogonek\")
237 (autoload 'ogonek-recode-region \"ogonek\")
238 (autoload 'ogonek-prefixify-region \"ogonek\")
239 (autoload 'ogonek-deprefixify-region \"ogonek\")
12365826
RS
240
241 The most frequent function calls can be abbreviated and assigned to
242 keyboard keys. Here are a few practical examples:
243
f23515e1
RS
244 (defun deprefixify-iso8859-2-region (start end)
245 (interactive \"*r\")
246 (ogonek-deprefixify-region start end ?/ \"iso8859-2\"))
247 (global-set-key \"\\C-cd\" 'deprefixify-iso8859-2-region) ; ctrl-c d
12365826 248
a1506d29 249 (defun mazovia-to-iso8859-2 (start end)
f23515e1
RS
250 (interactive \"*r\")
251 (ogonek-recode-region start end \"mazovia\" \"iso8859-2\"))
252 (global-set-key \"\\C-cr\" 'mazovia-to-iso8859-2) ; ctrl-c r
12365826 253
f23515e1
RS
254 (defun prefixify-iso8859-2-region (start end)
255 (interactive \"*r\")
256 (ogonek-prefixify-region start end \"iso8859-2\" ?/))
257 (global-set-key \"\\C-cp\" 'prefixify-iso8859-2-region) ; ctrl-c p
12365826 258
f23515e1 259 Each recoding operation can be called off using the `undo' command.")
12365826
RS
260
261(defun ogonek-how ()
f23515e1 262 "Display `ogonek-information' in an auxiliary *recode-how* buffer."
12365826 263 (interactive "*")
f23515e1 264 (set-buffer (get-buffer-create " *ogonek-how*"))
12365826 265 (insert ogonek-information)
f23515e1 266 (switch-to-buffer " *ogonek-how*")
12365826
RS
267 (beginning-of-buffer))
268
f23515e1 269;; ---- Variables keeping the suggested answers to dialogue questions -----
3413eafa 270(defvar ogonek-encoding-choices
a1506d29 271 (cons 'choice
3413eafa
SE
272 (mapcar (lambda (x) (list 'const (car x)))
273 ogonek-name-encoding-alist))
274 "List of ogonek encodings. Used only for customization.")
275(defcustom ogonek-from-encoding "iso8859-2"
276 "*Encoding in the source file of recoding."
277 :type ogonek-encoding-choices
278 :group 'ogonek)
279(defcustom ogonek-to-encoding "ascii"
280 "*Encoding in the target file of recoding."
281 :type ogonek-encoding-choices
282 :group 'ogonek)
283(defcustom ogonek-prefix-char ?/
284 "*Prefix character for prefix encodings."
285 :type 'character
286 :group 'ogonek)
287(defcustom ogonek-prefix-from-encoding "iso8859-2"
288 "*Encoding in the source file subject to prefixifation."
289 :type ogonek-encoding-choices
290 :group 'ogonek)
291(defcustom ogonek-prefix-to-encoding "iso8859-2"
292 "*Encoding in the target file subject to deprefixifation."
293 :type ogonek-encoding-choices
294 :group 'ogonek)
12365826 295
f23515e1 296;; ---- Auxiliary functions for reading parameters in interactive mode ----
12365826
RS
297
298(defun ogonek-read-encoding (prompt default-name-var)
f23515e1 299 "Read encoding name with completion based on `ogonek-name-encoding-alist'.
b9d67a77 300Store the name in the parameter-variable DEFAULT-NAME-VAR.
f23515e1 301PROMPT is a string to be shown when the user is asked for a name."
a1506d29
JB
302 (let ((encoding
303 (completing-read
12365826
RS
304 (format "%s (default %s): " prompt (eval default-name-var))
305 ogonek-name-encoding-alist nil t)))
f23515e1 306 ;; change the default name to the one just read
a1506d29
JB
307 (set default-name-var
308 (if (string= encoding "") (eval default-name-var) encoding))
f23515e1 309 ;; return the new default as the name you read
12365826
RS
310 (eval default-name-var)))
311
312(defun ogonek-read-prefix (prompt default-prefix-var)
f23515e1 313 "Read a prefix character for prefix notation.
a1506d29 314The result is stored in the variable DEFAULT-PREFIX-VAR.
f23515e1 315PROMPT is a string to be shown when the user is asked for a new prefix."
a1506d29
JB
316 (let ((prefix-string
317 (read-string
318 (format "%s (default %s): " prompt
12365826
RS
319 (char-to-string (eval default-prefix-var))))))
320 (if (> (length prefix-string) 1)
a1506d29 321 (error "! Only one character expected")
f23515e1 322 ;; set the default prefix character to the one just read
12365826 323 (set default-prefix-var
a1506d29
JB
324 (if (string= prefix-string "")
325 (eval default-prefix-var)
12365826 326 (string-to-char prefix-string)))
f23515e1 327 ;; the new default prefix is the function's result:
12365826
RS
328 (eval default-prefix-var))))
329
330(defun ogonek-lookup-encoding (encoding)
f23515e1 331 "Pick up an association for ENCODING in `ogonek-name-encoding-alist'.
a1506d29 332Before returning a result test whether the string ENCODING is in
f23515e1 333the list `ogonek-name-encoding-alist'"
12365826
RS
334 (let ((code-list (assoc encoding ogonek-name-encoding-alist)))
335 (if (null code-list)
e8af40ee 336 (error "! Name `%s' not known in `ogonek-name-encoding-alist'"
12365826
RS
337 encoding)
338 (cdr code-list))))
339
f23515e1 340;; ---- An auxiliary function for zipping two lists of equal length ----
12365826
RS
341
342(defun ogonek-zip-lists (xs ys)
a1506d29
JB
343 "Build a list of pairs from lists XS and YS of the same length."
344 (let ((pairs nil))
12365826
RS
345 (while xs
346 (setq pairs (cons (cons (car xs) (car ys)) pairs))
347 (setq xs (cdr xs))
348 (setq ys (cdr ys)))
f23515e1 349 ;; `pairs' are the function's result
12365826
RS
350 pairs))
351
f23515e1 352;; ---- An auxiliary function building a one-to-one recoding table -----
12365826 353
a1506d29 354(defun ogonek-build-table (recoding-pairs)
f23515e1
RS
355 "Build a table required by Emacs's `translate-region' function.
356RECODING-PAIRS is a list of character pairs for which recoding
a1506d29 357is not an identity.
12365826
RS
358By using the built-in `translate-region' function
359we gain better performance compared to converting characters
360by a hand-written routine as it is done for prefix encodings."
361 (let ((table (make-string 256 0))
362 (i 0))
a1506d29
JB
363 (while (< i 256)
364 (aset table i i)
12365826 365 (setq i (1+ i)))
f23515e1 366 ;; make changes in `table' according to `recoding-pairs'
12365826
RS
367 (while recoding-pairs
368 (aset table (car (car recoding-pairs)) (cdr (car recoding-pairs)))
369 (setq recoding-pairs (cdr recoding-pairs)))
f23515e1 370 ;; return the table just built
12365826
RS
371 table))
372
f23515e1
RS
373;; ---- Commands for one-to-one recoding -------------------------------
374
a1506d29 375(defun ogonek-recode-region (start end from-encoding to-encoding)
f23515e1 376 "Recode text in a marked region in one-to-one manner.
a1506d29
JB
377When called interactively ask the user for the names of the FROM-
378and TO- encodings."
12365826 379 (interactive (progn (barf-if-buffer-read-only)
a1506d29
JB
380 (list
381 (region-beginning)
12365826
RS
382 (region-end)
383 (ogonek-read-encoding "From code" 'ogonek-from-encoding)
384 (ogonek-read-encoding "To code" 'ogonek-to-encoding))))
385 (save-excursion
a1506d29 386 (translate-region
12365826 387 start end
a1506d29 388 (ogonek-build-table
12365826
RS
389 (ogonek-zip-lists
390 (ogonek-lookup-encoding from-encoding)
391 (ogonek-lookup-encoding to-encoding))))))
392
393(defun ogonek-recode-buffer (from-encoding to-encoding)
f23515e1 394 "Call `ogonek-recode-region' on the entire buffer.
a1506d29 395When called interactively ask the user for the names of the FROM-
f23515e1 396and TO- encodings."
12365826 397 (interactive (progn (barf-if-buffer-read-only)
a1506d29 398 (list
12365826
RS
399 (ogonek-read-encoding "From code" 'ogonek-from-encoding)
400 (ogonek-read-encoding "To code" 'ogonek-to-encoding))))
a1506d29 401 (ogonek-recode-region
12365826
RS
402 (point-min) (point-max) from-encoding to-encoding))
403
f23515e1 404;; ---- Recoding with prefix notation -------------------------------
12365826 405
a1506d29
JB
406(defconst ogonek-prefix-code '(?A ?C ?E ?L ?N ?O ?S ?X ?Z
407 ?a ?c ?e ?l ?n ?o ?s ?x ?z))
408
12365826 409(defun ogonek-prefixify-region (start end from-encoding prefix-char)
f23515e1 410 "In a region, replace FROM-encoded Polish characters with PREFIX pairs.
a1506d29
JB
411A PREFIX pair generated consists of PREFIX-CHAR and the respective
412character listed in the `ogonek-prefix-code' constant.
f23515e1 413PREFIX-CHAR itself gets doubled."
12365826 414 (interactive (progn (barf-if-buffer-read-only)
a1506d29
JB
415 (list
416 (region-beginning)
417 (region-end)
12365826
RS
418 (ogonek-read-encoding "From code" 'ogonek-prefix-from-encoding)
419 (ogonek-read-prefix "Prefix character" 'ogonek-prefix-char))))
a1506d29 420 (let*
12365826 421 ((from-code (ogonek-lookup-encoding from-encoding))
f23515e1
RS
422 (to-code ogonek-prefix-code)
423 (recoding-pairs ; `ogonek-prefix-char' added for doubling
a1506d29
JB
424 (ogonek-zip-lists
425 (cons prefix-char from-code)
12365826
RS
426 (cons prefix-char to-code))))
427 (save-excursion
428 (goto-char start)
429 (while (< (point) end)
430 (let ((pair (assoc (following-char) recoding-pairs)))
431 (if (null pair)
f23515e1 432 ;; not a Polish character -- skip it
12365826 433 (forward-char 1)
f23515e1 434 ;; Polish character -- insert a prefix pair instead
12365826
RS
435 (delete-char 1)
436 (insert ogonek-prefix-char)
437 (insert (cdr pair))
f23515e1 438 ;; the region is now one character longer
12365826
RS
439 (setq end (1+ end))))))))
440
441(defun ogonek-prefixify-buffer (from-encoding prefix-char)
442 "Call `ogonek-prefixify-region' on the entire buffer."
443 (interactive (progn (barf-if-buffer-read-only)
a1506d29 444 (list
12365826
RS
445 (ogonek-read-encoding "From code" 'ogonek-prefix-from-encoding)
446 (ogonek-read-prefix "Prefix character" 'ogonek-prefix-char))))
a1506d29 447 (ogonek-prefixify-region
12365826
RS
448 (point-min) (point-max) from-encoding prefix-char))
449
450(defun ogonek-deprefixify-region (start end prefix-char to-encoding)
f23515e1 451 "In a region, replace PREFIX pairs with their corresponding TO-encodings.
a1506d29 452PREFIX-CHAR followed by a Polish character from the `ogonek-prefix-code'
f23515e1 453list is replaced with the corresponding TO-encoded character. A doubled
a1506d29
JB
454PREFIX-CHAR gets replaced with a single one. A combination of PREFIX-CHAR
455followed by a non-Polish character, that is one not listed in the
f23515e1 456`ogonek-prefix-code' constant, is left unchanged."
12365826 457 (interactive (progn (barf-if-buffer-read-only)
a1506d29 458 (list (region-beginning)
12365826 459 (region-end)
a1506d29 460 (ogonek-read-prefix
12365826 461 "Prefix character" 'ogonek-prefix-char)
a1506d29 462 (ogonek-read-encoding
12365826 463 "To code" 'ogonek-prefix-to-encoding))))
a1506d29 464 (let*
f23515e1 465 ((from-code ogonek-prefix-code)
12365826 466 (to-code (ogonek-lookup-encoding to-encoding))
a1506d29
JB
467 (recoding-pairs
468 (ogonek-zip-lists
469 (cons prefix-char from-code)
12365826
RS
470 (cons prefix-char to-code))))
471 (save-excursion
472 (goto-char start)
473 (while (< (point) end)
474 (forward-char 1)
475 (if (or (not (= (preceding-char) prefix-char)) (= (point) end))
f23515e1 476 ;; non-prefix character or the end-of-region -- do nothing
12365826 477 ()
f23515e1 478 ;; now, we can check the next character
12365826 479 (let ((pair (assoc (following-char) recoding-pairs)))
a1506d29 480 (if (null pair)
f23515e1
RS
481 ;; `following-char' is not a Polish character nor it is
482 ;; `prefix-char' since the one is among `recoding-pairs'
a1506d29 483 (forward-char 1)
f23515e1
RS
484 ;; else prefix followed by a Polish character has been found
485 ;; replace it by the corresponding Polish character
12365826
RS
486 (backward-char 1)
487 (delete-char 2)
488 (insert (cdr pair))
f23515e1 489 ;; the region got shorter by one character
12365826
RS
490 (setq end (1- end)))))))))
491
492(defun ogonek-deprefixify-buffer (prefix-char to-encoding)
493 "Call `ogonek-deprefixify-region' on the entire buffer."
494 (interactive (progn (barf-if-buffer-read-only)
a1506d29 495 (list
12365826
RS
496 (ogonek-read-prefix "Prefix character" 'ogonek-prefix-char)
497 (ogonek-read-encoding "To code" 'ogonek-prefix-to-encoding))))
a1506d29 498 (ogonek-deprefixify-region
12365826
RS
499 (point-min) (point-max) prefix-char to-encoding))
500
501(provide 'ogonek)
502
ab5796a9 503;;; arch-tag: 672d7744-28ac-412b-965e-06a27e50d1d7
12365826 504;;; ogonek.el ends here