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
patches, and running Emacs this way has saved me a number of M-x
recover-session invocations.)
I use the following two bash functions to handle my Emacs sessions:
,----[ ~/.bash_profile
| # Usage: preload_emacs <name> [<waitp>]
| #
| # Preloads the Emacs instance called NAME in a detached screen
| # session. Does nothing if the instance is already running. If WAITP
| # is non-empty, the function waits until the server starts up and
| # creates its socket; otherwise it returns immediately.
| function preload_emacs {
| local name="$1"
| local waitp="$2"
| local screendir="/var/run/screen/S-$USER"
| local serverdir="/tmp/emacs$UID"
| local emacs=emacs # Or wherever you installed your multi-tty Emacs
|
| if [ -z "$name" ]; then
| echo "Usage: preload_emacs <name> [<waitp>]" >&2
| return 1
| fi
|
| if [ ! -e "$screendir"/*."$name" ]; then
| if [ -e "$serverdir/$name" ]; then
| # Delete leftover socket (for the wait option)
| rm "$serverdir/$name"
| fi
| screen -dmS "$name" "$emacs" -nw --eval "(setq server-name \"$name\")" -f server-start
| fi
| if [ ! -z "$waitp" ]; then
| while [ ! -e "$serverdir/$name" ]; do sleep 0.1; done
| fi
| return 0
| }
|
| # Usage: connect_emacs <name> <args>...
| #
| # Connects to the Emacs instance called NAME. Starts up the instance
| # if it is not already running. The rest of the arguments are passed
| # to emacsclient.
| function connect_emacs {
| local name="$1"
| shift
|
| if [ -z "$name" ]; then
| echo "Usage: connect_emacs <name> <args>..." >&2
| fi
| preload_emacs "$name" wait
| emacsclient -s "$name" "$@"
| }
|
| export -f preload_emacs connect_emacs
|
| # Preload editor and gnus sessions for speedy initial connects.
| preload_emacs editor
| preload_emacs gnus
`----
,----[ ~/.bashrc
| alias gnus="connect_emacs gnus"
| alias edit="connect_emacs editor"
| alias et="connect_emacs editor -t"
| alias e=edit
`----
I use the following two bash scripts to handle my Emacs sessions:
-------------------------------------------------------connect-emacs--
#!/bin/bash
# Usage: connect-emacs <name> <args>...
#
# Connects to the Emacs instance called NAME. Starts up the instance
# if it is not already running. The rest of the arguments are passed
# to emacsclient.
name="$1"
shift
if [ -z "$name" ]; then
echo "Usage: connect_emacs <name> <args>..." >&2
exit 1
fi
preload-emacs "$name" wait
/usr/bin/emacsclient.emacs-multi-tty -s "$name" "$@"
----------------------------------------------------------------------
-------------------------------------------------------preload-emacs--
#!/bin/bash
# Usage: preload-emacs <name> [<waitp>]
#
# Preloads the Emacs instance called NAME in a detached screen
# session. Does nothing if the instance is already running. If WAITP
# is non-empty, the function waits until the server starts up and
# creates its socket; otherwise it returns immediately.
name="$1"
waitp="$2"
screendir="/var/run/screen/S-$USER"
serverdir="/tmp/emacs$UID"
emacs=/usr/bin/emacs-multi-tty # Or wherever you installed your multi-tty Emacs
if [ -z "$name" ]; then
echo "Usage: preload_emacs <name> [<waitp>]" >&2
exit 1
fi
if [ ! -e "$screendir"/*."$name" ]; then
if [ -e "$serverdir/$name" ]; then
# Delete leftover socket (for the wait option)
rm "$serverdir/$name"
fi
screen -dmS "$name" "$emacs" -nw --eval "(setq server-name \"$name\")" -f server-start
fi
if [ ! -z "$waitp" ]; then
while [ ! -e "$serverdir/$name" ]; do sleep 0.1; done
fi
----------------------------------------------------------------------
I have the following in my profile to have two instances automatically
preloaded for editing and email:
preload-emacs editor
preload-emacs gnus
It is useful to set up short aliases for connect-emacs. I use the
following:
alias edit="connect-emacs editor"
alias e=edit
alias et="connect-emacs editor -t"
alias gnus="connect-emacs gnus"
NEWS
......@@ -406,18 +409,20 @@ THINGS TO DO
** rif->flush_display_optional (NULL) calls should be replaced by a
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
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.
** standard-display-table should be display-local.
standard-display-european should be display-local.
** 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)?
(2) Have a look at Vlocale_coding_system. Seems like it would
be a tedious job to localize it, although most references
use it for interfacing with libc and are therefore OK with
the global definition.
** Have a look at Vlocale_coding_system. Seems like it would be a
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.
......@@ -440,10 +445,6 @@ THINGS TO DO
(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
parameters, which may confuse Emacs with multiple displays. Change
them to tweak only frame-local settings, if possible. (They tend
......@@ -497,8 +498,6 @@ THINGS TO DO
that's why raw terminal support is broken again. I really do need
to understand input.)
** Maybe standard-display-table should be display-local.
DIARY OF CHANGES
----------------
......@@ -1042,4 +1041,13 @@ DIARY OF CHANGES
(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
......@@ -1782,6 +1782,7 @@ created."
;; 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-paste-function . nil)))
(set-locale-environment nil frame)
(setq success t))
(unless success
(delete-frame frame)))
......
......@@ -1741,7 +1741,7 @@ The default status is as follows:
(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."
(let ((coding (get-language-info language-name 'unibyte-display)))
(if coding
......@@ -1755,7 +1755,7 @@ The default status is as follows:
(dotimes (i 128)
(aset standard-display-table (+ i 128) nil))))
(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)
"Set up multi-lingual environment for using LANGUAGE-NAME.
......@@ -2349,7 +2349,7 @@ is returned. Thus, for instance, if charset \"ISO8859-2\",
;; too, for setting things such as calendar holidays, ps-print paper
;; 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.
This sets the language environment, the coding system priority,
the default input method and sometimes other things.
......@@ -2370,6 +2370,11 @@ directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
will be translated according to the table specified by
`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',
`locale-preferred-coding-systems' and `locale-coding-system'."
(interactive "sSet environment for locale: ")
......@@ -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
;; 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,
;; we are using single-byte characters,
;; so the display table and terminal coding system are irrelevant.
(when default-enable-multibyte-characters
(set-display-table-and-terminal-coding-system
language-name coding-system))
language-name coding-system display))
;; Set the `keyboard-coding-system' if appropriate (tty
;; only). At least X and MS Windows can generate
......@@ -2477,12 +2483,14 @@ See also `locale-charset-language-names', `locale-language-names',
(let ((kcs (or coding-system
(car (get-language-info language-name
'coding-system)))))
(if kcs (set-keyboard-coding-system kcs)))
(if kcs (set-keyboard-coding-system kcs display)))
(unless display
(setq locale-coding-system
(car (get-language-info language-name 'coding-priority))))
(car (get-language-info language-name 'coding-priority)))))
(when (and coding-system
(when (and (not display)
coding-system
(not (coding-system-equal coding-system
locale-coding-system)))
(prefer-coding-system coding-system)
......@@ -2494,9 +2502,9 @@ See also `locale-charset-language-names', `locale-language-names',
(when (boundp 'w32-ansi-code-page)
(let ((code-page-coding (intern (format "cp%d" w32-ansi-code-page))))
(when (coding-system-p code-page-coding)
(setq locale-coding-system code-page-coding)
(set-keyboard-coding-system code-page-coding)
(set-terminal-coding-system code-page-coding))))
(unless display (setq locale-coding-system code-page-coding))
(set-keyboard-coding-system code-page-coding display)
(set-terminal-coding-system code-page-coding display))))
(when (eq system-type 'darwin)
;; On Darwin, file names are always encoded in utf-8, no matter
......@@ -2511,6 +2519,7 @@ See also `locale-charset-language-names', `locale-language-names',
;; Default to A4 paper if we're not in a C, POSIX or US locale.
;; (See comments in Flocale_info.)
(unless display
(let ((locale locale)
(paper (locale-info 'paper)))
(if paper
......@@ -2536,7 +2545,7 @@ See also `locale-charset-language-names', `locale-language-names',
("esu$" . letter)
("enc$" . letter)
("frc$" . letter)))
'a4))))))
'a4)))))))
nil)
;;; Charset property
......
......@@ -651,10 +651,10 @@ The following commands are accepted by the client:
(setq request (substring request (match-end 0)))
(unless (server-client-get client 'version)
(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
("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_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO"
"TERMINFO_DIRS" "TERMPATH")
......@@ -665,10 +665,6 @@ The following commands are accepted by the client:
(server-client-set client 'tty (display-name 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.
(server-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n"))
(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