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
** 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.
- (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.
+** 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)?
- Exceptions found so far: x-select-text and
- x-cut-buffer-or-selection-value.
+** 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.
** Have a look at fatal_error_hook.
(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
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
----------------
(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
;; 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)))
(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
(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.
;; 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.
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: ")
;; 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
(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)))
- (setq locale-coding-system
- (car (get-language-info language-name 'coding-priority))))
+ (unless display
+ (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
locale-coding-system)))
(prefer-coding-system coding-system)
(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
;; Default to A4 paper if we're not in a C, POSIX or US locale.
;; (See comments in Flocale_info.)
- (let ((locale locale)
- (paper (locale-info 'paper)))
- (if paper
- ;; This will always be null at the time of writing.
- (cond
- ((equal paper '(216 279))
- (setq ps-paper-type 'letter))
- ((equal paper '(210 297))
- (setq ps-paper-type 'a4)))
- (let ((vars '("LC_ALL" "LC_PAPER" "LANG")))
- (while (and vars (= 0 (length locale)))
- (setq locale (getenv (pop vars)))))
- (when locale
- ;; As of glibc 2.2.5, these are the only US Letter locales,
- ;; and the rest are A4.
- (setq ps-paper-type
- (or (locale-name-match locale '(("c$" . letter)
- ("posix$" . letter)
- (".._us" . letter)
- (".._pr" . letter)
- (".._ca" . letter)
- ("enu$" . letter) ; Windows
- ("esu$" . letter)
- ("enc$" . letter)
- ("frc$" . letter)))
- 'a4))))))
+ (unless display
+ (let ((locale locale)
+ (paper (locale-info 'paper)))
+ (if paper
+ ;; This will always be null at the time of writing.
+ (cond
+ ((equal paper '(216 279))
+ (setq ps-paper-type 'letter))
+ ((equal paper '(210 297))
+ (setq ps-paper-type 'a4)))
+ (let ((vars '("LC_ALL" "LC_PAPER" "LANG")))
+ (while (and vars (= 0 (length locale)))
+ (setq locale (getenv (pop vars)))))
+ (when locale
+ ;; As of glibc 2.2.5, these are the only US Letter locales,
+ ;; and the rest are A4.
+ (setq ps-paper-type
+ (or (locale-name-match locale '(("c$" . letter)
+ ("posix$" . letter)
+ (".._us" . letter)
+ (".._pr" . letter)
+ (".._ca" . letter)
+ ("enu$" . letter) ; Windows
+ ("esu$" . letter)
+ ("enc$" . letter)
+ ("frc$" . letter)))
+ 'a4)))))))
nil)
\f
;;; Charset property
(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")
(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)))