28 |
;; To use this library load it using |
;; To use this library load it using |
29 |
;; M-x load-library [enter] ogonek |
;; M-x load-library [enter] ogonek |
30 |
;; Then, you may get a short info by calling one of |
;; Then, you may get a short info by calling one of |
31 |
;; M-x ogonek-jak -- in Polish |
;; M-x ogonek-jak -- in Polish |
32 |
;; M-x ogonek-how -- in English " |
;; M-x ogonek-how -- in English " |
33 |
|
|
34 |
;;; Code: |
;;; Code: |
39 |
:group 'i18n) |
:group 'i18n) |
40 |
|
|
41 |
(defconst ogonek-name-encoding-alist |
(defconst ogonek-name-encoding-alist |
42 |
'(("ascii" . (?A ?C ?E ?L ?N ?O ?S ?Z ?Z |
'(("ascii" . (?A ?C ?E ?L ?N ?O ?S ?Z ?Z |
43 |
?a ?c ?e ?l ?n ?o ?s ?z ?z)) |
?a ?c ?e ?l ?n ?o ?s ?z ?z)) |
44 |
("iso8859-2" . (161 198 202 163 209 211 166 172 175 |
("iso8859-2" . (161 198 202 163 209 211 166 172 175 |
45 |
177 230 234 179 241 243 182 188 191)) |
177 230 234 179 241 243 182 188 191)) |
46 |
("mazovia" . (143 149 144 156 165 163 152 160 161 |
("mazovia" . (143 149 144 156 165 163 152 160 161 |
47 |
134 141 145 146 164 162 158 166 167)) |
134 141 145 146 164 162 158 166 167)) |
48 |
("windows-EE" . (165 198 202 163 209 211 140 143 175 |
("windows-EE" . (165 198 202 163 209 211 140 143 175 |
49 |
185 230 234 179 241 243 156 159 191)) |
185 230 234 179 241 243 156 159 191)) |
50 |
("windows-PL" . (165 198 202 163 209 211 140 143 175 |
("windows-PL" . (165 198 202 163 209 211 140 143 175 |
51 |
185 230 234 179 241 243 156 159 191)) |
185 230 234 179 241 243 156 159 191)) |
52 |
("latin-2" . (164 143 168 157 227 224 151 141 189 |
("latin-2" . (164 143 168 157 227 224 151 141 189 |
53 |
165 134 169 136 228 162 152 171 190)) |
165 134 169 136 228 162 152 171 190)) |
54 |
("CP852" . (164 143 168 157 227 224 151 141 189 |
("CP852" . (164 143 168 157 227 224 151 141 189 |
55 |
165 134 169 136 228 162 152 171 190)) |
165 134 169 136 228 162 152 171 190)) |
56 |
("MeX" . (129 130 134 138 139 211 145 153 155 |
("MeX" . (129 130 134 138 139 211 145 153 155 |
57 |
161 162 166 170 171 243 177 185 187)) |
161 162 166 170 171 243 177 185 187)) |
58 |
("CorelDraw" . (197 242 201 163 209 211 255 225 237 |
("CorelDraw" . (197 242 201 163 209 211 255 225 237 |
59 |
229 236 230 198 241 243 165 170 186)) |
229 236 230 198 241 243 165 170 186)) |
60 |
("Amiga" . (194 202 203 206 207 211 212 218 219 |
("Amiga" . (194 202 203 206 207 211 212 218 219 |
61 |
226 234 235 238 239 243 244 250 251)) |
226 234 235 238 239 243 244 250 251)) |
62 |
("Mac" . (132 140 162 252 193 238 229 143 251 |
("Mac" . (132 140 162 252 193 238 229 143 251 |
63 |
136 141 171 184 196 151 230 144 253)) |
136 141 171 184 196 151 230 144 253)) |
64 |
) |
) |
65 |
"The constant `ogonek-name-encoding-alist' is a list of (NAME.LIST) pairs. |
"The constant `ogonek-name-encoding-alist' is a list of (NAME.LIST) pairs. |
66 |
Each LIST contains codes for 18 Polish diacritic characters. The codes |
Each LIST contains codes for 18 Polish diacritic characters. The codes |
67 |
are given in the following order: |
are given in the following order: |
74 |
" FUNKCJE INTERAKCYJNE UDOST/EPNIANE PRZEZ BIBLIOTEK/E `ogonek'. |
" FUNKCJE INTERAKCYJNE UDOST/EPNIANE PRZEZ BIBLIOTEK/E `ogonek'. |
75 |
|
|
76 |
Je/sli czytasz ten tekst, to albo przegl/adasz plik /xr/od/lowy |
Je/sli czytasz ten tekst, to albo przegl/adasz plik /xr/od/lowy |
77 |
biblioteki `ogonek.el', albo wywo/la/le/s polecenie `ogonek-jak'. |
biblioteki `ogonek.el', albo wywo/la/le/s polecenie `ogonek-jak'. |
78 |
W drugim przypadku mo/zesz usun/a/c tekst z ekranu, stosuj/ac |
W drugim przypadku mo/zesz usun/a/c tekst z ekranu, stosuj/ac |
79 |
polecenie `M-x kill-buffer'. |
polecenie `M-x kill-buffer'. |
80 |
|
|
81 |
Niniejsza biblioteka dostarcza funkcji do zmiany kodowania polskich |
Niniejsza biblioteka dostarcza funkcji do zmiany kodowania polskich |
82 |
znak/ow diakrytycznych. Funkcje te mo/zna pogrupowa/c nast/epuj/aco. |
znak/ow diakrytycznych. Funkcje te mo/zna pogrupowa/c nast/epuj/aco. |
83 |
|
|
84 |
1. `ogonek-recode-region' oraz `ogonek-recode-buffer' |
1. `ogonek-recode-region' oraz `ogonek-recode-buffer' |
85 |
przekodowuj/a zaznaczony fragment wzgl/ednie ca/ly buffor. |
przekodowuj/a zaznaczony fragment wzgl/ednie ca/ly buffor. |
86 |
Po wywo/laniu interakcyjnym funkcji zadawane s/a |
Po wywo/laniu interakcyjnym funkcji zadawane s/a |
87 |
pytania o parametry przekodowania: nazw/e kodowania |
pytania o parametry przekodowania: nazw/e kodowania |
88 |
w tek/scie /xr/od/lowym i nazw/e kodowania docelowego. |
w tek/scie /xr/od/lowym i nazw/e kodowania docelowego. |
89 |
Poni/zsze przyk/lady powinny wyja/sni/c, jakich parametr/ow |
Poni/zsze przyk/lady powinny wyja/sni/c, jakich parametr/ow |
90 |
oczekuj/a wymienione funkcje: |
oczekuj/a wymienione funkcje: |
91 |
|
|
92 |
(ogonek-recode-region (poczatek-fragmentu) (koniec-fragmentu) |
(ogonek-recode-region (poczatek-fragmentu) (koniec-fragmentu) |
93 |
nazwa-kodowania-w-tekscie-zrodlowym nazwa-kodowania-docelowa) |
nazwa-kodowania-w-tekscie-zrodlowym nazwa-kodowania-docelowa) |
94 |
(ogonek-recode-buffer |
(ogonek-recode-buffer |
95 |
nazwa-kodowania-w-tekscie-zrodlowym nazwa-kodowania-docelowa) |
nazwa-kodowania-w-tekscie-zrodlowym nazwa-kodowania-docelowa) |
96 |
|
|
97 |
2. `ogonek-prefixify-region' oraz `ogonek-prefixify-buffer' |
2. `ogonek-prefixify-region' oraz `ogonek-prefixify-buffer' |
98 |
s/lu/z/a do wprowadzania notacji prefiksowej. |
s/lu/z/a do wprowadzania notacji prefiksowej. |
99 |
|
|
100 |
(ogonek-prefixify-region (poczatek-fragmentu) (koniec-fragmentu) |
(ogonek-prefixify-region (poczatek-fragmentu) (koniec-fragmentu) |
101 |
nazwa-kodowania-w-tekscie-zrodlowym znak-prefiksu) |
nazwa-kodowania-w-tekscie-zrodlowym znak-prefiksu) |
102 |
(ogonek-prefixify-buffer |
(ogonek-prefixify-buffer |
103 |
nazwa-kodowania-w-tekscie-zrodlowym znak-prefiksu) |
nazwa-kodowania-w-tekscie-zrodlowym znak-prefiksu) |
104 |
|
|
105 |
3. `ogonek-deprefixify-region' oraz `ogonek-deprefixify-buffer' |
3. `ogonek-deprefixify-region' oraz `ogonek-deprefixify-buffer' |
106 |
s/lu/z/a do usuwania notacji prefiksowej. |
s/lu/z/a do usuwania notacji prefiksowej. |
107 |
|
|
108 |
(ogonek-deprefixify-region (poczatek-fragmentu) (koniec-fragmentu) |
(ogonek-deprefixify-region (poczatek-fragmentu) (koniec-fragmentu) |
109 |
znak-prefiksu nazwa-kodowania-docelowa) |
znak-prefiksu nazwa-kodowania-docelowa) |
110 |
(ogonek-prefixify-buffer |
(ogonek-prefixify-buffer |
111 |
znak-prefiksu nazwa-kodowania-docelowa) |
znak-prefiksu nazwa-kodowania-docelowa) |
112 |
|
|
113 |
U/zycie klawisza TAB w trybie interakcyjnym powoduje wy/swietlenie |
U/zycie klawisza TAB w trybie interakcyjnym powoduje wy/swietlenie |
114 |
listy dopuszczalnych nazw kod/ow, pami/etanych w sta/lej |
listy dopuszczalnych nazw kod/ow, pami/etanych w sta/lej |
115 |
`ogonek-name-encoding-alist'. |
`ogonek-name-encoding-alist'. |
116 |
|
|
117 |
Funkcje biblioteki odwo/luj/a si/e do pi/eciu zmiennych, kt/ore |
Funkcje biblioteki odwo/luj/a si/e do pi/eciu zmiennych, kt/ore |
118 |
przechowuj/a podpowiedzi do zadawanych pyta/n. Nazwy tych zmiennych |
przechowuj/a podpowiedzi do zadawanych pyta/n. Nazwy tych zmiennych |
119 |
oraz ich warto/sci domy/slne s/a nast/epuj/ace: |
oraz ich warto/sci domy/slne s/a nast/epuj/ace: |
120 |
|
|
121 |
ogonek-from-encoding iso8859-2 |
ogonek-from-encoding iso8859-2 |
122 |
ogonek-to-encoding ascii |
ogonek-to-encoding ascii |
131 |
(setq ogonek-prefix-to-encoding \"iso8859-2\") |
(setq ogonek-prefix-to-encoding \"iso8859-2\") |
132 |
|
|
133 |
Zamiast wczytywania ca/lej biblioteki `ogonek.el' mo/zna w pliku |
Zamiast wczytywania ca/lej biblioteki `ogonek.el' mo/zna w pliku |
134 |
`~/.emacs' za/z/ada/c wczytania wybranych funkcji, na dodatek dopiero |
`~/.emacs' za/z/ada/c wczytania wybranych funkcji, na dodatek dopiero |
135 |
w chwili ich rzeczywistego u/zycia: |
w chwili ich rzeczywistego u/zycia: |
136 |
|
|
137 |
(autoload 'ogonek-jak \"ogonek\") |
(autoload 'ogonek-jak \"ogonek\") |
147 |
(ogonek-deprefixify-region start end ?/ \"iso8859-2\")) |
(ogonek-deprefixify-region start end ?/ \"iso8859-2\")) |
148 |
(global-set-key \"\\C-cd\" 'deprefixify-iso8859-2-region) ; ctrl-c d |
(global-set-key \"\\C-cd\" 'deprefixify-iso8859-2-region) ; ctrl-c d |
149 |
|
|
150 |
(defun mazovia-to-iso8859-2 (start end) |
(defun mazovia-to-iso8859-2 (start end) |
151 |
(interactive \"*r\") |
(interactive \"*r\") |
152 |
(ogonek-recode-region start end \"mazovia\" \"iso8859-2\")) |
(ogonek-recode-region start end \"mazovia\" \"iso8859-2\")) |
153 |
(global-set-key \"\\C-cr\" 'mazovia-to-iso8859-2) ; ctrl-c r |
(global-set-key \"\\C-cr\" 'mazovia-to-iso8859-2) ; ctrl-c r |
182 |
The functions come in the following groups. |
The functions come in the following groups. |
183 |
|
|
184 |
1. `ogonek-recode-region' and `ogonek-recode-buffer' to change |
1. `ogonek-recode-region' and `ogonek-recode-buffer' to change |
185 |
between one-character encodings, such as `iso-8859-2', `mazovia', |
between one-character encodings, such as `iso-8859-2', `mazovia', |
186 |
plain `ascii' or `TeX'. As the names suggest you may recode |
plain `ascii' or `TeX'. As the names suggest you may recode |
187 |
either the entire current buffer or just a marked region |
either the entire current buffer or just a marked region |
188 |
in it. You may use the functions interactively as commands. |
in it. You may use the functions interactively as commands. |
189 |
Once you call a command you will be asked about the code |
Once you call a command you will be asked about the code |
190 |
currently used in your text and the target encoding, the one |
currently used in your text and the target encoding, the one |
191 |
you want to get. The following example shows a non-interactive |
you want to get. The following example shows a non-interactive |
192 |
use of the functions in a program. This also illustrates what |
use of the functions in a program. This also illustrates what |
193 |
type of parameters the functions expect to be called with: |
type of parameters the functions expect to be called with: |
194 |
|
|
195 |
(ogonek-recode-region |
(ogonek-recode-region |
196 |
(region-beginning) (region-end) from-code-name to-code-name) |
(region-beginning) (region-end) from-code-name to-code-name) |
197 |
(ogonek-recode-buffer from-code-name to-code-name) |
(ogonek-recode-buffer from-code-name to-code-name) |
198 |
|
|
199 |
2. `ogonek-prefixify-region' and `ogonek-prefixify-buffer' for |
2. `ogonek-prefixify-region' and `ogonek-prefixify-buffer' for |
200 |
introducing prefix notation: |
introducing prefix notation: |
201 |
|
|
202 |
(ogonek-prefixify-region |
(ogonek-prefixify-region |
203 |
(region-beginning) (region-end) from-code-name prefix-char) |
(region-beginning) (region-end) from-code-name prefix-char) |
204 |
(ogonek-prefixify-buffer from-code-name prefix-char) |
(ogonek-prefixify-buffer from-code-name prefix-char) |
205 |
|
|
206 |
3. `ogonek-deprefixify-region' and `ogonek-deprefixify-buffer' for |
3. `ogonek-deprefixify-region' and `ogonek-deprefixify-buffer' for |
207 |
removing prefix notation: |
removing prefix notation: |
208 |
|
|
209 |
(ogonek-deprefixify-region |
(ogonek-deprefixify-region |
210 |
(region-beginning) (region-end) prefix-char to-code-name) |
(region-beginning) (region-end) prefix-char to-code-name) |
211 |
(ogonek-prefixify-buffer prefix-char to-code-name) |
(ogonek-prefixify-buffer prefix-char to-code-name) |
212 |
|
|
213 |
The TAB character used in interactive mode makes `emacs' |
The TAB character used in interactive mode makes `emacs' |
214 |
display the list of encodings recognized by the library. The list |
display the list of encodings recognized by the library. The list |
215 |
is stored in the constant `ogonek-name-encoding-alist'. |
is stored in the constant `ogonek-name-encoding-alist'. |
216 |
|
|
217 |
The `ogonek' functions refer to five variables in which the suggested |
The `ogonek' functions refer to five variables in which the suggested |
218 |
answers to dialogue questions are stored. The variables and their |
answers to dialogue questions are stored. The variables and their |
219 |
default values are: |
default values are: |
220 |
|
|
221 |
ogonek-from-encoding iso8859-2 |
ogonek-from-encoding iso8859-2 |
222 |
ogonek-to-encoding ascii |
ogonek-to-encoding ascii |
223 |
ogonek-prefix-char / |
ogonek-prefix-char / |
224 |
ogonek-prefix-from-encoding iso8859-2 |
ogonek-prefix-from-encoding iso8859-2 |
225 |
ogonek-prefix-to-encoding iso8859-2 |
ogonek-prefix-to-encoding iso8859-2 |
226 |
|
|
227 |
The above default values can be changed by placing appropriate settings |
The above default values can be changed by placing appropriate settings |
228 |
in the '~/.emacs' file: |
in the '~/.emacs' file: |
229 |
|
|
230 |
(setq ogonek-prefix-char ?/) |
(setq ogonek-prefix-char ?/) |
246 |
(ogonek-deprefixify-region start end ?/ \"iso8859-2\")) |
(ogonek-deprefixify-region start end ?/ \"iso8859-2\")) |
247 |
(global-set-key \"\\C-cd\" 'deprefixify-iso8859-2-region) ; ctrl-c d |
(global-set-key \"\\C-cd\" 'deprefixify-iso8859-2-region) ; ctrl-c d |
248 |
|
|
249 |
(defun mazovia-to-iso8859-2 (start end) |
(defun mazovia-to-iso8859-2 (start end) |
250 |
(interactive \"*r\") |
(interactive \"*r\") |
251 |
(ogonek-recode-region start end \"mazovia\" \"iso8859-2\")) |
(ogonek-recode-region start end \"mazovia\" \"iso8859-2\")) |
252 |
(global-set-key \"\\C-cr\" 'mazovia-to-iso8859-2) ; ctrl-c r |
(global-set-key \"\\C-cr\" 'mazovia-to-iso8859-2) ; ctrl-c r |
268 |
|
|
269 |
;; ---- Variables keeping the suggested answers to dialogue questions ----- |
;; ---- Variables keeping the suggested answers to dialogue questions ----- |
270 |
(defvar ogonek-encoding-choices |
(defvar ogonek-encoding-choices |
271 |
(cons 'choice |
(cons 'choice |
272 |
(mapcar (lambda (x) (list 'const (car x))) |
(mapcar (lambda (x) (list 'const (car x))) |
273 |
ogonek-name-encoding-alist)) |
ogonek-name-encoding-alist)) |
274 |
"List of ogonek encodings. Used only for customization.") |
"List of ogonek encodings. Used only for customization.") |
299 |
"Read encoding name with completion based on `ogonek-name-encoding-alist'. |
"Read encoding name with completion based on `ogonek-name-encoding-alist'. |
300 |
Store the name in the parameter-variable DEFAULT-NAME-VAR. |
Store the name in the parameter-variable DEFAULT-NAME-VAR. |
301 |
PROMPT is a string to be shown when the user is asked for a name." |
PROMPT is a string to be shown when the user is asked for a name." |
302 |
(let ((encoding |
(let ((encoding |
303 |
(completing-read |
(completing-read |
304 |
(format "%s (default %s): " prompt (eval default-name-var)) |
(format "%s (default %s): " prompt (eval default-name-var)) |
305 |
ogonek-name-encoding-alist nil t))) |
ogonek-name-encoding-alist nil t))) |
306 |
;; change the default name to the one just read |
;; change the default name to the one just read |
307 |
(set default-name-var |
(set default-name-var |
308 |
(if (string= encoding "") (eval default-name-var) encoding)) |
(if (string= encoding "") (eval default-name-var) encoding)) |
309 |
;; return the new default as the name you read |
;; return the new default as the name you read |
310 |
(eval default-name-var))) |
(eval default-name-var))) |
311 |
|
|
312 |
(defun ogonek-read-prefix (prompt default-prefix-var) |
(defun ogonek-read-prefix (prompt default-prefix-var) |
313 |
"Read a prefix character for prefix notation. |
"Read a prefix character for prefix notation. |
314 |
The result is stored in the variable DEFAULT-PREFIX-VAR. |
The result is stored in the variable DEFAULT-PREFIX-VAR. |
315 |
PROMPT is a string to be shown when the user is asked for a new prefix." |
PROMPT is a string to be shown when the user is asked for a new prefix." |
316 |
(let ((prefix-string |
(let ((prefix-string |
317 |
(read-string |
(read-string |
318 |
(format "%s (default %s): " prompt |
(format "%s (default %s): " prompt |
319 |
(char-to-string (eval default-prefix-var)))))) |
(char-to-string (eval default-prefix-var)))))) |
320 |
(if (> (length prefix-string) 1) |
(if (> (length prefix-string) 1) |
321 |
(error "! Only one character expected") |
(error "! Only one character expected") |
322 |
;; set the default prefix character to the one just read |
;; set the default prefix character to the one just read |
323 |
(set default-prefix-var |
(set default-prefix-var |
324 |
(if (string= prefix-string "") |
(if (string= prefix-string "") |
325 |
(eval default-prefix-var) |
(eval default-prefix-var) |
326 |
(string-to-char prefix-string))) |
(string-to-char prefix-string))) |
327 |
;; the new default prefix is the function's result: |
;; the new default prefix is the function's result: |
328 |
(eval default-prefix-var)))) |
(eval default-prefix-var)))) |
329 |
|
|
330 |
(defun ogonek-lookup-encoding (encoding) |
(defun ogonek-lookup-encoding (encoding) |
331 |
"Pick up an association for ENCODING in `ogonek-name-encoding-alist'. |
"Pick up an association for ENCODING in `ogonek-name-encoding-alist'. |
332 |
Before returning a result test whether the string ENCODING is in |
Before returning a result test whether the string ENCODING is in |
333 |
the list `ogonek-name-encoding-alist'" |
the list `ogonek-name-encoding-alist'" |
334 |
(let ((code-list (assoc encoding ogonek-name-encoding-alist))) |
(let ((code-list (assoc encoding ogonek-name-encoding-alist))) |
335 |
(if (null code-list) |
(if (null code-list) |
340 |
;; ---- An auxiliary function for zipping two lists of equal length ---- |
;; ---- An auxiliary function for zipping two lists of equal length ---- |
341 |
|
|
342 |
(defun ogonek-zip-lists (xs ys) |
(defun ogonek-zip-lists (xs ys) |
343 |
"Build a list of pairs from lists XS and YS of the same length." |
"Build a list of pairs from lists XS and YS of the same length." |
344 |
(let ((pairs nil)) |
(let ((pairs nil)) |
345 |
(while xs |
(while xs |
346 |
(setq pairs (cons (cons (car xs) (car ys)) pairs)) |
(setq pairs (cons (cons (car xs) (car ys)) pairs)) |
347 |
(setq xs (cdr xs)) |
(setq xs (cdr xs)) |
351 |
|
|
352 |
;; ---- An auxiliary function building a one-to-one recoding table ----- |
;; ---- An auxiliary function building a one-to-one recoding table ----- |
353 |
|
|
354 |
(defun ogonek-build-table (recoding-pairs) |
(defun ogonek-build-table (recoding-pairs) |
355 |
"Build a table required by Emacs's `translate-region' function. |
"Build a table required by Emacs's `translate-region' function. |
356 |
RECODING-PAIRS is a list of character pairs for which recoding |
RECODING-PAIRS is a list of character pairs for which recoding |
357 |
is not an identity. |
is not an identity. |
358 |
By using the built-in `translate-region' function |
By using the built-in `translate-region' function |
359 |
we gain better performance compared to converting characters |
we gain better performance compared to converting characters |
360 |
by a hand-written routine as it is done for prefix encodings." |
by a hand-written routine as it is done for prefix encodings." |
361 |
(let ((table (make-string 256 0)) |
(let ((table (make-string 256 0)) |
362 |
(i 0)) |
(i 0)) |
363 |
(while (< i 256) |
(while (< i 256) |
364 |
(aset table i i) |
(aset table i i) |
365 |
(setq i (1+ i))) |
(setq i (1+ i))) |
366 |
;; make changes in `table' according to `recoding-pairs' |
;; make changes in `table' according to `recoding-pairs' |
367 |
(while recoding-pairs |
(while recoding-pairs |
372 |
|
|
373 |
;; ---- Commands for one-to-one recoding ------------------------------- |
;; ---- Commands for one-to-one recoding ------------------------------- |
374 |
|
|
375 |
(defun ogonek-recode-region (start end from-encoding to-encoding) |
(defun ogonek-recode-region (start end from-encoding to-encoding) |
376 |
"Recode text in a marked region in one-to-one manner. |
"Recode text in a marked region in one-to-one manner. |
377 |
When called interactively ask the user for the names of the FROM- |
When called interactively ask the user for the names of the FROM- |
378 |
and TO- encodings." |
and TO- encodings." |
379 |
(interactive (progn (barf-if-buffer-read-only) |
(interactive (progn (barf-if-buffer-read-only) |
380 |
(list |
(list |
381 |
(region-beginning) |
(region-beginning) |
382 |
(region-end) |
(region-end) |
383 |
(ogonek-read-encoding "From code" 'ogonek-from-encoding) |
(ogonek-read-encoding "From code" 'ogonek-from-encoding) |
384 |
(ogonek-read-encoding "To code" 'ogonek-to-encoding)))) |
(ogonek-read-encoding "To code" 'ogonek-to-encoding)))) |
385 |
(save-excursion |
(save-excursion |
386 |
(translate-region |
(translate-region |
387 |
start end |
start end |
388 |
(ogonek-build-table |
(ogonek-build-table |
389 |
(ogonek-zip-lists |
(ogonek-zip-lists |
390 |
(ogonek-lookup-encoding from-encoding) |
(ogonek-lookup-encoding from-encoding) |
391 |
(ogonek-lookup-encoding to-encoding)))))) |
(ogonek-lookup-encoding to-encoding)))))) |
392 |
|
|
393 |
(defun ogonek-recode-buffer (from-encoding to-encoding) |
(defun ogonek-recode-buffer (from-encoding to-encoding) |
394 |
"Call `ogonek-recode-region' on the entire buffer. |
"Call `ogonek-recode-region' on the entire buffer. |
395 |
When called interactively ask the user for the names of the FROM- |
When called interactively ask the user for the names of the FROM- |
396 |
and TO- encodings." |
and TO- encodings." |
397 |
(interactive (progn (barf-if-buffer-read-only) |
(interactive (progn (barf-if-buffer-read-only) |
398 |
(list |
(list |
399 |
(ogonek-read-encoding "From code" 'ogonek-from-encoding) |
(ogonek-read-encoding "From code" 'ogonek-from-encoding) |
400 |
(ogonek-read-encoding "To code" 'ogonek-to-encoding)))) |
(ogonek-read-encoding "To code" 'ogonek-to-encoding)))) |
401 |
(ogonek-recode-region |
(ogonek-recode-region |
402 |
(point-min) (point-max) from-encoding to-encoding)) |
(point-min) (point-max) from-encoding to-encoding)) |
403 |
|
|
404 |
;; ---- Recoding with prefix notation ------------------------------- |
;; ---- Recoding with prefix notation ------------------------------- |
405 |
|
|
406 |
(defconst ogonek-prefix-code '(?A ?C ?E ?L ?N ?O ?S ?X ?Z |
(defconst ogonek-prefix-code '(?A ?C ?E ?L ?N ?O ?S ?X ?Z |
407 |
?a ?c ?e ?l ?n ?o ?s ?x ?z)) |
?a ?c ?e ?l ?n ?o ?s ?x ?z)) |
408 |
|
|
409 |
(defun ogonek-prefixify-region (start end from-encoding prefix-char) |
(defun ogonek-prefixify-region (start end from-encoding prefix-char) |
410 |
"In a region, replace FROM-encoded Polish characters with PREFIX pairs. |
"In a region, replace FROM-encoded Polish characters with PREFIX pairs. |
411 |
A PREFIX pair generated consists of PREFIX-CHAR and the respective |
A PREFIX pair generated consists of PREFIX-CHAR and the respective |
412 |
character listed in the `ogonek-prefix-code' constant. |
character listed in the `ogonek-prefix-code' constant. |
413 |
PREFIX-CHAR itself gets doubled." |
PREFIX-CHAR itself gets doubled." |
414 |
(interactive (progn (barf-if-buffer-read-only) |
(interactive (progn (barf-if-buffer-read-only) |
415 |
(list |
(list |
416 |
(region-beginning) |
(region-beginning) |
417 |
(region-end) |
(region-end) |
418 |
(ogonek-read-encoding "From code" 'ogonek-prefix-from-encoding) |
(ogonek-read-encoding "From code" 'ogonek-prefix-from-encoding) |
419 |
(ogonek-read-prefix "Prefix character" 'ogonek-prefix-char)))) |
(ogonek-read-prefix "Prefix character" 'ogonek-prefix-char)))) |
420 |
(let* |
(let* |
421 |
((from-code (ogonek-lookup-encoding from-encoding)) |
((from-code (ogonek-lookup-encoding from-encoding)) |
422 |
(to-code ogonek-prefix-code) |
(to-code ogonek-prefix-code) |
423 |
(recoding-pairs ; `ogonek-prefix-char' added for doubling |
(recoding-pairs ; `ogonek-prefix-char' added for doubling |
424 |
(ogonek-zip-lists |
(ogonek-zip-lists |
425 |
(cons prefix-char from-code) |
(cons prefix-char from-code) |
426 |
(cons prefix-char to-code)))) |
(cons prefix-char to-code)))) |
427 |
(save-excursion |
(save-excursion |
428 |
(goto-char start) |
(goto-char start) |
441 |
(defun ogonek-prefixify-buffer (from-encoding prefix-char) |
(defun ogonek-prefixify-buffer (from-encoding prefix-char) |
442 |
"Call `ogonek-prefixify-region' on the entire buffer." |
"Call `ogonek-prefixify-region' on the entire buffer." |
443 |
(interactive (progn (barf-if-buffer-read-only) |
(interactive (progn (barf-if-buffer-read-only) |
444 |
(list |
(list |
445 |
(ogonek-read-encoding "From code" 'ogonek-prefix-from-encoding) |
(ogonek-read-encoding "From code" 'ogonek-prefix-from-encoding) |
446 |
(ogonek-read-prefix "Prefix character" 'ogonek-prefix-char)))) |
(ogonek-read-prefix "Prefix character" 'ogonek-prefix-char)))) |
447 |
(ogonek-prefixify-region |
(ogonek-prefixify-region |
448 |
(point-min) (point-max) from-encoding prefix-char)) |
(point-min) (point-max) from-encoding prefix-char)) |
449 |
|
|
450 |
(defun ogonek-deprefixify-region (start end prefix-char to-encoding) |
(defun ogonek-deprefixify-region (start end prefix-char to-encoding) |
451 |
"In a region, replace PREFIX pairs with their corresponding TO-encodings. |
"In a region, replace PREFIX pairs with their corresponding TO-encodings. |
452 |
PREFIX-CHAR followed by a Polish character from the `ogonek-prefix-code' |
PREFIX-CHAR followed by a Polish character from the `ogonek-prefix-code' |
453 |
list is replaced with the corresponding TO-encoded character. A doubled |
list is replaced with the corresponding TO-encoded character. A doubled |
454 |
PREFIX-CHAR gets replaced with a single one. A combination of PREFIX-CHAR |
PREFIX-CHAR gets replaced with a single one. A combination of PREFIX-CHAR |
455 |
followed by a non-Polish character, that is one not listed in the |
followed by a non-Polish character, that is one not listed in the |
456 |
`ogonek-prefix-code' constant, is left unchanged." |
`ogonek-prefix-code' constant, is left unchanged." |
457 |
(interactive (progn (barf-if-buffer-read-only) |
(interactive (progn (barf-if-buffer-read-only) |
458 |
(list (region-beginning) |
(list (region-beginning) |
459 |
(region-end) |
(region-end) |
460 |
(ogonek-read-prefix |
(ogonek-read-prefix |
461 |
"Prefix character" 'ogonek-prefix-char) |
"Prefix character" 'ogonek-prefix-char) |
462 |
(ogonek-read-encoding |
(ogonek-read-encoding |
463 |
"To code" 'ogonek-prefix-to-encoding)))) |
"To code" 'ogonek-prefix-to-encoding)))) |
464 |
(let* |
(let* |
465 |
((from-code ogonek-prefix-code) |
((from-code ogonek-prefix-code) |
466 |
(to-code (ogonek-lookup-encoding to-encoding)) |
(to-code (ogonek-lookup-encoding to-encoding)) |
467 |
(recoding-pairs |
(recoding-pairs |
468 |
(ogonek-zip-lists |
(ogonek-zip-lists |
469 |
(cons prefix-char from-code) |
(cons prefix-char from-code) |
470 |
(cons prefix-char to-code)))) |
(cons prefix-char to-code)))) |
471 |
(save-excursion |
(save-excursion |
472 |
(goto-char start) |
(goto-char start) |
477 |
() |
() |
478 |
;; now, we can check the next character |
;; now, we can check the next character |
479 |
(let ((pair (assoc (following-char) recoding-pairs))) |
(let ((pair (assoc (following-char) recoding-pairs))) |
480 |
(if (null pair) |
(if (null pair) |
481 |
;; `following-char' is not a Polish character nor it is |
;; `following-char' is not a Polish character nor it is |
482 |
;; `prefix-char' since the one is among `recoding-pairs' |
;; `prefix-char' since the one is among `recoding-pairs' |
483 |
(forward-char 1) |
(forward-char 1) |
484 |
;; else prefix followed by a Polish character has been found |
;; else prefix followed by a Polish character has been found |
485 |
;; replace it by the corresponding Polish character |
;; replace it by the corresponding Polish character |
486 |
(backward-char 1) |
(backward-char 1) |
492 |
(defun ogonek-deprefixify-buffer (prefix-char to-encoding) |
(defun ogonek-deprefixify-buffer (prefix-char to-encoding) |
493 |
"Call `ogonek-deprefixify-region' on the entire buffer." |
"Call `ogonek-deprefixify-region' on the entire buffer." |
494 |
(interactive (progn (barf-if-buffer-read-only) |
(interactive (progn (barf-if-buffer-read-only) |
495 |
(list |
(list |
496 |
(ogonek-read-prefix "Prefix character" 'ogonek-prefix-char) |
(ogonek-read-prefix "Prefix character" 'ogonek-prefix-char) |
497 |
(ogonek-read-encoding "To code" 'ogonek-prefix-to-encoding)))) |
(ogonek-read-encoding "To code" 'ogonek-prefix-to-encoding)))) |
498 |
(ogonek-deprefixify-region |
(ogonek-deprefixify-region |
499 |
(point-min) (point-max) prefix-char to-encoding)) |
(point-min) (point-max) prefix-char to-encoding)) |
500 |
|
|
501 |
(provide 'ogonek) |
(provide 'ogonek) |