diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-21 16:14:33 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-21 16:14:33 -0400 |
commit | c5fb55843c66f1ff6d4491009d9cf9781c0a3d7f (patch) | |
tree | 2192e1abfb7e85d866a5fd9efffb221bed0344cb /.config/bash/rc.d/emacs.sh | |
parent | 81bdd77380a77945931687b334d47c95b7492a8d (diff) | |
parent | d65775a22e1648eca8e74389a4d9c1c299017cf3 (diff) |
Merge remote-tracking branch 'origin/master' into build64-par
Diffstat (limited to '.config/bash/rc.d/emacs.sh')
-rw-r--r-- | .config/bash/rc.d/emacs.sh | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/.config/bash/rc.d/emacs.sh b/.config/bash/rc.d/emacs.sh index f484bbb..9c1bf4d 100644 --- a/.config/bash/rc.d/emacs.sh +++ b/.config/bash/rc.d/emacs.sh @@ -1,8 +1,41 @@ +#!/bin/bash + case "$TERM" in eterm*) - SELECTED_EDITOR='emacsclient' - EDITOR=$SELECTED_EDITOR - VISUAL=$SELECTED_EDITOR - export SELECTED_EDITOR EDITOR VISUAL - :;; + SELECTED_EDITOR='emacsclient' + EDITOR=$SELECTED_EDITOR + VISUAL=$SELECTED_EDITOR + export SELECTED_EDITOR EDITOR VISUAL + # The following uses the variable _EMACS_BUFFER to store some state + _emacs_quote() { + local str="$*" + str="${str//\\/\\\\}" + str="${str//\"/\\\"}" + str="\"${str}\"" + printf '%s' "$str" + } + _emacs_rename_terminal() { + local name="$(_emacs_quote "$(_emacs_get_desired_buffer_name)")" + if [[ -n $_EMACS_BUFFER ]]; then + local buffer="(get-buffer $_EMACS_BUFFER)" + else + local buffer='(window-buffer (selected-window))' + fi + _EMACS_BUFFER="$(emacsclient -e "(with-current-buffer ${buffer} (rename-buffer ${name} t)))" 2>/dev/null)" + } + _emacs_get_short_cwd() { + local base=$1 + local suffix='' + if [[ $base =~ (/(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches))*$ ]]; then + suffix=$BASH_REMATCH + base=${base%$suffix} + fi + base=${base##*/} + echo ${base}${suffix} + } + _emacs_get_desired_buffer_name() { + echo "*ansi-term*<$(_emacs_get_short_cwd "$PWD")>" + } + PROMPT_COMMAND='_emacs_rename_terminal "$(_emacs_get_desired_buffer_name)"' + :;; esac |