Skip to content

Make emacs temp buffers inherit buffer-local environment variables

Notifications You must be signed in to change notification settings

purcell/inheritenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Melpa Status Melpa Stable Status Build Status Support me

Make Emacs temp buffers inherit buffer-local environment variables

Environment variables in Emacs can be set buffer-locally, like many Emacs preferences, and this allows users to have different buffer-local paths for executables in different projects, specified by a .dir-locals.el file or via a direnv integration like envrc.

However, there's a fairly common pitfall when Emacs libraries run background processes on behalf of a user: many such libraries run processes in temporary buffers that do not inherit the calling buffer's environment if it is set buffer-locally. This can result in executables not being found, or the wrong versions of executables being picked up.

An example is the Emacs built-in command shell-command-to-string. Whatever buffer-local process-environment (or exec-path) the user has set, that command will always use the Emacs-wide default. This is specified behaviour, but not expected or helpful.

inheritenv provides a couple of tools for dealing with this issue:

  1. Library authors can wrap code that plans to execute processes in temporary buffers with the inheritenv macro.
  2. Users can modify commands like shell-command-to-string using the inheritenv-add-advice macro.

Installation

Manual

Ensure inheritenv.el is in a directory on your load-path, and add the following to your ~/.emacs or ~/.emacs.d/init.el:

(require 'inheritenv)

MELPA

If you're an Emacs 24 user or you have a recent version of package.el you can install inheritenv from the MELPA repository. The version of inheritenv there will always be up-to-date.

About

Author: Steve Purcell

Homepage: https://github.com/purcell/inheritenv


💝 Support this project and my other Open Source work

💼 LinkedIn profile

✍ sanityinc.com

About

Make emacs temp buffers inherit buffer-local environment variables

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published