diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-08-22 03:51:52 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-09-22 15:27:18 -0400 |
commit | 1ae109d7abae11a327f362bfdfb623ac0ac770e0 (patch) | |
tree | 5bf25f17077d4477c4a18a401081493076a8c28a /.config/bash/rc.d/90_emacs.sh | |
parent | ef71eedb6bcc3889128af24df3aa668dde3e2c6f (diff) |
Clean up bash configuration, and bash-emacs integration
Diffstat (limited to '.config/bash/rc.d/90_emacs.sh')
-rw-r--r-- | .config/bash/rc.d/90_emacs.sh | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/.config/bash/rc.d/90_emacs.sh b/.config/bash/rc.d/90_emacs.sh new file mode 100644 index 0000000..595ddcf --- /dev/null +++ b/.config/bash/rc.d/90_emacs.sh @@ -0,0 +1,63 @@ +#!/hint/bash + +if [[ $TERM == eterm* ]]; then + ## Primatives for interacting with Emacs ############################### + + # _emacs_run LISP + _emacs_run() { + emacsclient -a false -e "$*" 2>/dev/null + } + # _emacs_quote UNQUOTED_STRING + _emacs_quote() { + local str="$*" + str="${str//\\/\\\\}" # \ -> \\ + str="${str//\"/\\\"}" # " -> \" + str="\"${str}\"" # wrap it in quotes + printf '%s' "$str" + } + # _emacs_unquote QUOTED_STRING + _emacs_unquote() { + local str="$*" + if [[ $str =~ ^\"(.*)\"$ ]]; then + str=${BASH_REMATCH[1]} # un-quote it + str="${str//\\\\/\\}" # \\ -> \ + str="${str//\\\"/\"}" # \" -> " + fi + printf '%s' "$str" + } + + ## High-level tasks #################################################### + + # Set the TRAMP directory for remote hosts (shell -> emacs) + _emacs_set_remote_dir() { + # Because (term-handle-ansi-terminal-messages) is run + # after each item is set, the user should be set + # before the hostname is set, otherwise it will set + # (default-directory) to an invalid TRAMP string. + # + # Because the hostname is compared to (system-name) to + # check if it is localhost, "$(hostname -f)" needs to + # be used instead of $HOSTNAME, unfortunately. + printf '\eAnSiT%s %s\n' \ + u "$USER" \ + c "$PWD" \ + h "$(hostname -f)" + } + # Set the shell's X11 display (emacs -> shell) + _emacs_set_shell_DISPLAY() { + export DISPLAY=$(_emacs_unquote "$(_emacs_run "(cdr (assoc 'display (frame-parameters)))")") + [[ $DISPLAY != nil ]] || unset DISPLAY + } + + ## Install the hooks ################################################### + + export SELECTED_EDITOR='emacsclient' + export EDITOR=$SELECTED_EDITOR + export VISUAL=$SELECTED_EDITOR + export PAGER=cat + if _emacs_run '()' >/dev/null; then + PROMPT_COMMAND+='_emacs_set_shell_DISPLAY;' + fi + # Remember, the $() strips the trailing newline, so add it back in + PS1_EXTRA+='\[$(_emacs_set_remote_dir)'$'\n\\]' +fi |