-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdotbash_emacs
executable file
·150 lines (133 loc) · 4.4 KB
/
dotbash_emacs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
#
# Alex's .bashrc_emacs
#
# Emacs Specific setup
#
# There is only one editor (although I can get to it in different ways).
# For most stuff I want to use emacsclient to spawn a quick shell and
# for emacs 23 I want to ensure the daemon is always running for the user.
#
# Luckily this is covered by specifying -a '' which will spawn a daemon if
# one is not running
#
# I don't want to bring up daemons on every machine
COMPILED_EMACS_PATH=$(find_directories "${HOME}/src/emacs" "/export/src/emacs")
# I may already have the latest and greatest, so use whatever is appropriate
if [[ -d "$COMPILED_EMACS_PATH" && -e "$COMPILED_EMACS_PATH/install/bin/emacs" ]]; then
system_version=`emacs --version | head -n 1 | cut -d ' ' -f 3`
compiled_version=`$COMPILED_EMACS_PATH/install/bin/emacs --version | head -n 1 | cut -d ' ' -f 3`
$(vercomp $compiled_version $system_version)
#echo "comparing $compiled_version to $system_version got $?"
if [[ "$?" == "1" || "$?" == "0" ]]; then
# add_to_world from main bash profile
add_to_world $COMPILED_EMACS_PATH
fi
fi
if [[ "$DISPLAY" == "" || "${SSH_TTY}" ]]; then
# Can we use muti-tty?
emacsclient --help 2>&1 | grep "\-\-tty" > /dev/null
if [[ "$?" == "0" ]]; then
# Thats a yes
EMACS_CMD="emacsclient"
EMACS_ARGS="-a '' -t"
REPORT="with multi-tty"
else
# Hmmm, opening in another pane would be a pain?
EMACS_CMD="emacs"
EMACS_ARGS="-nw"
REPORT="standalone"
fi
else
# otherwise open a new frame
EMACS_CMD="emacsclient"
EMACS_ARGS="-a '' -c"
# No wait only makes sense for interactive, GUI frame sessions
EMACS_NW="-n"
REPORT="with X"
fi
alias ect="emacsclient -a '' -t"
alias dired="emacsclient -a '' -t -e '(my-dired-frame default-directory)'"
# Set the environment variables for the editors, remember that programs like
# git or crontab -e will get confused if they don't wait for the editor to return.
export EDITOR="${EMACS_CMD} ${EMACS_ARGS} "
export VISUAL="${EMACS_CMD} ${EMACS_ARGS} "
export ALTERNATE_EDITOR=emacs
# shortcut
alias ec="${EMACS_CMD} ${EMACS_NW} ${EMACS_ARGS}"
#
# If I've been using a screen session while physically next to
# the box I'll have an EDITOR etc set up for new X frames. However
# if I then login remotely I'll be wanting to spawn --tty frames
# for new cases.
#
function switch_emacs_to_terminal()
{
if [ "${EMACS_CMD}" == "emacsclient" ]; then
export EDITOR="${EMACS_CMD} -a '' -t "
export VISUAL="${EMACS_CMD} -a '' -t "
export ALTERNATE_EDITOR="emacs -nw"
echo "Emacs clients now in terminal mode"
fi
}
function use_zile_for_visual()
{
ZILE=$(find_alternatives "zile")
if [[ -x "${ZILE}" ]]; then
export EDITOR=${ZILE}
export VISUAL=${ZILE}
echo "Enabled VISUAL=${VISUAL}"
fi
}
function use_emacs_for_visual()
{
ZILE=$(find_alternatives "zile")
if [[ -x "${ZILE}" ]]; then
export EDITOR="${EMACS_CMD} ${EMACS_ARGS} "
export VISUAL="${EMACS_CMD} ${EMACS_ARGS} "
echo "Enabled VISUAL=${VISUAL}"
fi
}
XKBMAP=$(find_alternatives "setxkbmap")
KEYMAPS=""
if [ -z "${DISPLAY}" ]; then
if [ -e ${XKBMAP} ]; then
setxkbmap -layout gb -option "ctrl:nocaps" 2> /dev/null
KEYMAPS="${KEYMAPS} Caps->Ctrl (console)"
fi
fi
#
# These two functions come from eproject/contrib/eproject.sh
# and allow basic shell navigation based on current project or
# finding the root of the current directory.
#
# Go to currently active project root in Emacs
cdp() {
local EMACS_CWP=$(emacsclient -a false -e \
"(eproject-current-working-directory)" \
| sed 's/^"\(.*\)"$/\1/')
if [ -d "$EMACS_CWP" ]; then
cd "$EMACS_CWP"
else
return 1
fi
}
# Go to the top of the project root of the current directory
cdtp() {
local tmp_dir=$(pwd)
local tmp_file=$(mktemp -p "$tmp_dir" -t ".cdeprj_XXXXX")
local elisp="(let ((tmp \"$tmp_file\")) (with-temp-file tmp (setq buffer-file-name tmp) (eproject-maybe-turn-on)))"
local EMACS_CWP=$(emacsclient -a false -e "${elisp}" | sed 's/^"\(.*\)"$/\1/')
rm -f ${tmp_file}
if [ -d "$EMACS_CWP" ]; then
cd "$EMACS_CWP"
else
return 1
fi
}
if [ ! -d ~/.emacs.d/elpa ]; then
REPORT="$REPORT (no packages)"
alias bootstrap_emacs="emacs -q --batch -l ~/.emacs.d/my-elisp/my-package.el -f my-packages-reset"
fi
alias .emacs=". ~/.bash_emacs"
echo "loading .bash_emacs (Using: `which $EMACS_CMD` $REPORT $KEYMAPS)"