Hi screen-users,
* Gregor Zattler <[EMAIL PROTECTED]> [14. Mär. 2006]:
> Hi screen-users,
> 
> via   screen -x   it is possible to attach several times from
> various displays to one single screen session.  But how do I end
> one such connection to this screen session without detatching the
> others (via command line)?
> 
> I use this simple line of bash script:
> 
> { emacsclient --alternate-editor "emacs -nw"  "$@" ; screen -d emacsserver ; 
> } &>/dev/null  & screen -x emacsserver
> 
> to attach to an emacsserver running in a screen session.  If I use
> this script several times from several windows for different files I
> will see the last opened file in all windows (that's not optimal
> but o.k.).  When done with editing one file (via ^x# aka
> server-edit) all windows show the previous file. But then my
> script detaches this screen session running emacsserver via
> screen -d   and this screen session is detached for all windows
> instead only for the one I'm currently working in.  
> 
> The crucial part is "screen -d emacsserver".  Any ideas what to
> do instead?

Torsten Scheck had the correct idea:  Use 
"screen -x emacsserver -X detach" instead of "screen -d emacsserver".

Now there is another but minor problem: Most times I use this
script from within a screen window.  In this cases of a "screen in
screen" situation the outer screen grabs at all screen keyboard
commands.  How do I send keyboard commands to the inner screen
session (e.g. ^aF)?


Script attached.  Warning: The emacs screen session uses "°" as
command character since ^a is not usable when working with
emacs. 

Ciao, Gregor
#!/bin/sh

#set -x


# Using emacsclient and emacs server for editing files is very
# fast and since all files are edited in the same emacs instance
# you can e.g. kill-and-yank between different buffers.

# This script transparently edits files with emacsclient from the
# console, from xterm or from within a screen session running on
# the console or on a xterm.
# As visible difference to running one emacs instance for every
# file you will see in every window the very same buffer because
# all files are edited in the same emacs instance which runs in a
# screen session.

# You may want to set your EDITOR and VISUAL environment
# variables to this script.  E. g.:
# EDITOR=/usr/local/bin/ec
# VISUAL=/usr/local/bin/ec


# For emacsclient to work, we need an already running Emacs with
# a server.  If the emacs server is not already running then
# start it in an detached screen session and wait until startup
# finished.
if ! screen -ls|grep emacsserver >/dev/null ; then
    # screen command line options:
    # -a: all terminal capabilities
    # -fn: no flow control
    # -e °°: use ° as command character since the default is unusable with emacs
    # -d -m: start in detached mode
    # -S emmacsserver: call this session 'emacsserver'
    # -t emacs: window title is 'emacs'
    # emacs command line options:
    # -nw: do not use graphical interface
    # -f server-start: Execute the lisp function 'server-start'
    # --unibyte: Do almost everything with single-byte buffers
    # and strings; this you may change

    screen -a -fn -e °° -d -m -S emacsserver -t emacs emacs -nw --unibyte -f 
server-start
    echo "please wait patiently"
    until ps xu | grep '/[e]macsserver' > /dev/null ; do
        sleep 1
    done

    # Do not show hard status line since we use this screen
    # session as transparent replacement for an emacs invokation
    screen -x emacsserver -X hardstatus ignore
fi


# As a background process connect to the emacs server via
# emacsclient.  When the user finished editing the buffer, s/he
# types `C-x #' (`server-edit').  This sends a message back to
# the `emacsclient' program telling it to exit.  Then we close
# the screen the session connected to the emacs server.

# Use 'emacs -w' as fallback if connection to the emacs server
# fails.  It's probably a safer to avoid emacs as fallback.
{
    emacsclient --alternate-editor "emacs -nw"  "$@"
    screen -x emacsserver -X detach ;
} 2>&1 | egrep -v "Waiting for Emacs|No screen session found|screen is 
terminating" &


# Wait until this script connets to screen session 'emacsserver'
# in multi-display mode.  The fit this screen session to the
# terminal.
{
    until ps t | grep 'screen -x emacsserver' > /dev/null ; do
        sleep 0.01
    done
    screen -x emacsserver -X fit ;
} &

# Connect to screen session 'emacsserver' in multi-display mode.
screen  -x emacsserver
_______________________________________________
screen-users mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/screen-users

Reply via email to