# -*-sh-*-

### Emacs
# gnuclient -h localhost -p


gnuserv_via_socket(){
    true;
#only in chroot on `linux6'!

#    [ $(/bin/hostname) = "linux1"  -o $(/bin/hostname) = "portege" ]
    ## hostname is also in _other_ dirs. there, running this file would cause problems !!!!
}


if false;  # GNUCLIENT
then

    if gnuserv_via_socket;
    then

        (( emacs_port = 21490 + $UID ))
        export emacs_port

        # emacs & xemacs available.  gnudoit works via socket
        # alias en='gnudoit "(make-frame-on-display \"linux3:0\")"'
        alias en='gnuclient -h localhost -q -p ${emacs_port}  -batch -q --display ${DISPLAY} -eval "(make-frame-on-display \"${DISPLAY}\")"'

        alias edit='gnuclient -h localhost -q -p ${emacs_port}  -q --display ${DISPLAY}'

        #   alias dired='gnuclient -h localhost -batch -q --display ${DISPLAY} -p ${emacs_port} -eval \"\(progn \(select-frame \(make-frame-on-display \\\"$DISPLAY\\\"\)\)\(dired \\\"$(pwd)\\\"\)\)\"'

        alias dired='gnuclient -h localhost -batch -q --display ${DISPLAY} -p ${emacs_port} -eval "(progn (select-frame (make-frame-on-display \"$DISPLAY\"))(dired \"$(pwd)\"))"'

        #   alias xxx='gnuclient -h localhost -batch -q --display ${DISPLAY} -p ${emacs_port} -eval \"\(message \\\"ok\\\"\)\"'

        alias dr='gnuclient -h localhost -batch -q --display ${DISPLAY} -p ${emacs_port} -eval "(progn (select-frame (make-frame-on-display \"$DISPLAY\"))(dired \"$(pwd)\"))"'

        # fixme: I dunno how to make dr = dired, w/o doubling.
    else
        # 1 emacs only. gnudoit works via   named pipe
        alias en='gnudoit \"(make-frame-on-display \\\"${DISPLAY}\\\")\"  '
        alias dired='gnudoit \"(progn (make-frame-extern) (dired \\\"\\$(pwd)\\\"))\"'
    fi

emacs_ssh(){
    # propagate ENV from the shell into the emacs (accessible via gnuclient)
    gnuclient -h localhost -q -p ${emacs_port}  -batch -q --display ${DISPLAY} -eval \
        "(setenv \"SSH_AUTH_SOCK\" \"$SSH_AUTH_SOCK\")"
    gnuclient -h localhost -q -p ${emacs_port}  -batch -q --display ${DISPLAY} -eval \
        "(setenv \"SSH_AUTH_SOCK\" \"$SSH_AUTH_SOCK\")"
}

else # no gnuclient(1):
    # VISUAL
    alias edit="emacsclient"

    alias magit='emacsclient -c -e "(magit-status \"$PWD/\")"'

    alias en='emacsclient --eval "(make-frame-on-display \"$DISPLAY\" nil)" '
fi

alias emacs_compile="emacs -batch  -f batch-byte-compile"
