aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sh/profile.d/visual.sh24
1 files changed, 20 insertions, 4 deletions
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