Commit 97c57fb2 authored by Karoly Lorentey's avatar Karoly Lorentey
Browse files

Support for ttys with different character locale settings.

* lisp/server.el (server-process-filter): Set locale environment
  variables from client while creating tty frames.

* lisp/faces.el (tty-create-frame-with-faces): Call set-locale-environment.

* lisp/international/mule-cmds.el (set-display-table-and-terminal-coding-system): 
  Add DISPLAY parameter.  Pass it to set-terminal-coding-system.
  (set-locale-environment): Add DISPLAY parameter.

git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-340
parent 2f420fa8
...@@ -257,69 +257,72 @@ extremely unstable X server for some time while I was developing these ...@@ -257,69 +257,72 @@ extremely unstable X server for some time while I was developing these
patches, and running Emacs this way has saved me a number of M-x patches, and running Emacs this way has saved me a number of M-x
recover-session invocations.) recover-session invocations.)
I use the following two bash functions to handle my Emacs sessions: I use the following two bash scripts to handle my Emacs sessions:
,----[ ~/.bash_profile -------------------------------------------------------connect-emacs--
| # Usage: preload_emacs <name> [<waitp>] #!/bin/bash
| # # Usage: connect-emacs <name> <args>...
| # Preloads the Emacs instance called NAME in a detached screen #
| # session. Does nothing if the instance is already running. If WAITP # Connects to the Emacs instance called NAME. Starts up the instance
| # is non-empty, the function waits until the server starts up and # if it is not already running. The rest of the arguments are passed
| # creates its socket; otherwise it returns immediately. # to emacsclient.
| function preload_emacs {
| local name="$1" name="$1"
| local waitp="$2" shift
| local screendir="/var/run/screen/S-$USER"
| local serverdir="/tmp/emacs$UID" if [ -z "$name" ]; then
| local emacs=emacs # Or wherever you installed your multi-tty Emacs echo "Usage: connect_emacs <name> <args>..." >&2
| exit 1
| if [ -z "$name" ]; then fi
| echo "Usage: preload_emacs <name> [<waitp>]" >&2 preload-emacs "$name" wait
| return 1 /usr/bin/emacsclient.emacs-multi-tty -s "$name" "$@"
| fi ----------------------------------------------------------------------
|
| if [ ! -e "$screendir"/*."$name" ]; then -------------------------------------------------------preload-emacs--
| if [ -e "$serverdir/$name" ]; then #!/bin/bash
| # Delete leftover socket (for the wait option) # Usage: preload-emacs <name> [<waitp>]
| rm "$serverdir/$name" #
| fi # Preloads the Emacs instance called NAME in a detached screen
| screen -dmS "$name" "$emacs" -nw --eval "(setq server-name \"$name\")" -f server-start # session. Does nothing if the instance is already running. If WAITP
| fi # is non-empty, the function waits until the server starts up and
| if [ ! -z "$waitp" ]; then # creates its socket; otherwise it returns immediately.
| while [ ! -e "$serverdir/$name" ]; do sleep 0.1; done
| fi name="$1"
| return 0 waitp="$2"
| } screendir="/var/run/screen/S-$USER"
| serverdir="/tmp/emacs$UID"
| # Usage: connect_emacs <name> <args>... emacs=/usr/bin/emacs-multi-tty # Or wherever you installed your multi-tty Emacs
| #
| # Connects to the Emacs instance called NAME. Starts up the instance if [ -z "$name" ]; then
| # if it is not already running. The rest of the arguments are passed echo "Usage: preload_emacs <name> [<waitp>]" >&2
| # to emacsclient. exit 1
| function connect_emacs { fi
| local name="$1"
| shift if [ ! -e "$screendir"/*."$name" ]; then
| if [ -e "$serverdir/$name" ]; then
| if [ -z "$name" ]; then # Delete leftover socket (for the wait option)
| echo "Usage: connect_emacs <name> <args>..." >&2 rm "$serverdir/$name"
| fi fi
| preload_emacs "$name" wait screen -dmS "$name" "$emacs" -nw --eval "(setq server-name \"$name\")" -f server-start
| emacsclient -s "$name" "$@" fi
| } if [ ! -z "$waitp" ]; then
| while [ ! -e "$serverdir/$name" ]; do sleep 0.1; done
| export -f preload_emacs connect_emacs fi
| ----------------------------------------------------------------------
| # Preload editor and gnus sessions for speedy initial connects.
| preload_emacs editor I have the following in my profile to have two instances automatically
| preload_emacs gnus preloaded for editing and email:
`----
preload-emacs editor
,----[ ~/.bashrc preload-emacs gnus
| alias gnus="connect_emacs gnus"
| alias edit="connect_emacs editor" It is useful to set up short aliases for connect-emacs. I use the
| alias et="connect_emacs editor -t" following:
| alias e=edit
`---- alias edit="connect-emacs editor"
alias e=edit
alias et="connect-emacs editor -t"
alias gnus="connect-emacs gnus"
NEWS NEWS
...@@ -406,21 +409,23 @@ THINGS TO DO ...@@ -406,21 +409,23 @@ THINGS TO DO
** rif->flush_display_optional (NULL) calls should be replaced by a ** rif->flush_display_optional (NULL) calls should be replaced by a
new global function. new global function.
** Support multiple character locales. ** The set-locale-environment hack (adding the DISPLAY option) should
be replaced with a clean design.
(1) A version of `set-locale-environment' needs to be written ** standard-display-table should be display-local.
for setting up display-local settings on ttys. I think standard-display-european should be display-local.
calling set-display-table-and-terminal-coding-system and
set-keyboard-coding-system would be enough. The language
environment itself should remain a global setting.
(2) Have a look at Vlocale_coding_system. Seems like it would ** Fix set-input-mode for multi-tty. It's a truly horrible interface;
be a tedious job to localize it, although most references what if we'd blow it up into several separate functions (with a
use it for interfacing with libc and are therefore OK with compatibility definition)?
the global definition.
Exceptions found so far: x-select-text and ** Have a look at Vlocale_coding_system. Seems like it would be a
x-cut-buffer-or-selection-value. tedious job to localize it, although most references use it for
interfacing with libc and are therefore OK with the global
definition.
Exceptions found so far: x-select-text and
x-cut-buffer-or-selection-value.
** Have a look at fatal_error_hook. ** Have a look at fatal_error_hook.
...@@ -440,10 +445,6 @@ THINGS TO DO ...@@ -440,10 +445,6 @@ THINGS TO DO
(This is likely an error in the CVS trunk.) (This is likely an error in the CVS trunk.)
** Fix set-input-mode for multi-tty. It's a truly horrible interface;
what if we'd blow it up into several separate functions (with a
compatibility definition)?
** The terminal customization files in term/*.el tend to change global ** The terminal customization files in term/*.el tend to change global
parameters, which may confuse Emacs with multiple displays. Change parameters, which may confuse Emacs with multiple displays. Change
them to tweak only frame-local settings, if possible. (They tend them to tweak only frame-local settings, if possible. (They tend
...@@ -497,8 +498,6 @@ THINGS TO DO ...@@ -497,8 +498,6 @@ THINGS TO DO
that's why raw terminal support is broken again. I really do need that's why raw terminal support is broken again. I really do need
to understand input.) to understand input.)
** Maybe standard-display-table should be display-local.
DIARY OF CHANGES DIARY OF CHANGES
---------------- ----------------
...@@ -1042,4 +1041,13 @@ DIARY OF CHANGES ...@@ -1042,4 +1041,13 @@ DIARY OF CHANGES
(Nothing to do. It doesn't seem ugly any more. It's rather clever.) (Nothing to do. It doesn't seem ugly any more. It's rather clever.)
-- Support multiple character locales. A version of
`set-locale-environment' needs to be written for setting up
display-local settings on ttys. I think calling
set-display-table-and-terminal-coding-system and
set-keyboard-coding-system would be enough. The language
environment itself should remain a global setting.
(Done, by an ugly hack.)
;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d ;;; arch-tag: 8da1619e-2e79-41a8-9ac9-a0485daad17d
...@@ -1782,6 +1782,7 @@ created." ...@@ -1782,6 +1782,7 @@ created."
;; Make sure the kill and yank functions do not touch the X clipboard. ;; Make sure the kill and yank functions do not touch the X clipboard.
(modify-frame-parameters frame '((interprogram-cut-function . nil))) (modify-frame-parameters frame '((interprogram-cut-function . nil)))
(modify-frame-parameters frame '((interprogram-paste-function . nil))) (modify-frame-parameters frame '((interprogram-paste-function . nil)))
(set-locale-environment nil frame)
(setq success t)) (setq success t))
(unless success (unless success
(delete-frame frame))) (delete-frame frame)))
......
...@@ -1741,7 +1741,7 @@ The default status is as follows: ...@@ -1741,7 +1741,7 @@ The default status is as follows:
(reset-language-environment) (reset-language-environment)
(defun set-display-table-and-terminal-coding-system (language-name &optional coding-system) (defun set-display-table-and-terminal-coding-system (language-name &optional coding-system display)
"Set up the display table and terminal coding system for LANGUAGE-NAME." "Set up the display table and terminal coding system for LANGUAGE-NAME."
(let ((coding (get-language-info language-name 'unibyte-display))) (let ((coding (get-language-info language-name 'unibyte-display)))
(if coding (if coding
...@@ -1755,7 +1755,7 @@ The default status is as follows: ...@@ -1755,7 +1755,7 @@ The default status is as follows:
(dotimes (i 128) (dotimes (i 128)
(aset standard-display-table (+ i 128) nil)))) (aset standard-display-table (+ i 128) nil))))
(or (eq window-system 'pc) (or (eq window-system 'pc)
(set-terminal-coding-system (or coding-system coding))))) (set-terminal-coding-system (or coding-system coding) display))))
(defun set-language-environment (language-name) (defun set-language-environment (language-name)
"Set up multi-lingual environment for using LANGUAGE-NAME. "Set up multi-lingual environment for using LANGUAGE-NAME.
...@@ -2349,7 +2349,7 @@ is returned. Thus, for instance, if charset \"ISO8859-2\", ...@@ -2349,7 +2349,7 @@ is returned. Thus, for instance, if charset \"ISO8859-2\",
;; too, for setting things such as calendar holidays, ps-print paper ;; too, for setting things such as calendar holidays, ps-print paper
;; size, spelling dictionary. ;; size, spelling dictionary.
(defun set-locale-environment (&optional locale-name) (defun set-locale-environment (&optional locale-name display)
"Set up multi-lingual environment for using LOCALE-NAME. "Set up multi-lingual environment for using LOCALE-NAME.
This sets the language environment, the coding system priority, This sets the language environment, the coding system priority,
the default input method and sometimes other things. the default input method and sometimes other things.
...@@ -2370,6 +2370,11 @@ directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME ...@@ -2370,6 +2370,11 @@ directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
will be translated according to the table specified by will be translated according to the table specified by
`locale-translation-file-name'. `locale-translation-file-name'.
If DISPLAY is non-nil, only set the keyboard coding system and
the terminal coding system for the given display, and don't touch
session-global parameters like the language environment. DISPLAY
may be a display id or a frame.
See also `locale-charset-language-names', `locale-language-names', See also `locale-charset-language-names', `locale-language-names',
`locale-preferred-coding-systems' and `locale-coding-system'." `locale-preferred-coding-systems' and `locale-coding-system'."
(interactive "sSet environment for locale: ") (interactive "sSet environment for locale: ")
...@@ -2458,14 +2463,15 @@ See also `locale-charset-language-names', `locale-language-names', ...@@ -2458,14 +2463,15 @@ See also `locale-charset-language-names', `locale-language-names',
;; Set up for this character set. This is now the right way ;; Set up for this character set. This is now the right way
;; to do it for both unibyte and multibyte modes. ;; to do it for both unibyte and multibyte modes.
(set-language-environment language-name) (unless display
(set-language-environment language-name))
;; If default-enable-multibyte-characters is nil, ;; If default-enable-multibyte-characters is nil,
;; we are using single-byte characters, ;; we are using single-byte characters,
;; so the display table and terminal coding system are irrelevant. ;; so the display table and terminal coding system are irrelevant.
(when default-enable-multibyte-characters (when default-enable-multibyte-characters
(set-display-table-and-terminal-coding-system (set-display-table-and-terminal-coding-system
language-name coding-system)) language-name coding-system display))
;; Set the `keyboard-coding-system' if appropriate (tty ;; Set the `keyboard-coding-system' if appropriate (tty
;; only). At least X and MS Windows can generate ;; only). At least X and MS Windows can generate
...@@ -2477,12 +2483,14 @@ See also `locale-charset-language-names', `locale-language-names', ...@@ -2477,12 +2483,14 @@ See also `locale-charset-language-names', `locale-language-names',
(let ((kcs (or coding-system (let ((kcs (or coding-system
(car (get-language-info language-name (car (get-language-info language-name
'coding-system))))) 'coding-system)))))
(if kcs (set-keyboard-coding-system kcs))) (if kcs (set-keyboard-coding-system kcs display)))
(setq locale-coding-system (unless display
(car (get-language-info language-name 'coding-priority)))) (setq locale-coding-system
(car (get-language-info language-name 'coding-priority)))))
(when (and coding-system (when (and (not display)
coding-system
(not (coding-system-equal coding-system (not (coding-system-equal coding-system
locale-coding-system))) locale-coding-system)))
(prefer-coding-system coding-system) (prefer-coding-system coding-system)
...@@ -2494,9 +2502,9 @@ See also `locale-charset-language-names', `locale-language-names', ...@@ -2494,9 +2502,9 @@ See also `locale-charset-language-names', `locale-language-names',
(when (boundp 'w32-ansi-code-page) (when (boundp 'w32-ansi-code-page)
(let ((code-page-coding (intern (format "cp%d" w32-ansi-code-page)))) (let ((code-page-coding (intern (format "cp%d" w32-ansi-code-page))))
(when (coding-system-p code-page-coding) (when (coding-system-p code-page-coding)
(setq locale-coding-system code-page-coding) (unless display (setq locale-coding-system code-page-coding))
(set-keyboard-coding-system code-page-coding) (set-keyboard-coding-system code-page-coding display)
(set-terminal-coding-system code-page-coding)))) (set-terminal-coding-system code-page-coding display))))
(when (eq system-type 'darwin) (when (eq system-type 'darwin)
;; On Darwin, file names are always encoded in utf-8, no matter ;; On Darwin, file names are always encoded in utf-8, no matter
...@@ -2511,32 +2519,33 @@ See also `locale-charset-language-names', `locale-language-names', ...@@ -2511,32 +2519,33 @@ See also `locale-charset-language-names', `locale-language-names',
;; Default to A4 paper if we're not in a C, POSIX or US locale. ;; Default to A4 paper if we're not in a C, POSIX or US locale.
;; (See comments in Flocale_info.) ;; (See comments in Flocale_info.)
(let ((locale locale) (unless display
(paper (locale-info 'paper))) (let ((locale locale)
(if paper (paper (locale-info 'paper)))
;; This will always be null at the time of writing. (if paper
(cond ;; This will always be null at the time of writing.
((equal paper '(216 279)) (cond
(setq ps-paper-type 'letter)) ((equal paper '(216 279))
((equal paper '(210 297)) (setq ps-paper-type 'letter))
(setq ps-paper-type 'a4))) ((equal paper '(210 297))
(let ((vars '("LC_ALL" "LC_PAPER" "LANG"))) (setq ps-paper-type 'a4)))
(while (and vars (= 0 (length locale))) (let ((vars '("LC_ALL" "LC_PAPER" "LANG")))
(setq locale (getenv (pop vars))))) (while (and vars (= 0 (length locale)))
(when locale (setq locale (getenv (pop vars)))))
;; As of glibc 2.2.5, these are the only US Letter locales, (when locale
;; and the rest are A4. ;; As of glibc 2.2.5, these are the only US Letter locales,
(setq ps-paper-type ;; and the rest are A4.
(or (locale-name-match locale '(("c$" . letter) (setq ps-paper-type
("posix$" . letter) (or (locale-name-match locale '(("c$" . letter)
(".._us" . letter) ("posix$" . letter)
(".._pr" . letter) (".._us" . letter)
(".._ca" . letter) (".._pr" . letter)
("enu$" . letter) ; Windows (".._ca" . letter)
("esu$" . letter) ("enu$" . letter) ; Windows
("enc$" . letter) ("esu$" . letter)
("frc$" . letter))) ("enc$" . letter)
'a4)))))) ("frc$" . letter)))
'a4)))))))
nil) nil)
;;; Charset property ;;; Charset property
......
...@@ -651,10 +651,10 @@ The following commands are accepted by the client: ...@@ -651,10 +651,10 @@ The following commands are accepted by the client:
(setq request (substring request (match-end 0))) (setq request (substring request (match-end 0)))
(unless (server-client-get client 'version) (unless (server-client-get client 'version)
(error "Protocol error; make sure you use the correct version of emacsclient")) (error "Protocol error; make sure you use the correct version of emacsclient"))
;; Set up client's environment for tgetent(3)
;; according to ncurses(3).
(server-with-client-environment proc (server-with-client-environment proc
("BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES" ("LANG" "LC_CTYPE" "LC_ALL"
;; For tgetent(3); list according to ncurses(3).
"BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES"
"NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING" "NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING"
"NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO" "NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO"
"TERMINFO_DIRS" "TERMPATH") "TERMINFO_DIRS" "TERMPATH")
...@@ -665,10 +665,6 @@ The following commands are accepted by the client: ...@@ -665,10 +665,6 @@ The following commands are accepted by the client:
(server-client-set client 'tty (display-name frame)) (server-client-set client 'tty (display-name frame))
(server-client-set client 'display (frame-display frame)) (server-client-set client 'display (frame-display frame))
;; Set up display for the remote locale.
;; XXX This function has been removed from mule-cmds.el, we need to find another way.
;; (configure-display-for-locale)
;; Reply with our pid. ;; Reply with our pid.
(server-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n")) (server-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n"))
(setq dontkill t))) (setq dontkill t)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment