aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaroly Lorentey2004-05-23 03:56:10 +0000
committerKaroly Lorentey2004-05-23 03:56:10 +0000
commit14de9163b46dbdaaf75e3caf617f69c1956d024b (patch)
tree8d5102414965649964e47334dbc71816108fa648
parent44070fdf1af9b9fd6e5ada81759c9dc749a05ab7 (diff)
downloademacs-14de9163b46dbdaaf75e3caf617f69c1956d024b.tar.gz
emacs-14de9163b46dbdaaf75e3caf617f69c1956d024b.zip
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
-rw-r--r--lisp/international/mule-cmds.el171
-rw-r--r--lisp/server.el2
-rw-r--r--lisp/startup.el2
3 files changed, 115 insertions, 60 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index d8683b53ec9..7aed6a95e7c 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -2291,6 +2291,111 @@ is returned. Thus, for instance, if charset \"ISO8859-2\",
2291 (pop cs))) 2291 (pop cs)))
2292 (if c (coding-system-base c))))) 2292 (if c (coding-system-base c)))))
2293 2293
2294(defun set-locale-translation-file-name ()
2295 "Set up the locale-translation-file-name on the current system.
2296
2297This needs to be done at runtime for the sake of binaries
2298possibly transported to a system without X."
2299 (setq locale-translation-file-name
2300 (let ((files
2301 '("/usr/lib/X11/locale/locale.alias" ; e.g. X11R6.4
2302 "/usr/X11R6/lib/X11/locale/locale.alias" ; XFree86, e.g. RedHat 4.2
2303 "/usr/openwin/lib/locale/locale.alias" ; e.g. Solaris 2.6
2304 ;;
2305 ;; The following name appears after the X-related names above,
2306 ;; since the X-related names are what X actually uses.
2307 "/usr/share/locale/locale.alias" ; GNU/Linux sans X
2308 )))
2309 (while (and files (not (file-exists-p (car files))))
2310 (setq files (cdr files)))
2311 (car files))))
2312
2313(defun get-locale-real-name (&optional locale-name)
2314 "Return the canonicalized name of locale LOCALE-NAME.
2315
2316LOCALE-NAME should be a string which is the name of a locale supported
2317by the system. Often it is of the form xx_XX.CODE, where xx is a
2318language, XX is a country, and CODE specifies a character set and
2319coding system. For example, the locale name \"ja_JP.EUC\" might name
2320a locale for Japanese in Japan using the `japanese-iso-8bit'
2321coding-system. The name may also have a modifier suffix, e.g. `@euro'
2322or `@cyrillic'.
2323
2324If LOCALE-NAME is nil, its value is taken from the environment
2325variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
2326On server frames, the environment of the emacsclient process is
2327used.
2328
2329See 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
2339 ;; Translate "swedish" into "sv_SE.ISO8859-1", and so on,
2340 ;; using the translation file that many systems have.
2341 (when locale-translation-file-name
2342 (with-temp-buffer
2343 (insert-file-contents locale-translation-file-name)
2344 (when (re-search-forward
2345 (concat "^" (regexp-quote locale-name) ":?[ \t]+") nil t)
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
2362The display table, the terminal coding system and the keyboard
2363coding system of the current display device are set up for the
2364given 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
2294;; Fixme: This ought to deal with the territory part of the locale 2399;; Fixme: This ought to deal with the territory part of the locale
2295;; too, for setting things such as calendar holidays, ps-print paper 2400;; too, for setting things such as calendar holidays, ps-print paper
2296;; size, spelling dictionary. 2401;; size, spelling dictionary.
@@ -2310,6 +2415,8 @@ or `@cyrillic'.
2310 2415
2311If LOCALE-NAME is nil, its value is taken from the environment 2416If LOCALE-NAME is nil, its value is taken from the environment
2312variables LC_ALL, LC_CTYPE and LANG (the first one that is set). 2417variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
2418On server frames, the environment of the emacsclient process is
2419used.
2313 2420
2314The locale names supported by your system can typically be found in a 2421The locale names supported by your system can typically be found in a
2315directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME 2422directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
@@ -2320,43 +2427,10 @@ See also `locale-charset-language-names', `locale-language-names',
2320`locale-preferred-coding-systems' and `locale-coding-system'." 2427`locale-preferred-coding-systems' and `locale-coding-system'."
2321 (interactive "sSet environment for locale: ") 2428 (interactive "sSet environment for locale: ")
2322 2429
2323 ;; Do this at runtime for the sake of binaries possibly transported 2430 (let ((locale (get-locale-real-name locale-name)))
2324 ;; to a system without X.
2325 (setq locale-translation-file-name
2326 (let ((files
2327 '("/usr/lib/X11/locale/locale.alias" ; e.g. X11R6.4
2328 "/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
2330 ;;
2331 ;; The following name appears after the X-related names above,
2332 ;; since the X-related names are what X actually uses.
2333 "/usr/share/locale/locale.alias" ; GNU/Linux sans X
2334 )))
2335 (while (and files (not (file-exists-p (car files))))
2336 (setq files (cdr files)))
2337 (car files)))
2338
2339 (let ((locale locale-name))
2340
2341 (unless locale
2342 ;; Use the first of these three environment variables
2343 ;; that has a nonempty value.
2344 (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
2345 (while (and vars
2346 (= 0 (length locale))) ; nil or empty string
2347 (setq locale (getenv (pop vars))))))
2348 2431
2349 (when locale 2432 (when locale
2350 2433
2351 ;; Translate "swedish" into "sv_SE.ISO8859-1", and so on,
2352 ;; using the translation file that many systems have.
2353 (when locale-translation-file-name
2354 (with-temp-buffer
2355 (insert-file-contents locale-translation-file-name)
2356 (when (re-search-forward
2357 (concat "^" (regexp-quote locale) ":?[ \t]+") nil t)
2358 (setq locale (buffer-substring (point) (line-end-position))))))
2359
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
@@ -2367,16 +2441,14 @@ See also `locale-charset-language-names', `locale-language-names',
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
@@ -2391,27 +2463,6 @@ See also `locale-charset-language-names', `locale-language-names',
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 2465
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
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
diff --git a/lisp/server.el b/lisp/server.el
index 433d9a7cd26..9758ac1a7cb 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -514,6 +514,8 @@ PROC is the server process. Format of STRING is \"PATH PATH PATH... \\n\"."
514 (select-frame frame) 514 (select-frame frame)
515 (server-client-set client 'frame frame) 515 (server-client-set client 'frame frame)
516 (server-client-set client 'tty (frame-tty-name frame)) 516 (server-client-set client 'tty (frame-tty-name frame))
517 ;; Set up display for the remote locale.
518 (configure-display-for-locale)
517 ;; Reply with our pid. 519 ;; Reply with our pid.
518 (process-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n")) 520 (process-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n"))
519 (setq dontkill t))) 521 (setq dontkill t)))
diff --git a/lisp/startup.el b/lisp/startup.el
index d9b4c049414..2402d116734 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -647,6 +647,8 @@ opening the first frame (e.g. open a connection to the server).")
647 (setq initial-window-system nil) 647 (setq initial-window-system nil)
648 (kill-emacs))) 648 (kill-emacs)))
649 649
650 ;; Locale initialization.
651 (set-locale-translation-file-name)
650 (set-locale-environment nil) 652 (set-locale-environment nil)
651 653
652 ;; Convert the arguments to Emacs internal representation. 654 ;; Convert the arguments to Emacs internal representation.