pierre-rouleau / pel

Pragmatic Emacs Library
GNU General Public License v3.0
33 stars 0 forks source link

Add support for Emacs not launched from a shell #23

Closed pierre-rouleau closed 3 years ago

pierre-rouleau commented 3 years ago

PEL fast-startup, terminal/graphics independent customization and package quickstart control depend on ability to detect the environment and for some of this logic that depends on Emacs being launched from a shell.

It's possible to launch Emacs from outside of a shell in several operating systems. When its done PEL code is not able to detect important information and several Emacs package are not initialized properly.

Steve Purcell provides a library to handle this but its solution increases the Emacs startup time (it launches a child shell and extracts the environment values out of that shell to add them to the ones used by future Emacs shell children).

One of PEL goals is to speed Emacs startup. Steve Purcell's library is therefore not a good fit for PEL.

On macOS it's possible to store extra environment variables inside the macOS Emacs app bundle Info.plist file. This however is not very flexible and also only works on macOS.

Compounding the problem is the fact that some decisions PEL must make have to be taken inside the execution of early-init.el which is before the customization file is loaded. For the moment only one environment-based decision must be taken by PEL inside early-init.el: to determine if Emacs is running in terminal or graphics mode.

One possible solution would be to find a environment variable that is always defined when Emacs was launched from a shell and that is also not defined when Emacs is launched from a GUI program like Windows Explorer or macOS Finder.

CURRENT PROPOSED SOLUTION:

pierre-rouleau commented 3 years ago

The last commit implements something very similar to what is described above. If you use macOS and Bash you do not need to define a PEL_SHELL environment variable as it uses the _ environment variable as the detection mechanism. But for other environments you will have to identify the environment variable to use and there is a PEL user-option for that: pel-shell-detection-envvar.