about summary refs log tree commit diff
path: root/emacs/index.sh
blob: 42791549881d5ab95295e8b68deff2391734fddf (plain) (blame)
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
#!/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
  chpwd() { print -P "\033AnSiTc %d" }
  print -P "\033AnSiTu %n"
  print -P "\033AnSiTc %d"
fi


# Custom emacs pager support
if [ -n "${INSIDE_EMACS}" ]; then
    export PAGER="create-shell-pager.sh"
fi


# For git primarily. Edit commit messages, etc from ansi-term in Emacs
if [ -n "${INSIDE_EMACS}" ]; then
    export EDITOR="edit-file-in-emacs.sh"
fi


# 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\")"
    }
fi


# Prefer Emac's built-in man util when called from an Emacs terminal
if [ -n "${INSIDE_EMACS}" ]; then
    function man () {
        emacsclient -e  "(man \"$1\")"
    }
fi