From 63103674b9108d9b79092a471299be2415ac5e7b Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 15 Aug 2015 21:32:56 -0700 Subject: [PATCH] Make a temp file when standard in comes to emacs. This supports using emacs as a PAGER --- dotfiles/lib/editor.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/dotfiles/lib/editor.sh b/dotfiles/lib/editor.sh index 34905eef..96bbce50 100755 --- a/dotfiles/lib/editor.sh +++ b/dotfiles/lib/editor.sh @@ -1,8 +1,22 @@ #!/usr/bin/env zsh -if is_osx; then - reattach-to-user-namespace emacsclient "$@" + +function editor { + if is_osx; then + reattach-to-user-namespace emacsclient "$@" + else + emacsclient "$@" + fi +} + + +if [ -t 1 ]; then + TMP="$(mktemp -t emacs)" + echo $TMP + cat > "$TMP" + editor "$TMP" "$@" + rm "$TMP" else - emacsclient "$@" + editor "$@" fi return 0