about summary refs log tree commit diff
path: root/emacs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2018-01-08T20·42-0500
committerWilliam Carroll <wpcarro@gmail.com>2018-01-08T20·42-0500
commitc4663580482a7faed5f73dd72a0fb037d1e56a03 (patch)
tree753943b9d934ffd237a9a52fce17d2a2487bd5e5 /emacs
parent8cadd912a607efae3d2a92e9d49d03fe0eaf5a23 (diff)
Update Emacs / Bash monkey-patched functions
Diffstat (limited to 'emacs')
-rwxr-xr-xemacs/index.sh45
1 files changed, 23 insertions, 22 deletions
diff --git a/emacs/index.sh b/emacs/index.sh
index d80372eba312..42791549881d 100755
--- a/emacs/index.sh
+++ b/emacs/index.sh
@@ -1,8 +1,15 @@
 #!/usr/bin/env zsh
 
+# This file contains tooling that make terminal usage from within Emacs more enjoyable. Some of
+# these are conditionally defined functions that monkey patch CLI utils like vim and man and
+# dispatch to native Emacs utils that should function as analogous alternatives.
+
+# While most of these conditional definitions could fall inside of one larger, if "${INSIDE_EMACS}"
+# block, to increase portability, smaller, redundant blocks are preferred.
+
 
 # Have zsh export variables for Emacs to track the cwd
-if [ -n "$INSIDE_EMACS" ]; then
+if [ -n "${INSIDE_EMACS}" ]; then
   chpwd() { print -P "\033AnSiTc %d" }
   print -P "\033AnSiTu %n"
   print -P "\033AnSiTc %d"
@@ -10,36 +17,30 @@ fi
 
 
 # Custom emacs pager support
-if [ -n "$INSIDE_EMACS" ]; then
+if [ -n "${INSIDE_EMACS}" ]; then
     export PAGER="create-shell-pager.sh"
-else
-    export PAGER="less"
 fi
 
 
-# Edit commit messages, etc from ansi-term in emacs
-if [ -n "$INSIDE_EMACS" ]; then
+# For git primarily. Edit commit messages, etc from ansi-term in Emacs
+if [ -n "${INSIDE_EMACS}" ]; then
     export EDITOR="edit-file-in-emacs.sh"
-else
-    export EDITOR="command vim"
 fi
 
 
-# Calls to vim from within ansi-term trigger emacs find-file
-vim () {
-    if [ -n "$INSIDE_EMACS" ]; then
+# Muscle-memory dies hard. Calls to vim from an Emacs terminal attempt to open vim from inside of
+# Emacs. This is a really bad UX, and hard to exit from. Instead of retraining muscle-memory,
+# dispatch to Emacs' file editing when vim is called from an Emacs terminal.
+if [ -n "${INSIDE_EMACS}" ]; then
+    function vim () {
         emacsclient -e "(find-file-other-window \"$1\")"
-    else
-        command vim "$1"
-    fi
-}
+    }
+fi
 
 
-# Calls to man from within ansi-term trigger emacs man
-man () {
-    if [ -n "$INSIDE_EMACS" ]; then
+# Prefer Emac's built-in man util when called from an Emacs terminal
+if [ -n "${INSIDE_EMACS}" ]; then
+    function man () {
         emacsclient -e  "(man \"$1\")"
-    else
-        command man "$1"
-    fi
-}
+    }
+fi