From b1cb59184d3e35a961d0139ae657a330ad9b1a13 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 2 Jan 2019 21:45:46 +1300 Subject: Add emacsclient logic to $VISUAL set --- sh/profile.d/visual.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'sh/profile.d/visual.sh') diff --git a/sh/profile.d/visual.sh b/sh/profile.d/visual.sh index 94aee963..359bf13a 100644 --- a/sh/profile.d/visual.sh +++ b/sh/profile.d/visual.sh @@ -1,9 +1,25 @@ -# If emacs is installed, and ~/.emacs exists, use emacs as the visual editor; -# otherwise, use the system's vi +# If an Emacs is installed, and ~/.emacs exists, use emacs as the visual +# editor; otherwise, use the system's vi if command -v emacs >/dev/null 2>&1 && - [ -f "$HOME"/.emacs ] ; then - VISUAL=emacs + [ -f "$HOME"/.emacs ] ; then + + # Use or start a GNU Emacs client, if possible + if command -v pgrep >/dev/null 2>&1 && + pgrep --exact --full --euid="$USER" \ + 'emacs --daemon' >/dev/null || + emacs --daemon >/dev/null ; then + VISUAL=emacsclient + + # If no GNU Emacs daemon is available, just create a new instance every + # time + else + VISUAL=emacs + fi + +# If an Emacs isn't installed, just use good old vi else VISUAL=vi fi + +# Export final editor decision export VISUAL -- cgit v1.2.3