1

I'm trying to troubleshoot an issue with my exec-path. It contains a couple of paths prepended to it that I don't want. initial-environment contains the paths that match what I see when I echo $PATH in xterm but process-environment contains a couple extra and I can't figure out how they are getting there.

I've tried setting a watcher withdebug-on-variable-change at the start of my init.el file, but by the time the watcher gets triggered, process-environment already has those 2 garbage entries. Can I set that watch before Emacs launches?

0

2 Answers 2

2

The C function set_initial_environment in callproc.c populates process-environment and initial-environment together. Subsequent calls to setenv are the usual way of modifying process-environment (but noting that it's very common to be doing that in only a temporary dynamic scope). Obviously it's just a list though, so other manipulations are also entirely possible.

Is there a way to watch a variable and enter a debugger when it is changed?

Yes, see: C-hig (elisp)Watching Variables

Can I set that watch before Emacs launches?

There is nothing to set or watch before Emacs launches.

0

The answer is related to Doom Emacs. I should have included in my original question that I was using a Doom config.

The reason my initial attempt at putting a debug-on-variable-change in my init.el didn't work was because I was putting it in .doom.d/init.el which is loaded late in the initialization process. After reading the Doom docs about the initialization order, I saw that it starts with .emacs.d/init.el (of course). I put the debug-on-variable-change in there and saw it was happening in the function (doom-load-envvars-file "~/.emacs.d/.local/env") which gets called as part of Doom's initialization.

# -*- mode: sh -*-
# Generated from a /bin/zsh shell environent
# ---------------------------------------------------------------------------
# This file was auto-generated by `doom env'. It contains a list of environment
# variables scraped from your default shell (excluding variables blacklisted
# in doom-env-ignored-vars).
#
# It is NOT safe to edit this file. Changes will be overwritten next time you
# run 'doom sync'. To create a safe-to-edit envvar file use:
#
#   doom env -o ~/.doom.d/myenv
#
# And load it with (doom-load-envvars-file "~/.doom.d/myenv").
# ---------------------------------------------------------------------------

I just needed to run doom sync from a terminal that had the environment that I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.