From c39457161c02bca6a0bda2ba42d02da1cf4ddc17 Mon Sep 17 00:00:00 2001 From: "Adam J. Jackson" Date: Mon, 18 May 2026 17:42:22 +0100 Subject: [PATCH] WIP improved emacsclient launch function The main requirement for this is to avoid messy situations if I instintively "em" while inside an emacs vterm. Nested emacs instances are not nice, instead this should jump to existing (outer) emacs. Currently there are some rough corners: - if TUI and GUI are both open, sometimes vterm->em from TUI opens in GUI instead - other programs using EDITOR don't expect/like this to be a fish function. --- dotfiles.org | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/dotfiles.org b/dotfiles.org index 356b5cb..303d0c7 100644 --- a/dotfiles.org +++ b/dotfiles.org @@ -724,14 +724,35 @@ corresponding section of Bash config for more info. if status is-interactive # Commands to run in interactive sessions can go here - if test -f "/usr/lib64/libc_malloc_debug.so.0" - set -x EDITOR="LD_PRELOAD=/usr/lib64/libc_malloc_debug.so.0 emacsclient -t" - else - set -x EDITOR "emacsclient -t" + set -x ALTERNATE_EDITOR '' + + function em + set -l PRELOAD_LIB /usr/lib/libc_malloc_debug.so + set -l EC_ARGS -t + + if set -q INSIDE_EMACS + and not set -q EMACS_SERVER_NAME + echo "em: EMACS_SERVER_NAME not set" >&2 + return 1 + end + + if set -q EMACS_SERVER_NAME + set -a EC_ARGS -s $EMACS_SERVER_NAME + end + + if set -q INSIDE_EMACS + set -a EC_ARGS -n + end + + if test -e $PRELOAD_LIB + env LD_PRELOAD=$PRELOAD_LIB emacsclient $EC_ARGS $argv + else + emacsclient $EC_ARGS $argv + end end - set -x ALTERNATE_EDITOR '' - alias em $EDITOR + set -x EDITOR em + end #+end_src