comparison lisp/international/mule-cmds.el @ 83131:24e9d5ea9a88

Use the remote locale for terminal & keyboard coding system. lisp/international/mule-cmds.el (set-locale-translation-file-name) (get-locale-real-name, get-locale-coding-system) (configure-display-for-locale): New functions. (set-locale-environment): Factored contents into separate functions. lisp/server.el (server-process-filter): Call configure-display-for-locale after creating a new terminal frame. lisp/startup.el (command-line): Call set-locale-translation-file-name. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-171
author Karoly Lorentey <lorentey@elte.hu>
date Sun, 23 May 2004 03:56:10 +0000
parents b545019c77b0
children 72439f0b5650
comparison
equal deleted inserted replaced
83130:20f9fa3c5131 83131:24e9d5ea9a88
2289 (if (locale-charset-match-p charset (caar cs)) 2289 (if (locale-charset-match-p charset (caar cs))
2290 (setq c (intern (caar cs))) 2290 (setq c (intern (caar cs)))
2291 (pop cs))) 2291 (pop cs)))
2292 (if c (coding-system-base c))))) 2292 (if c (coding-system-base c)))))
2293 2293
2294 ;; Fixme: This ought to deal with the territory part of the locale 2294 (defun set-locale-translation-file-name ()
2295 ;; too, for setting things such as calendar holidays, ps-print paper 2295 "Set up the locale-translation-file-name on the current system.
2296 ;; size, spelling dictionary. 2296
2297 2297 This needs to be done at runtime for the sake of binaries
2298 (defun set-locale-environment (&optional locale-name) 2298 possibly transported to a system without X."
2299 "Set up multi-lingual environment for using LOCALE-NAME.
2300 This sets the language environment, the coding system priority,
2301 the default input method and sometimes other things.
2302
2303 LOCALE-NAME should be a string which is the name of a locale supported
2304 by the system. Often it is of the form xx_XX.CODE, where xx is a
2305 language, XX is a country, and CODE specifies a character set and
2306 coding system. For example, the locale name \"ja_JP.EUC\" might name
2307 a locale for Japanese in Japan using the `japanese-iso-8bit'
2308 coding-system. The name may also have a modifier suffix, e.g. `@euro'
2309 or `@cyrillic'.
2310
2311 If LOCALE-NAME is nil, its value is taken from the environment
2312 variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
2313
2314 The locale names supported by your system can typically be found in a
2315 directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
2316 will be translated according to the table specified by
2317 `locale-translation-file-name'.
2318
2319 See also `locale-charset-language-names', `locale-language-names',
2320 `locale-preferred-coding-systems' and `locale-coding-system'."
2321 (interactive "sSet environment for locale: ")
2322
2323 ;; Do this at runtime for the sake of binaries possibly transported
2324 ;; to a system without X.
2325 (setq locale-translation-file-name 2299 (setq locale-translation-file-name
2326 (let ((files 2300 (let ((files
2327 '("/usr/lib/X11/locale/locale.alias" ; e.g. X11R6.4 2301 '("/usr/lib/X11/locale/locale.alias" ; e.g. X11R6.4
2328 "/usr/X11R6/lib/X11/locale/locale.alias" ; XFree86, e.g. RedHat 4.2 2302 "/usr/X11R6/lib/X11/locale/locale.alias" ; XFree86, e.g. RedHat 4.2
2329 "/usr/openwin/lib/locale/locale.alias" ; e.g. Solaris 2.6 2303 "/usr/openwin/lib/locale/locale.alias" ; e.g. Solaris 2.6
2332 ;; since the X-related names are what X actually uses. 2306 ;; since the X-related names are what X actually uses.
2333 "/usr/share/locale/locale.alias" ; GNU/Linux sans X 2307 "/usr/share/locale/locale.alias" ; GNU/Linux sans X
2334 ))) 2308 )))
2335 (while (and files (not (file-exists-p (car files)))) 2309 (while (and files (not (file-exists-p (car files))))
2336 (setq files (cdr files))) 2310 (setq files (cdr files)))
2337 (car files))) 2311 (car files))))
2338 2312
2339 (let ((locale locale-name)) 2313 (defun get-locale-real-name (&optional locale-name)
2340 2314 "Return the canonicalized name of locale LOCALE-NAME.
2341 (unless locale 2315
2342 ;; Use the first of these three environment variables 2316 LOCALE-NAME should be a string which is the name of a locale supported
2343 ;; that has a nonempty value. 2317 by the system. Often it is of the form xx_XX.CODE, where xx is a
2344 (let ((vars '("LC_ALL" "LC_CTYPE" "LANG"))) 2318 language, XX is a country, and CODE specifies a character set and
2345 (while (and vars 2319 coding system. For example, the locale name \"ja_JP.EUC\" might name
2346 (= 0 (length locale))) ; nil or empty string 2320 a locale for Japanese in Japan using the `japanese-iso-8bit'
2347 (setq locale (getenv (pop vars)))))) 2321 coding-system. The name may also have a modifier suffix, e.g. `@euro'
2348 2322 or `@cyrillic'.
2349 (when locale 2323
2350 2324 If LOCALE-NAME is nil, its value is taken from the environment
2325 variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
2326 On server frames, the environment of the emacsclient process is
2327 used.
2328
2329 See also `set-locale-environment'."
2330 (unless locale-name
2331 ;; Use the first of these three environment variables
2332 ;; that has a nonempty value.
2333 (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
2334 (while (and vars
2335 (= 0 (length locale-name))) ; nil or empty string
2336 (setq locale-name (server-getenv (pop vars))))))
2337
2338 (when locale-name
2351 ;; Translate "swedish" into "sv_SE.ISO8859-1", and so on, 2339 ;; Translate "swedish" into "sv_SE.ISO8859-1", and so on,
2352 ;; using the translation file that many systems have. 2340 ;; using the translation file that many systems have.
2353 (when locale-translation-file-name 2341 (when locale-translation-file-name
2354 (with-temp-buffer 2342 (with-temp-buffer
2355 (insert-file-contents locale-translation-file-name) 2343 (insert-file-contents locale-translation-file-name)
2356 (when (re-search-forward 2344 (when (re-search-forward
2357 (concat "^" (regexp-quote locale) ":?[ \t]+") nil t) 2345 (concat "^" (regexp-quote locale-name) ":?[ \t]+") nil t)
2358 (setq locale (buffer-substring (point) (line-end-position)))))) 2346 (setq locale-name (buffer-substring (point) (line-end-position)))))))
2347 locale-name)
2348
2349 (defun get-locale-coding-system (&optional locale)
2350 "Return the coding system corresponding to locale LOCALE."
2351 (setq locale (or locale (get-locale-real-name nil)))
2352 (when locale
2353 (or (locale-name-match locale locale-preferred-coding-systems)
2354 (when locale
2355 (if (string-match "\\.\\([^@]+\\)" locale)
2356 (locale-charset-to-coding-system
2357 (match-string 1 locale)))))))
2358
2359 (defun configure-display-for-locale (&optional locale)
2360 "Set up terminal for locale LOCALE.
2361
2362 The display table, the terminal coding system and the keyboard
2363 coding system of the current display device are set up for the
2364 given locale."
2365 (setq locale (or locale (get-locale-real-name nil)))
2366
2367 (when locale
2368 (let ((language-name
2369 (locale-name-match locale locale-language-names))
2370 (charset-language-name
2371 (locale-name-match locale locale-charset-language-names))
2372 (coding-system
2373 (get-locale-coding-system locale)))
2374
2375 ;; Give preference to charset-language-name over language-name.
2376 (if (and charset-language-name
2377 (not
2378 (equal (get-language-info language-name 'charset)
2379 (get-language-info charset-language-name 'charset))))
2380 (setq language-name charset-language-name))
2381
2382 (when language-name
2383
2384 ;; If default-enable-multibyte-characters is nil,
2385 ;; we are using single-byte characters,
2386 ;; so the display table and terminal coding system are irrelevant.
2387 (when default-enable-multibyte-characters
2388 (set-display-table-and-terminal-coding-system language-name))
2389
2390 ;; Set the `keyboard-coding-system' if appropriate (tty
2391 ;; only). At least X and MS Windows can generate
2392 ;; multilingual input.
2393 (unless window-system
2394 (let ((kcs (or coding-system
2395 (car (get-language-info language-name
2396 'coding-system)))))
2397 (if kcs (set-keyboard-coding-system kcs))))))))
2398
2399 ;; Fixme: This ought to deal with the territory part of the locale
2400 ;; too, for setting things such as calendar holidays, ps-print paper
2401 ;; size, spelling dictionary.
2402
2403 (defun set-locale-environment (&optional locale-name)
2404 "Set up multi-lingual environment for using LOCALE-NAME.
2405 This sets the language environment, the coding system priority,
2406 the default input method and sometimes other things.
2407
2408 LOCALE-NAME should be a string which is the name of a locale supported
2409 by the system. Often it is of the form xx_XX.CODE, where xx is a
2410 language, XX is a country, and CODE specifies a character set and
2411 coding system. For example, the locale name \"ja_JP.EUC\" might name
2412 a locale for Japanese in Japan using the `japanese-iso-8bit'
2413 coding-system. The name may also have a modifier suffix, e.g. `@euro'
2414 or `@cyrillic'.
2415
2416 If LOCALE-NAME is nil, its value is taken from the environment
2417 variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
2418 On server frames, the environment of the emacsclient process is
2419 used.
2420
2421 The locale names supported by your system can typically be found in a
2422 directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
2423 will be translated according to the table specified by
2424 `locale-translation-file-name'.
2425
2426 See also `locale-charset-language-names', `locale-language-names',
2427 `locale-preferred-coding-systems' and `locale-coding-system'."
2428 (interactive "sSet environment for locale: ")
2429
2430 (let ((locale (get-locale-real-name locale-name)))
2431
2432 (when locale
2359 2433
2360 ;; Leave the system locales alone if the caller did not specify 2434 ;; Leave the system locales alone if the caller did not specify
2361 ;; an explicit locale name, as their defaults are set from 2435 ;; an explicit locale name, as their defaults are set from
2362 ;; LC_MESSAGES and LC_TIME, not LC_CTYPE, and the user might not 2436 ;; LC_MESSAGES and LC_TIME, not LC_CTYPE, and the user might not
2363 ;; want to set them to the same value as LC_CTYPE. 2437 ;; want to set them to the same value as LC_CTYPE.
2365 (setq system-messages-locale locale) 2439 (setq system-messages-locale locale)
2366 (setq system-time-locale locale)) 2440 (setq system-time-locale locale))
2367 2441
2368 (setq locale (downcase locale)) 2442 (setq locale (downcase locale))
2369 2443
2444 (configure-display-for-locale locale)
2445
2370 (let ((language-name 2446 (let ((language-name
2371 (locale-name-match locale locale-language-names)) 2447 (locale-name-match locale locale-language-names))
2372 (charset-language-name 2448 (charset-language-name
2373 (locale-name-match locale locale-charset-language-names)) 2449 (locale-name-match locale locale-charset-language-names))
2374 (coding-system 2450 (coding-system
2375 (or (locale-name-match locale locale-preferred-coding-systems) 2451 (get-locale-coding-system locale)))
2376 (when locale
2377 (if (string-match "\\.\\([^@]+\\)" locale)
2378 (locale-charset-to-coding-system
2379 (match-string 1 locale)))))))
2380 2452
2381 ;; Give preference to charset-language-name over language-name. 2453 ;; Give preference to charset-language-name over language-name.
2382 (if (and charset-language-name 2454 (if (and charset-language-name
2383 (not 2455 (not
2384 (equal (get-language-info language-name 'charset) 2456 (equal (get-language-info language-name 'charset)
2388 (when language-name 2460 (when language-name
2389 2461
2390 ;; Set up for this character set. This is now the right way 2462 ;; Set up for this character set. This is now the right way
2391 ;; to do it for both unibyte and multibyte modes. 2463 ;; to do it for both unibyte and multibyte modes.
2392 (set-language-environment language-name) 2464 (set-language-environment language-name)
2393
2394 ;; If default-enable-multibyte-characters is nil,
2395 ;; we are using single-byte characters,
2396 ;; so the display table and terminal coding system are irrelevant.
2397 (when default-enable-multibyte-characters
2398 (set-display-table-and-terminal-coding-system language-name))
2399
2400 ;; Set the `keyboard-coding-system' if appropriate (tty
2401 ;; only). At least X and MS Windows can generate
2402 ;; multilingual input.
2403 (unless (or window-system
2404 keyboard-coding-system)
2405 ;; FIXME: keyboard-coding-system must be removed from the above
2406 ;; condition when multi-tty locale handling is correctly
2407 ;; implemented. Also, unconditionally overriding it with nil
2408 ;; is not a good idea, as it ignores the user's
2409 ;; customization. -- lorentey
2410 (let ((kcs (or coding-system
2411 (car (get-language-info language-name
2412 'coding-system)))))
2413 (if kcs (set-keyboard-coding-system kcs))))
2414 2465
2415 (setq locale-coding-system 2466 (setq locale-coding-system
2416 (car (get-language-info language-name 'coding-priority)))) 2467 (car (get-language-info language-name 'coding-priority))))
2417 2468
2418 (when coding-system 2469 (when coding-system