diff options
| -rw-r--r-- | lisp/international/iso-acc.el | 259 |
1 files changed, 160 insertions, 99 deletions
diff --git a/lisp/international/iso-acc.el b/lisp/international/iso-acc.el index ea4f0bcf139..bbd6e5f52e4 100644 --- a/lisp/international/iso-acc.el +++ b/lisp/international/iso-acc.el | |||
| @@ -62,92 +62,74 @@ | |||
| 62 | 62 | ||
| 63 | (provide 'iso-acc) | 63 | (provide 'iso-acc) |
| 64 | 64 | ||
| 65 | (defvar iso-accents-list | 65 | (defvar iso-languages |
| 66 | '(((?' ?A) ?\301) | 66 | '(("portuguese" |
| 67 | ((?' ?E) ?\311) | 67 | (?' ?` ?^ ?\" ?~) |
| 68 | ((?' ?I) ?\315) | 68 | (((?' ?A) ?\301) ((?' ?E) ?\311) ((?' ?I) ?\315) ((?' ?O) ?\323) |
| 69 | ((?' ?O) ?\323) | 69 | ((?' ?U) ?\332) ((?' ?C) ?\307) ((?' ?a) ?\341) ((?' ?e) ?\351) |
| 70 | ((?' ?U) ?\332) | 70 | ((?' ?i) ?\355) ((?' ?o) ?\363) ((?' ?u) ?\372) ((?' ?c) ?\347) |
| 71 | ((?' ?Y) ?\335) | 71 | ((?' ? ) ?') ((?` ?A) ?\300) ((?` ?a) ?\340) ((?` ? ) ?`) |
| 72 | ((?' ?a) ?\341) | 72 | ((?^ ?A) ?\302) ((?^ ?E) ?\312) ((?^ ?O) ?\324) ((?^ ?a) ?\342) |
| 73 | ((?' ?e) ?\351) | 73 | ((?^ ?e) ?\352) ((?^ ?o) ?\364) ((?^ ? ) ?^) ((?\" ?U) ?\334) |
| 74 | ((?' ?i) ?\355) | 74 | ((?\" ?u) ?\374) ((?\" ? ) ?\") ((?\~ ?A) ?\303) ((?\~ ?O) ?\325) |
| 75 | ((?' ?o) ?\363) | 75 | ((?\~ ?a) ?\343) ((?\~ ?o) ?\365) ((?\~ ?\ ) ?\~))) |
| 76 | ((?' ?u) ?\372) | 76 | ("french" |
| 77 | ((?' ?y) ?\375) | 77 | (?' ?` ?^ ?\" ?~) |
| 78 | ((?' ?') ?\264) | 78 | (((?' ?A) ?\301) ((?' ?E) ?\311) ((?' ?I) ?\315) ((?' ?O) ?\323) |
| 79 | ((?' ? ) ?') | 79 | ((?' ?U) ?\332) ((?' ?C) ?\307) ((?' ?a) ?\341) ((?' ?e) ?\351) |
| 80 | ((?` ?A) ?\300) | 80 | ((?' ?i) ?\355) ((?' ?o) ?\363) ((?' ?u) ?\372) ((?' ?c) ?\347) |
| 81 | ((?` ?E) ?\310) | 81 | ((?' ? ) ?') ((?` ?A) ?\300) ((?` ?E) ?\310) ((?` ?a) ?\340) |
| 82 | ((?` ?I) ?\314) | 82 | ((?` ?e) ?\350) ((?` ? ) ?`) ((?^ ?A) ?\302) ((?^ ?E) ?\312) |
| 83 | ((?` ?O) ?\322) | 83 | ((?^ ?I) ?\316) ((?^ ?O) ?\324) ((?^ ?U) ?\333) ((?^ ?a) ?\342) |
| 84 | ((?` ?U) ?\331) | 84 | ((?^ ?e) ?\352) ((?^ ?i) ?\356) ((?^ ?o) ?\364) ((?^ ?u) ?\373) |
| 85 | ((?` ?a) ?\340) | 85 | ((?^ ? ) ?^) ((?\" ?U) ?\334) ((?\" ?u) ?\374) ((?\" ? ) ?\") |
| 86 | ((?` ?e) ?\350) | 86 | ((?\~ ?A) ?\303) ((?\~ ?O) ?\325) ((?\~ ?a) ?\343) ((?\~ ?o) ?\365) |
| 87 | ((?` ?i) ?\354) | 87 | ((?\~ ?\ ) ?\~))) |
| 88 | ((?` ?o) ?\362) | 88 | ("default" |
| 89 | ((?` ?u) ?\371) | 89 | (?' ?` ?^ ?\" ?~ ?/) |
| 90 | ((?` ? ) ?`) | 90 | (((?' ?A) ?\301) ((?' ?E) ?\311) ((?' ?I) ?\315) ((?' ?O) ?\323) |
| 91 | ((?` ?`) ?`) ; no special code? | 91 | ((?' ?U) ?\332) ((?' ?Y) ?\335) ((?' ?a) ?\341) ((?' ?e) ?\351) |
| 92 | ((?^ ?A) ?\302) | 92 | ((?' ?i) ?\355) ((?' ?o) ?\363) ((?' ?u) ?\372) ((?' ?y) ?\375) |
| 93 | ((?^ ?E) ?\312) | 93 | ((?' ?') ?\264) ((?' ? ) ?') ((?` ?A) ?\300) ((?` ?E) ?\310) |
| 94 | ((?^ ?I) ?\316) | 94 | ((?` ?I) ?\314) ((?` ?O) ?\322) ((?` ?U) ?\331) ((?` ?a) ?\340) |
| 95 | ((?^ ?O) ?\324) | 95 | ((?` ?e) ?\350) ((?` ?i) ?\354) ((?` ?o) ?\362) ((?` ?u) ?\371) |
| 96 | ((?^ ?U) ?\333) | 96 | ((?` ? ) ?`) ((?` ?`) ?`) ((?^ ?A) ?\302) ((?^ ?E) ?\312) |
| 97 | ((?^ ?a) ?\342) | 97 | ((?^ ?I) ?\316) ((?^ ?O) ?\324) ((?^ ?U) ?\333) ((?^ ?a) ?\342) |
| 98 | ((?^ ?e) ?\352) | 98 | ((?^ ?e) ?\352) ((?^ ?i) ?\356) ((?^ ?o) ?\364) ((?^ ?u) ?\373) |
| 99 | ((?^ ?i) ?\356) | 99 | ((?^ ? ) ?^) ((?^ ?^) ?^) ((?\" ?A) ?\304) ((?\" ?E) ?\313) |
| 100 | ((?^ ?o) ?\364) | 100 | ((?\" ?I) ?\317) ((?\" ?O) ?\326) ((?\" ?U) ?\334) ((?\" ?a) ?\344) |
| 101 | ((?^ ?u) ?\373) | 101 | ((?\" ?e) ?\353) ((?\" ?i) ?\357) ((?\" ?o) ?\366) ((?\" ?s) ?\337) |
| 102 | ((?^ ? ) ?^) | 102 | ((?\" ?u) ?\374) ((?\" ?y) ?\377) ((?\" ? ) ?\") ((?\" ?\") ?\250) |
| 103 | ((?^ ?^) ?^) ; no special code? | 103 | ((?\~ ?A) ?\303) ((?\~ ?C) ?\307) ((?\~ ?D) ?\320) ((?\~ ?N) ?\321) |
| 104 | ((?\" ?A) ?\304) | 104 | ((?\~ ?O) ?\325) ((?\~ ?T) ?\336) ((?\~ ?a) ?\343) ((?\~ ?c) ?\347) |
| 105 | ((?\" ?E) ?\313) | 105 | ((?\~ ?d) ?\360) ((?\~ ?n) ?\361) ((?\~ ?o) ?\365) ((?\~ ?t) ?\376) |
| 106 | ((?\" ?I) ?\317) | 106 | ((?\~ ?>) ?\273) ((?\~ ?<) ?\253) ((?\~ ?\ ) ?\~) ((?\~ ?\~) ?\270) |
| 107 | ((?\" ?O) ?\326) | 107 | ((?\/ ?A) ?\305) ((?\/ ?E) ?\306) ((?\/ ?O) ?\330) ((?\/ ?a) ?\345) |
| 108 | ((?\" ?U) ?\334) | 108 | ((?\/ ?e) ?\346) ((?\/ ?o) ?\370) ((?\/ ?\ ) ?\/) ((?\/ ?\/) ?\260)))) |
| 109 | ((?\" ?a) ?\344) | 109 | |
| 110 | ((?\" ?e) ?\353) | 110 | "List of language-specific customizations for the ISO Accents mode. |
| 111 | ((?\" ?i) ?\357) | 111 | |
| 112 | ((?\" ?o) ?\366) | 112 | Each element of the list is of the form (LANGUAGE ENABLE LIST). |
| 113 | ((?\" ?s) ?\337) | 113 | |
| 114 | ((?\" ?u) ?\374) | 114 | LANGUAGE is a string naming the language. |
| 115 | ((?\" ?y) ?\377) | 115 | |
| 116 | ((?\" ? ) ?\") | 116 | ENABLE is a list of characters that will be used as accent prefixes. |
| 117 | ((?\" ?\") ?\250) | 117 | It will be the value of the iso-accents-enable variable. |
| 118 | ((?\~ ?A) ?\303) | 118 | |
| 119 | ((?\~ ?C) ?\307) | 119 | LIST is a list of accent translations. It will be the value of the |
| 120 | ((?\~ ?D) ?\320) | 120 | iso-accents-list variable.") |
| 121 | ((?\~ ?N) ?\321) | 121 | |
| 122 | ((?\~ ?O) ?\325) | 122 | (defvar iso-language nil |
| 123 | ((?\~ ?T) ?\336) | 123 | "Language for which ISO Accents mode is currently customized. |
| 124 | ((?\~ ?a) ?\343) | 124 | Change it with the `iso-accents-customize' function.") |
| 125 | ((?\~ ?c) ?\347) | 125 | |
| 126 | ((?\~ ?d) ?\360) | 126 | (defvar iso-accents-list nil |
| 127 | ((?\~ ?n) ?\361) | 127 | "Association list for ISO accent combinations, for the chosen language.") |
| 128 | ((?\~ ?o) ?\365) | ||
| 129 | ((?\~ ?t) ?\376) | ||
| 130 | ((?\~ ?>) ?\273) | ||
| 131 | ((?\~ ?<) ?\253) | ||
| 132 | ((?\~ ?!) ?\241) ;; Inverted exclamation mark | ||
| 133 | ((?\~ ??) ?\277) ;; Inverted question mark | ||
| 134 | ((?\~ ?\ ) ?\~) | ||
| 135 | ((?\~ ?\~) ?\270) ;; cedilla accent | ||
| 136 | ((?\/ ?A) ?\305) ;; A-with-ring (Norwegian and Danish) | ||
| 137 | ((?\/ ?E) ?\306) ;; AE-ligature (Norwegian and Danish) | ||
| 138 | ((?\/ ?O) ?\330) | ||
| 139 | ((?\/ ?a) ?\345) ;; a-with-ring (Norwegian and Danish) | ||
| 140 | ((?\/ ?e) ?\346) ;; ae-ligature (Norwegian and Danish) | ||
| 141 | ((?\/ ?o) ?\370) | ||
| 142 | ((?\/ ?\ ) ?\/) | ||
| 143 | ((?\/ ?\/) ?\260) ;; ring accent (actually degree sign?) | ||
| 144 | ) | ||
| 145 | "Association list for ISO accent combinations.") | ||
| 146 | 128 | ||
| 147 | (defvar iso-accents-mode nil | 129 | (defvar iso-accents-mode nil |
| 148 | "*Non-nil enables ISO Accents mode. | 130 | "*Non-nil enables ISO Accents mode. |
| 149 | Setting this variable makes it local to the current buffer. | 131 | Setting this variable makes it local to the current buffer. |
| 150 | See function `iso-accents-mode'.") | 132 | See the function `iso-accents-mode'.") |
| 151 | (make-variable-buffer-local 'iso-accents-mode) | 133 | (make-variable-buffer-local 'iso-accents-mode) |
| 152 | 134 | ||
| 153 | (defun iso-accents-accent-key (prompt) | 135 | (defun iso-accents-accent-key (prompt) |
| @@ -191,28 +173,12 @@ See function `iso-accents-mode'.") | |||
| 191 | (setq unread-command-events (list second-char)) | 173 | (setq unread-command-events (list second-char)) |
| 192 | (vector first-char)))) | 174 | (vector first-char)))) |
| 193 | 175 | ||
| 194 | (defvar iso-accents-enable '(?' ?` ?^ ?\" ?~ ?/) | 176 | (defvar iso-accents-enable nil |
| 195 | "*List of accent keys that become prefixes in ISO Accents mode. | 177 | "*List of accent keys that become prefixes in ISO Accents mode. |
| 196 | The default is (?' ?` ?^ ?\" ?~ ?/), which contains all the supported | 178 | The default is (?' ?` ?^ ?\" ?~ ?/), which contains all the supported |
| 197 | accent keys. For certain languages, you might want to remove some of | 179 | accent keys. For certain languages, you might want to remove some of |
| 198 | those characters that are not actually used.") | 180 | those characters that are not actually used.") |
| 199 | 181 | ||
| 200 | (or key-translation-map (setq key-translation-map (make-sparse-keymap))) | ||
| 201 | ;; For sequences starting with an accent character, | ||
| 202 | ;; use a function that tests iso-accents-mode. | ||
| 203 | (if (memq ?' iso-accents-enable) | ||
| 204 | (define-key key-translation-map "'" 'iso-accents-accent-key)) | ||
| 205 | (if (memq ?` iso-accents-enable) | ||
| 206 | (define-key key-translation-map "`" 'iso-accents-accent-key)) | ||
| 207 | (if (memq ?^ iso-accents-enable) | ||
| 208 | (define-key key-translation-map "^" 'iso-accents-accent-key)) | ||
| 209 | (if (memq ?\" iso-accents-enable) | ||
| 210 | (define-key key-translation-map "\"" 'iso-accents-accent-key)) | ||
| 211 | (if (memq ?~ iso-accents-enable) | ||
| 212 | (define-key key-translation-map "~" 'iso-accents-accent-key)) | ||
| 213 | (if (memq ?/ iso-accents-enable) | ||
| 214 | (define-key key-translation-map "/" 'iso-accents-accent-key)) | ||
| 215 | |||
| 216 | ;; It is a matter of taste if you want the minor mode indicated | 182 | ;; It is a matter of taste if you want the minor mode indicated |
| 217 | ;; in the mode line... | 183 | ;; in the mode line... |
| 218 | ;; If so, uncomment the next four lines. | 184 | ;; If so, uncomment the next four lines. |
| @@ -258,4 +224,99 @@ and a negative argument disables it." | |||
| 258 | ;; Enable electric accents. | 224 | ;; Enable electric accents. |
| 259 | (setq iso-accents-mode t))) | 225 | (setq iso-accents-mode t))) |
| 260 | 226 | ||
| 227 | (defun iso-accents-customize (language) | ||
| 228 | "Customize the ISO accents machinery for a particular language. | ||
| 229 | It selects the customization based on the specifications in the | ||
| 230 | `iso-languages' variable." | ||
| 231 | (interactive (list (completing-read "Language: " iso-languages nil t))) | ||
| 232 | (let ((table (assoc language iso-languages)) | ||
| 233 | c) | ||
| 234 | (if (not table) | ||
| 235 | (error "Unknown language") | ||
| 236 | (setq iso-language language) | ||
| 237 | (setq iso-accents-enable (car (cdr table))) | ||
| 238 | (setq iso-accents-list (car (cdr (cdr table)))) | ||
| 239 | (if key-translation-map | ||
| 240 | (substitute-key-definition | ||
| 241 | 'iso-accents-accent-key nil key-translation-map) | ||
| 242 | (setq key-translation-map (make-sparse-keymap))) | ||
| 243 | (setq c iso-accents-enable) | ||
| 244 | (while c | ||
| 245 | (define-key | ||
| 246 | key-translation-map (char-to-string (car c)) 'iso-accents-accent-key) | ||
| 247 | (setq c (cdr c)))))) | ||
| 248 | |||
| 249 | (defun iso-accentuate (start end) | ||
| 250 | "Convert two-character sequences in region into accented characters. | ||
| 251 | Noninteractively, this operates on text from START to END. | ||
| 252 | This uses the same conversion that ISO Accents mode uses for type-in." | ||
| 253 | (interactive "r") | ||
| 254 | (save-excursion | ||
| 255 | (save-restriction | ||
| 256 | (narrow-to-region start end) | ||
| 257 | (goto-char start) | ||
| 258 | (forward-char 1) | ||
| 259 | (let (entry) | ||
| 260 | (while (< (point) end) | ||
| 261 | (if (and (memq (preceding-char) iso-accents-enable) | ||
| 262 | (<= ?A (following-char)) | ||
| 263 | (<= (following-char) ?z) | ||
| 264 | (setq entry (assoc (list (preceding-char) (following-char)) | ||
| 265 | iso-accents-list))) | ||
| 266 | (progn | ||
| 267 | (forward-char -1) | ||
| 268 | (delete-char 2) | ||
| 269 | (insert (car (cdr entry))) | ||
| 270 | (setq end (1- end))) | ||
| 271 | (forward-char 1))))))) | ||
| 272 | |||
| 273 | (defun iso-accent-rassoc-unit (value alist) | ||
| 274 | (while (and alist | ||
| 275 | (not (eq (car (cdr (car alist))) value))) | ||
| 276 | (setq alist (cdr alist))) | ||
| 277 | (if alist | ||
| 278 | (car alist) | ||
| 279 | nil)) | ||
| 280 | |||
| 281 | (defun iso-unaccentuate (start end) | ||
| 282 | "Convert accented characters in the region into two-character sequences. | ||
| 283 | Noninteractively, this operates on text from START to END. | ||
| 284 | This uses the opposite of the conversion done by ISO Accents mode for type-in." | ||
| 285 | (interactive "r") | ||
| 286 | (save-excursion | ||
| 287 | (save-restriction | ||
| 288 | (narrow-to-region start end) | ||
| 289 | (goto-char start) | ||
| 290 | (let (entry) | ||
| 291 | (while (< (point) end) | ||
| 292 | (if (and (> (following-char) 127) | ||
| 293 | (setq entry (iso-accent-rassoc-unit (following-char) | ||
| 294 | iso-accents-list))) | ||
| 295 | (progn | ||
| 296 | (delete-char 1) | ||
| 297 | (insert (car (car entry)) (car (cdr (car entry)))) | ||
| 298 | (setq end (1+ end))) | ||
| 299 | (forward-char 1))))))) | ||
| 300 | |||
| 301 | (defun iso-deaccentuate (start end) | ||
| 302 | "Convert accented characters in the region into unaccented characters. | ||
| 303 | Noninteractively, this operates on text from START to END." | ||
| 304 | (interactive "r") | ||
| 305 | (save-excursion | ||
| 306 | (save-restriction | ||
| 307 | (narrow-to-region start end) | ||
| 308 | (goto-char start) | ||
| 309 | (let (entry) | ||
| 310 | (while (< (point) end) | ||
| 311 | (if (and (> (following-char) 127) | ||
| 312 | (setq entry (iso-accent-rassoc-unit (following-char) | ||
| 313 | iso-accents-list))) | ||
| 314 | (progn | ||
| 315 | (delete-char 1) | ||
| 316 | (insert (car (cdr (car entry))))) | ||
| 317 | (forward-char 1))))))) | ||
| 318 | |||
| 319 | (iso-customize-accents "default") | ||
| 320 | |||
| 261 | ;;; iso-acc.el ends here | 321 | ;;; iso-acc.el ends here |
| 322 | |||