-g() {
-
- local args gdb=false
-
- if [[ $EMACSDIR ]]; then
- path-add "$EMACSDIR/lib-src" "$EMACSDIR/src"
- fi
-
- if [[ $DISPLAY ]]; then
- args=-n
- fi
-
- if (( $# == 0 )); then
- args+=" -c"
- fi
- # duplicate -c, but oh well
- if ! pgrep -u $EUID emacsclient; then
- if (( $# == 0 )) && type -p gdb &>/dev/null; then
- gdb=true
- else
- args+=" -c"
- fi
- fi
- if [[ $EMACSDIR ]]; then
-
- # todo: we don't have to alter HOME since emacs 29+, we can set
- # user-emacs-directory with the flag --init-directory
-
- # Alter the path here, otherwise the nfs mount gets triggered on the
- # first path lookup when emacs is not being used.
- # shellcheck disable=SC2098 disable=SC2097 # false positive
- PATH="$EMACSDIR/lib-src:$EMACSDIR/src:$PATH" EHOME=$HOME HOME=$EMACSDIR m emacsclient -a "" $args "$@"
- else
- if $gdb; then
- # due to a bug, we cant debug from the start unless we get a new gdb
- # https://sourceware.org/bugzilla/show_bug.cgi?id=24454
- # m gdb -ex="set follow-fork-mode child" -ex=r -ex=quit --args emacs --daemon
- m emacsclient -a "" $args "$@"
- sleep 1
- cd "/a/opt/emacs-$(distro-name)$(distro-num)"
- s gdb -p "$(pgrep -f 'emacs --daemon')" -ex c
- cd -
- else
- m emacsclient -a "" $args "$@"
- fi
- fi
-}