Goal:
I would like to do the following with Emacs 27+:
- take advantage of the
package-quickstartoption to speed up startup, - have 2 independent elpa directories:
~/.emacs.d/elpawhen emacs runs in terminal mode,~/.emacs.d/elpa-graphicswhen emacs runs in graphics mode.
- have 2 customization files:
~/.emacs.d/emacs-customization.elwhen Emacs runs in terminal mode,~/.emacs.d/emacs-customization-graphics.elwhen Emacs runs in graphics mode.
Experiment:
I tried to distinguish the two modes inside ~/.emacs.d/early-init.el by calling display-graphic-p but it seems that it's too early for (display-graphic-p) to return a proper value. Here's what I wrote into early-init.el:
;; Separate elpa directory for Emacs in graphics mode and Emacs in TTY mode.
;; Use ~/.emacs.d/elpa in TTY mode, use ~/.emacs.d/elpa-graphics in graphics mode
(setq roup-was-here '(0))
(when (display-graphic-p)
(push 1 roup-was-here )
(setq package-user-dir (locate-user-emacs-file "elpa-graphics")))
(setq custom-file (if (display-graphic-p)
"~/.emacs.d/emacs-customization-graphics.el"
"~/.emacs.d/emacs-customization.el"))
(push custom-file roup-was-here)
After running Emacs 27.2 in both TTY first and then in graphics mode, I looked at the value of the variable roup-was-here. In both case the variable holds ("~/.emacs.d/emacs-customization.el" 0) indicating that my code above was not able to distinguish between Emacs running in graphics mode versus terminal mode.
If I set custom-file inside the file ~/.emacs.d/init.el like I do for Emacs 26 where I'm able to distinguish between the 2 modes and have 2 independent customization files. It is recognized but the graphics Emacs still uses ~/.emacs.d/elpa.
I tried to use the different customization file to distinguish and set package-user-dir via the customization file but that does not work either.
Question:
Is it possible with Emacs 27+ using the package-quickstart to set package-user-dir differently on Emacs in terminal (TTY/termcap) mode and Emacs in graphics mode? If so how is it done? Is there another variable that code in early-init.el can use to distinguish between the 2 modes?
The only way I have found is to start my graphical Emacs via a shell script that sets a OS environment variable that I then read with getenv inside the early-init.el file. Is it the only way it can be done?