#!/bin/sh # ====================[ emacso ]==================== # [ Time-stamp: "2008-08-21 14:37:06 leycec" ] # # An "emacsclient"-enabled shell script for opening new Emacs processes as # client frames of one master Emacs process - a little stabler and more feature- # filled than the "emacs.bash" and "emacs.csh" shell scripts pre-bundled with # Emacs. # # --------------------( SYNOPSIS )-------------------- # emacso [options] file... # # options # -h, --help Show this help. # -w, --wait Wait for Emacs to exit before exiting this script. # # --------------------( DESCRIPTION )-------------------- # Unlike the default "edit.bash" script shipping with Emacs, this script either # {a} returns immediately (non-blocking) or # {b} waits for you to complete editing before returning (blocking). # # By default, this script returns immediately. (This permits this script to be # used as a drop-in replacement for "emacs" via the $EDITOR shell variable. See # below, for details.) # # --------------------( INSTALLATION )-------------------- # # Move this file to a path in your $PATH. # mv emacso /usr/local/bin # # # Point your $EDITOR shell variable to this file. # export EDITOR=/usr/local/bin/emacso # # # Optionally, make a shell alias to this file. # alias e="emacso" # # --------------------( XEMACS )-------------------- # This script does not, as yet, support XEmacs - which, rather than use the # "emacsclient" binary and protocol for XEmacs client/server management, uses # "gnuclient". (Adding implicit support for XEmacs isn't difficult, of course; # it simply isn't supported, yet. Clean patches, on that front, are happily # welcome!) # # --------------------( MUTT )-------------------- # Mutt is an e-mail client. # # Mutt will "not quite" work out of the box, with this script. This script is # non-blocking, by default; Mutt, on the other, requires that your $EDITOR be # blocking (so that, clearly, it can be notified of your having completed # editing for the mail it passed your $EDITOR). # # This is correctable, as follows: # # # Open your user's "muttrc" file for editing. # emacso ~/.mutt/muttrc # # # Point the editor variable to this file (rather than letting it depend on # # the default value of the $EDITOR shell variable). # set editor="/usr/local/bin/emacso --wait" # # --------------------( CHANGELOG )-------------------- # [2007-05-30] 0.0.1: Creation. # ....................{ CONFIGURATION }.................... #FIXME: Add XEmacs support, here. EMACSCLIENT_COMMAND="emacsclient" EMACS_COMMAND="emacs --debug-init" # ....................{ USAGE }.................... SCRIPT_NAME=$(basename "$0") echo_usage_error() { echo_usage exit 1 } echo_usage_noerror() { echo_usage exit 0 } echo_usage() { echo "Usage: ${SCRIPT_NAME} [options] file... options -h, --help Show this help. -w, --wait Wait for Emacs to exit before exiting this script." } # ....................{ OPTIONS }.................... OPTIONS=$(getopt --unquoted --longoption 'wait,help' --options '+w,h' --shell sh -- "${@}") [ $? = 0 ] || echo_usage_error set -- $OPTIONS while [ $# -gt 0 ]; do case "$1" in --help) echo_usage_noerror;; -h) echo_usage_noerror;; --wait) IS_WAITING="1"; shift;; -w) IS_WAITING="1"; shift;; --) shift; break;; -*) echo_usage_error;; *) break;; esac done FILES_TO_EDIT="$@" # ....................{ COMMANDS }.................... run_emacs() { if [ -n "$IS_WAITING" ]; then echo "emacso: running $EMACS_COMMAND... (waiting)" 1>&2 $EMACS_COMMAND $FILES_TO_EDIT else echo "emacso: running $EMACS_COMMAND..." 1>&2 $EMACS_COMMAND $FILES_TO_EDIT & fi } run_emacsclient() { if [ -n "$IS_WAITING" ]; then echo "emacso: running $EMACSCLIENT_COMMAND... (waiting)" 1>&2 $EMACSCLIENT_COMMAND $FILES_TO_EDIT else echo "emacso: running $EMACSCLIENT_COMMAND..." 1>&2 $EMACSCLIENT_COMMAND --no-wait $FILES_TO_EDIT fi [ $? = 0 ] || run_emacs } # ....................{ EMACSO }.................... if [ -n "${DISPLAY}" ]; then # Do not just test if these files are sockets. On some systems # ordinary files or fifos are used instead. Just see if they exist. if [ -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ] then run_emacsclient else run_emacs fi else if jobs %emacs 2>/dev/null then echo "$(pwd)" $FILES_TO_EDIT >| ${HOME}/.emacs_args && fg %emacs else run_emacs fi fi exit $? # --------------------( COPYRIGHT AND LICENSE )-------------------- # The information below applies to everything in this distribution, # except where noted. # # Copyleft 2008 by B.w.Curry. # # http://www.raiazome.com # # This file is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This file is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this file; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.