Commit | Line | Data |
---|---|---|
e2916e48 GM |
1 | ### emacs.bash --- contact/resume an existing Emacs, or start a new one |
2 | ||
5df4f04c | 3 | ## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
e2916e48 GM |
4 | ## Free Software Foundation, Inc. |
5 | ||
6 | ## Author: Noah Friedman | |
7 | ||
8 | ## This file is part of GNU Emacs. | |
9 | ||
ab73e885 | 10 | ## GNU Emacs is free software: you can redistribute it and/or modify |
e2916e48 | 11 | ## it under the terms of the GNU General Public License as published by |
ab73e885 GM |
12 | ## the Free Software Foundation, either version 3 of the License, or |
13 | ## (at your option) any later version. | |
e2916e48 GM |
14 | |
15 | ## GNU Emacs is distributed in the hope that it will be useful, | |
16 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ## GNU General Public License for more details. | |
19 | ||
20 | ## You should have received a copy of the GNU General Public License | |
ab73e885 | 21 | ## along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
e2916e48 GM |
22 | |
23 | ### Commentary: | |
24 | ||
35f00409 GM |
25 | ## This file is obsolete. Use emacsclient -a instead. |
26 | ||
e2916e48 GM |
27 | ## This defines a bash command named `edit' which contacts/resumes an |
28 | ## existing emacs or starts a new one if none exists. | |
29 | ||
30 | ## One way or another, any arguments are passed to emacs to specify files | |
31 | ## (provided you have loaded `resume.el'). | |
32 | ||
33 | ## This function assumes the emacs program is named `emacs' and is somewhere | |
34 | ## in your load path. If either of these is not true, the most portable | |
35 | ## (and convenient) thing to do is to make an alias called emacs which | |
36 | ## refers to the real program, e.g. | |
37 | ## | |
38 | ## alias emacs=/usr/local/bin/gemacs | |
a933dad1 DL |
39 | |
40 | function edit () | |
41 | { | |
42 | local windowsys="${WINDOW_PARENT+sun}" | |
43 | ||
44 | windowsys="${windowsys:-${DISPLAY+x}}" | |
45 | ||
46 | if [ -n "${windowsys:+set}" ]; then | |
47 | # Do not just test if these files are sockets. On some systems | |
48 | # ordinary files or fifos are used instead. Just see if they exist. | |
13b9acf0 | 49 | if [ -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ]; then |
a933dad1 DL |
50 | emacsclient "$@" |
51 | return $? | |
52 | else | |
53 | echo "edit: starting emacs in background..." 1>&2 | |
54 | fi | |
55 | ||
56 | case "${windowsys}" in | |
57 | x ) (emacs "$@" &) ;; | |
6f022c19 | 58 | sun ) echo "unsupported window system"; return 1 ;; |
a933dad1 | 59 | esac |
177c0ea7 | 60 | else |
a933dad1 DL |
61 | if jobs %emacs 2> /dev/null ; then |
62 | echo "$(pwd)" "$@" >| ${HOME}/.emacs_args && fg %emacs | |
63 | else | |
64 | emacs "$@" | |
65 | fi | |
66 | fi | |
67 | } | |
68 | ||
69 | ||
ab5796a9 | 70 | # arch-tag: 1e1b74b9-bf2c-4b23-870f-9eebff7515cb |
e2916e48 | 71 | ### emacs.bash ends here |