all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs in multiple profiles
@ 2018-03-22 16:47 Konrad Hinsen
  2018-03-22 21:21 ` Alex Kost
  0 siblings, 1 reply; 53+ messages in thread
From: Konrad Hinsen @ 2018-03-22 16:47 UTC (permalink / raw)
  To: help-guix

Dear Guixers,

Is anyone aware of a way to have different Emacs configurations (i.e. 
different add-on packages) in distinct profiles?

I tried to set up a new profile with just "emacs" in it, but when I run 
that Emacs it load all the Emacs Lisp packages from my main profile. I 
traced this down to site-start.el loading guix-emacs.el, which has the 
main profile hard-coded and therefore loads all the packages from there:

   (defvar guix-user-profile (expand-file-name "~/.guix-profile"))

Since nothing runs before site-start.el, I don't see how I could 
override this definition. My only choice is to use the -Q option on the 
Emacs command line to bypass site-start.el altogether. But then I don't 
get the packages from my new profile either.

Konrad.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-22 16:47 Emacs in multiple profiles Konrad Hinsen
@ 2018-03-22 21:21 ` Alex Kost
  2018-03-23  7:57   ` Konrad Hinsen
  0 siblings, 1 reply; 53+ messages in thread
From: Alex Kost @ 2018-03-22 21:21 UTC (permalink / raw)
  To: Konrad Hinsen; +Cc: help-guix

Konrad Hinsen (2018-03-22 17:47 +0100) wrote:

> Dear Guixers,
>
> Is anyone aware of a way to have different Emacs configurations
> (i.e. different add-on packages) in distinct profiles?
>
> I tried to set up a new profile with just "emacs" in it, but when I run
> that Emacs it load all the Emacs Lisp packages from my main profile. I
> traced this down to site-start.el loading guix-emacs.el, which has the
> main profile hard-coded and therefore loads all the packages from there:
>
>   (defvar guix-user-profile (expand-file-name "~/.guix-profile"))
>
> Since nothing runs before site-start.el, I don't see how I could
> override this definition. My only choice is to use the -Q option on the
> Emacs command line to bypass site-start.el altogether. But then I don't
> get the packages from my new profile either.

It's not the only choice.  You can also use "--no-site-file".  It is
also mentioned at:

https://www.gnu.org/software/guix/manual/html_node/Application-Setup.html#Emacs-Packages


-- 
Alex

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-22 21:21 ` Alex Kost
@ 2018-03-23  7:57   ` Konrad Hinsen
  2018-03-23 17:25     ` Alex Kost
  0 siblings, 1 reply; 53+ messages in thread
From: Konrad Hinsen @ 2018-03-23  7:57 UTC (permalink / raw)
  To: Alex Kost, help-guix

Hi Alex,

Alex Kost <alezost@gmail.com> writes:

>> Since nothing runs before site-start.el, I don't see how I could
>> override this definition. My only choice is to use the -Q option on the
>> Emacs command line to bypass site-start.el altogether. But then I don't
>> get the packages from my new profile either.
>
> It's not the only choice.  You can also use "--no-site-file".  It is
> also mentioned at:
>
> https://www.gnu.org/software/guix/manual/html_node/Application-Setup.html#Emacs-Packages

Right, but that's not very different from -Q: I get no start-site at all
and thus none of the Guix-installed packages. What I am looking for is a
way to get the packages that I put into the profile from which I started
Emacs.

I suspect that this could only be done via some environment variable,
analogous $PATH and others. Emacs doesn't consult any such variable, and
it seems that Guix didn't introduce one either. At least I didn't find
any.

Is this a decision made for a good reason, or just something "to be
done"? I could image guix-emacs.el consult a Guix-specific "Emacs path"
for constructing the internal load-path.

Konrad.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-23  7:57   ` Konrad Hinsen
@ 2018-03-23 17:25     ` Alex Kost
  2018-03-24 12:14       ` Konrad Hinsen
  0 siblings, 1 reply; 53+ messages in thread
From: Alex Kost @ 2018-03-23 17:25 UTC (permalink / raw)
  To: Konrad Hinsen; +Cc: help-guix

Konrad Hinsen (2018-03-23 08:57 +0100) wrote:

> Hi Alex,
>
> Alex Kost <alezost@gmail.com> writes:
>
>>> Since nothing runs before site-start.el, I don't see how I could
>>> override this definition. My only choice is to use the -Q option on the
>>> Emacs command line to bypass site-start.el altogether. But then I don't
>>> get the packages from my new profile either.
>>
>> It's not the only choice.  You can also use "--no-site-file".  It is
>> also mentioned at:
>>
>> https://www.gnu.org/software/guix/manual/html_node/Application-Setup.html#Emacs-Packages
>
> Right, but that's not very different from -Q:

It is completely different: with "-Q", your .emacs file is not loaded at
all, and with "--no-site-file", only the emacs packages from the guix
profile are not autoloaded.  Isn't that what you wanted?

> I get no start-site at all
> and thus none of the Guix-installed packages. What I am looking for is a
> way to get the packages that I put into the profile from which I started
> Emacs.
>
> I suspect that this could only be done via some environment variable,
> analogous $PATH and others. Emacs doesn't consult any such variable, and
> it seems that Guix didn't introduce one either. At least I didn't find
> any.

If you want to autoload emacs packages from a guix environment (or
similarly from any non-standard guix profile), you can do it like this:

(let ((guix-env (getenv "GUIX_ENVIRONMENT")))
  (when (and guix-env
             (require 'guix-emacs nil t))
    (guix-emacs-autoload-packages guix-env)))

> Is this a decision made for a good reason, or just something "to be
> done"?

Sorry, I don't understand your use case (I think I just didn't read your
message carefully enough), but if you think there is something to be
done, please tell.

-- 
Alex

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-23 17:25     ` Alex Kost
@ 2018-03-24 12:14       ` Konrad Hinsen
  2018-03-24 16:07         ` Alex Kost
  0 siblings, 1 reply; 53+ messages in thread
From: Konrad Hinsen @ 2018-03-24 12:14 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-guix

Alex Kost <alezost@gmail.com> writes:

> It is completely different: with "-Q", your .emacs file is not loaded at
> all, and with "--no-site-file", only the emacs packages from the guix
> profile are not autoloaded.  Isn't that what you wanted?

Not quite: I want it to autoload the packages from my current Guix
profile, not from my main Guix profile.

> If you want to autoload emacs packages from a guix environment (or
> similarly from any non-standard guix profile), you can do it like this:
>
> (let ((guix-env (getenv "GUIX_ENVIRONMENT")))
>   (when (and guix-env
>              (require 'guix-emacs nil t))
>     (guix-emacs-autoload-packages guix-env)))

Except that GUIX_ENVIRONMENT is defined only by "guix environment", not
by profiles. Otherwise this would be exactly what I want - and in fact
what I'd expect guix-emacs.el to do, instead of accessing the user's
main profile.

Konrad.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-24 12:14       ` Konrad Hinsen
@ 2018-03-24 16:07         ` Alex Kost
  2018-03-26  8:24           ` Konrad Hinsen
  2018-04-20 20:52           ` Ricardo Wurmus
  0 siblings, 2 replies; 53+ messages in thread
From: Alex Kost @ 2018-03-24 16:07 UTC (permalink / raw)
  To: Konrad Hinsen; +Cc: help-guix

Konrad Hinsen (2018-03-24 13:14 +0100) wrote:

> Alex Kost <alezost@gmail.com> writes:
>
>> It is completely different: with "-Q", your .emacs file is not loaded at
>> all, and with "--no-site-file", only the emacs packages from the guix
>> profile are not autoloaded.  Isn't that what you wanted?
>
> Not quite: I want it to autoload the packages from my current Guix
> profile, not from my main Guix profile.

But what your "current profile" is?  How can emacs know about it?  It
"knows" only about the default (system and user) profiles.  So if you
wish to load packages from non-standard profiles, you need to do it on
your own (as I showed below).

>> If you want to autoload emacs packages from a guix environment (or
>> similarly from any non-standard guix profile), you can do it like this:
>>
>> (let ((guix-env (getenv "GUIX_ENVIRONMENT")))
>>   (when (and guix-env
>>              (require 'guix-emacs nil t))
>>     (guix-emacs-autoload-packages guix-env)))
>
> Except that GUIX_ENVIRONMENT is defined only by "guix environment", not
> by profiles. Otherwise this would be exactly what I want - and in fact
> what I'd expect guix-emacs.el to do, instead of accessing the user's
> main profile.

Again, I don't understand how emacs could guess in what profile you
installed your emacs packages, so it just autoloads whatever is found in
the system and user profile.

So for your situation, you can just run emacs with --no-site-file option
and put a code like this in your emacs config file:

(when (require 'guix-emacs nil t)
  (guix-emacs-autoload-packages "/path/to/your/profile"))

-- 
Alex

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-24 16:07         ` Alex Kost
@ 2018-03-26  8:24           ` Konrad Hinsen
  2018-03-27 15:38             ` Alex Kost
  2018-04-20 20:52           ` Ricardo Wurmus
  1 sibling, 1 reply; 53+ messages in thread
From: Konrad Hinsen @ 2018-03-26  8:24 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-guix

Alex Kost <alezost@gmail.com> writes:

> But what your "current profile" is?  How can emacs know about it?  It
> "knows" only about the default (system and user) profiles.  So if you

I'd say Emacs knows nothing at all about profiles. It's Guix that
manages profiles for everyone else, be it bash, Python, or Emacs. To get
the behavior that I expected, Guix would have to define and manage an
environment variable, let's call it EMACS_PATH, which would be used in
site-start.el.

What I cannot judge is how much effort it would be to implement such a
feature, and if it could have undesirable side-effects.

Konrad.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-26  8:24           ` Konrad Hinsen
@ 2018-03-27 15:38             ` Alex Kost
  2018-04-18 19:49               ` myglc2
  0 siblings, 1 reply; 53+ messages in thread
From: Alex Kost @ 2018-03-27 15:38 UTC (permalink / raw)
  To: Konrad Hinsen; +Cc: help-guix

Konrad Hinsen (2018-03-26 10:24 +0200) wrote:

> Alex Kost <alezost@gmail.com> writes:
>
>> But what your "current profile" is?  How can emacs know about it?  It
>> "knows" only about the default (system and user) profiles.  So if you
>
> I'd say Emacs knows nothing at all about profiles. It's Guix that
> manages profiles for everyone else, be it bash, Python, or Emacs. To get
> the behavior that I expected, Guix would have to define and manage an
> environment variable, let's call it EMACS_PATH, which would be used in
> site-start.el.
>
> What I cannot judge is how much effort it would be to implement such a
> feature, and if it could have undesirable side-effects.

As for me, I think the current behaviour (looking for packages only in
the user and the system profiles) is the right one.  If you want to
auto-load emacs packages from some non-standard profiles, you can easily
do this on your own (as I showed in the previous message).

Anyway, if you think that some feature is missing, I would recommend to
send a message to <bug-guix@gnu.org> about it.  Perhaps other people
will agree with your point.

-- 
Alex

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-27 15:38             ` Alex Kost
@ 2018-04-18 19:49               ` myglc2
  2018-05-05 16:01                 ` Konrad Hinsen
  2019-10-16 19:54                 ` Pierre Neidhardt
  0 siblings, 2 replies; 53+ messages in thread
From: myglc2 @ 2018-04-18 19:49 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 2223 bytes --]

On 03/27/2018 at 18:38 Alex Kost writes:

> Konrad Hinsen (2018-03-26 10:24 +0200) wrote:
>
>> Alex Kost <alezost@gmail.com> writes:
>>
>>> But what your "current profile" is?  How can emacs know about it?  It
>>> "knows" only about the default (system and user) profiles.  So if you
>>
>> I'd say Emacs knows nothing at all about profiles. It's Guix that
>> manages profiles for everyone else, be it bash, Python, or Emacs. To get
>> the behavior that I expected, Guix would have to define and manage an
>> environment variable, let's call it EMACS_PATH, which would be used in
>> site-start.el.
>>
>> What I cannot judge is how much effort it would be to implement such a
>> feature, and if it could have undesirable side-effects.
>
> As for me, I think the current behaviour (looking for packages only in
> the user and the system profiles) is the right one.  If you want to
> auto-load emacs packages from some non-standard profiles, you can easily
> do this on your own (as I showed in the previous message).
>
> Anyway, if you think that some feature is missing, I would recommend to
> send a message to <bug-guix@gnu.org> about it.  Perhaps other people
> will agree with your point.

Hi Konrad & Alex,

I am revamping my emacs config approach and I came across your
discussion. Following Alex's suggestions I found 2 approaches that seem
to do what Konrad wanted ...

1) guix profile approach ...

guix package -m emacs.scm
emacs --no-init-file \
      --eval="\
(let ((guix-env (getenv \"GUIX_ENVIRONMENT\")))
  (when (and guix-env
             (require 'guix-emacs nil t))
    (guix-emacs-autoload-packages guix-env)))" \
      --load=".emacs.d/init0.el"
guix package --roll-back

2) guix environment approach ...

guix environment --ad-hoc emacs magit -- \
emacs --no-init-file --no-site-file \
      --eval="\
(let ((guix-env (getenv \"GUIX_ENVIRONMENT\")))
  (when (and guix-env
             (require 'guix-emacs nil t))
    (guix-emacs-autoload-packages guix-env)))" \
      --load=".emacs.d/init0.el"

For my purposes 2) is better -- It starts more quickly and doesn't
"infect" other login sessions. It also allows multiple, different,
isolated Emacs environments to run simultaneously. Sweet ;-)

- George


[-- Attachment #2: emacs.scm --]
[-- Type: application/octet-stream, Size: 147 bytes --]

(use-modules (gnu packages))
(define usr-packages
   '(
     "font-dejavu"
     "emacs"
     "magit"
   ))
(specifications->manifest usr-packages)

[-- Attachment #3: init0.el --]
[-- Type: application/emacs-lisp, Size: 125 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-03-24 16:07         ` Alex Kost
  2018-03-26  8:24           ` Konrad Hinsen
@ 2018-04-20 20:52           ` Ricardo Wurmus
  1 sibling, 0 replies; 53+ messages in thread
From: Ricardo Wurmus @ 2018-04-20 20:52 UTC (permalink / raw)
  To: Alex Kost; +Cc: help-guix


Alex Kost <alezost@gmail.com> writes:

> Konrad Hinsen (2018-03-24 13:14 +0100) wrote:
>
>> Alex Kost <alezost@gmail.com> writes:
>>
>>> It is completely different: with "-Q", your .emacs file is not loaded at
>>> all, and with "--no-site-file", only the emacs packages from the guix
>>> profile are not autoloaded.  Isn't that what you wanted?
>>
>> Not quite: I want it to autoload the packages from my current Guix
>> profile, not from my main Guix profile.
>
> But what your "current profile" is?  How can emacs know about it?

We have the variable “GUIX_PROFILE”, which may be set to use a different
profile than the default.

-- 
Ricardo

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-04-18 19:49               ` myglc2
@ 2018-05-05 16:01                 ` Konrad Hinsen
  2019-10-16 19:54                 ` Pierre Neidhardt
  1 sibling, 0 replies; 53+ messages in thread
From: Konrad Hinsen @ 2018-05-05 16:01 UTC (permalink / raw)
  To: myglc2; +Cc: Alex Kost, help-guix

Hi George,

> I am revamping my emacs config approach and I came across your
> discussion. Following Alex's suggestions I found 2 approaches that seem
> to do what Konrad wanted ...

Thanks a lot - this looks very useful. Your second solution is just fine
for my use case as well. I just wish it were simpler!

Konrad.

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2018-04-18 19:49               ` myglc2
  2018-05-05 16:01                 ` Konrad Hinsen
@ 2019-10-16 19:54                 ` Pierre Neidhardt
  2019-10-17 15:56                   ` George Clemmer
                                     ` (2 more replies)
  1 sibling, 3 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-16 19:54 UTC (permalink / raw)
  To: myglc2, Alex Kost; +Cc: help-guix

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

Hi!

I'm resurrecting this since I got bitten by this today.

I'm currently writing a blog article on profiles and manifest, and I
realized that Emacs is the only program so far that does not behave
consistently with the rest of Guix.

When I source the etc/profile where I've installed my Emacs packages,
I'd expect the appropriate environment variables to be set so that
`guix-emacs-autoload-packages' knows where to load the packages from.

I believe the solution to be simple:

1. Make Emacs packages set XDG_DATA_DIRS in etc/profile
2. guix-emacs.el: Remove guix-user-profile
3. guix-emacs.el: Set profiles to all the paths in XDG_DATA_DIRS in the
guix-emacs-autoload-packages function.

Thoughts?

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-16 19:54                 ` Pierre Neidhardt
@ 2019-10-17 15:56                   ` George Clemmer
  2019-10-18  8:42                     ` Pierre Neidhardt
  2019-10-19 19:35                   ` Maxim Cournoyer
  2019-10-20 13:58                   ` Alex Kost
  2 siblings, 1 reply; 53+ messages in thread
From: George Clemmer @ 2019-10-17 15:56 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, help-guix


Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Hi!
>
> I'm resurrecting this since I got bitten by this today.
>
> I'm currently writing a blog article on profiles and manifest, and I
> realized that Emacs is the only program so far that does not behave
> consistently with the rest of Guix.

Hi Pierre,

I think the default emacs behavior reflects tje concept of emacs and
emacs-guix as "uber-all": E.g., Installing them in the default profile
~/.guix-profile/ allows a power user to do anything.

But, if you want to work in separate, independent project profiles each
with their own manifest, profile, and custom configs, it isn't obvious
what to do. E.g., Where is the .emacs file?  Which profile do you get
when you run a shell? How do you run a version of emacs or an emacs
package other than the one installed in the default ~/.guix-profile/?
Which .emacs.d/ gets used?

> When I source the etc/profile where I've installed my Emacs packages,
> I'd expect the appropriate environment variables to be set so that
> `guix-emacs-autoload-packages' knows where to load the packages from.
>
> I believe the solution to be simple:
>
> 1. Make Emacs packages set XDG_DATA_DIRS in etc/profile
> 2. guix-emacs.el: Remove guix-user-profile
> 3. guix-emacs.el: Set profiles to all the paths in XDG_DATA_DIRS in the
> guix-emacs-autoload-packages function.
>
> Thoughts?

FWIW, I can report on how I have happily used separate, independent
guix/emacs "project" configs for over a year. For my purposes I want to
start emacs in the context of the project (e.g. use the emacs version
and packages installed in the project's profile and the associated
configurations and user data) and, by default, stay in that context.

To automate this pattern of use across multiple projects, I have a
fairly baroque set of scripts and makefiles.

The gist is that I use separate ~/$GPM_ROOT project directories each
containing their own .guix-profile -> .guix-profile, .emacs,
.bashprofile, .bashrc, & .emacs.d/

The project "run" script includes ...

bash --rcfile $GPM_ROOT/.bash_profile -i -c "$carg"

... to start the project and $GPM_ROOT/.emacs sets
explicit-shell-file-name to point to this script so emacs shells "run"
in the project.

$GPM_ROOT/.bashprofile includes ...

vvv
export GPM_ROOT=/home/glc/gom
unset GUIX_ENVIRONMENT
export GUIX_PROFILE=/home/glc/gom/.guix-profile
eval $(guix package -p $GUIX_PROFILE \
	-p /run/current-system/profile --search-paths=exact)
export PATH=/run/setuid-programs:$PATH
[...]
export PATH=$GPM_ROOT/.gpm/bin:$PATH
if [ -f /home/glc/gom/.bashrc ]; then . /home/glc/gom/.bashrc; fi
^^^

and $GPM_ROOT/.gpm/bin/emacs runs emacs this way ...
VVV
#!/bin/sh
$GPM_ROOT/.guix-profile/bin/emacs \
    --no-site-file \
    --eval='(let ((guix-env (concat (getenv "GPM_ROOT") "/.guix-profile"))) (when (and guix-env (require (quote guix-emacs) nil t)) (guix-emacs-autoload-packages guix-env)))' \
    --no-init-file \
    --eval='(setq user-emacs-directory (concat (getenv "GPM_ROOT") "/.emacs.d/"))' \
    --eval='(load (concat (getenv "GPM_ROOT") "/.emacs"))' \
    --debug-init \
    "$@"
^^^

HTH - George

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-17 15:56                   ` George Clemmer
@ 2019-10-18  8:42                     ` Pierre Neidhardt
  2019-10-18 17:13                       ` George Clemmer
  2019-10-19  8:53                       ` Pierre Neidhardt
  0 siblings, 2 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-18  8:42 UTC (permalink / raw)
  To: George Clemmer; +Cc: Alex Kost, help-guix

[-- Attachment #1: Type: text/plain, Size: 2232 bytes --]

Hi George,

thanks for you input. 

> I think the default emacs behavior reflects tje concept of emacs and
> emacs-guix as "uber-all": E.g., Installing them in the default profile
> ~/.guix-profile/ allows a power user to do anything.
>
> But, if you want to work in separate, independent project profiles each
> with their own manifest, profile, and custom configs, it isn't obvious
> what to do.

I believe it is straightforward, as for other programs with non-default
multiple profiles: if the etc/profile is sourced, behave as if it were
the default.

> E.g., Where is the .emacs file?

I'm not sure that's related, .emacs is in the user's home.

> Which profile do you get
> when you run a shell?

Which shell?

> How do you run a version of emacs or an emacs
> package other than the one installed in the default ~/.guix-profile/?

The `emacs' you run is the last one in your PATH.  This is defined by
the load-order of the profiles, as for any program.  This is not Emacs-specific.

> Which .emacs.d/ gets used?

As above, this is the user's file, this is related to the Guix profile.

>> When I source the etc/profile where I've installed my Emacs packages,
>> I'd expect the appropriate environment variables to be set so that
>> `guix-emacs-autoload-packages' knows where to load the packages from.
>>
>> I believe the solution to be simple:
>>
>> 1. Make Emacs packages set XDG_DATA_DIRS in etc/profile
>> 2. guix-emacs.el: Remove guix-user-profile
>> 3. guix-emacs.el: Set profiles to all the paths in XDG_DATA_DIRS in the
>> guix-emacs-autoload-packages function.
>>
>> Thoughts?
>
> FWIW, I can report on how I have happily used separate, independent
> guix/emacs "project" configs for over a year.

I believe we are talking about slightly different things.  Every user is
free to write their custom scripts and Emacs config to suit their needs.

The problem I'm trying to address here is that of the default behaviour
of non-default profiles (actually: profiles in general).  With
zero-config, zero-script.  I believe Emacs should behave like the rest,
i.e. load the packages of all active profiles.

Cheers!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-18  8:42                     ` Pierre Neidhardt
@ 2019-10-18 17:13                       ` George Clemmer
  2019-10-19  8:57                         ` Pierre Neidhardt
  2019-10-19  8:53                       ` Pierre Neidhardt
  1 sibling, 1 reply; 53+ messages in thread
From: George Clemmer @ 2019-10-18 17:13 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, help-guix


Hi Pierre,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Hi George,
>
> thanks for you input.
[...]
>> FWIW, I can report on how I have happily used separate, independent
>> guix/emacs "project" configs for over a year.
>
> I believe we are talking about slightly different things.  Every user is
> free to write their custom scripts and Emacs config to suit their needs.

I provided an example of how I use emacs and the _non-default behavior_
of non-default profiles that I find particularly powerful in Guix. Of
course it's not the only way to go, but I thought it might be of
interest for your article.

> The problem I'm trying to address here is that of the default behaviour
> of non-default profiles (actually: profiles in general).

It wasn't clear until the sentence above that you are limiting the
article to _default behaviour_. IMO, this is selling non-default
profiles short.  E.G. kinda like writing a blog about 'guix environment'
without mentioning '--pure'.

HTH, George

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-18  8:42                     ` Pierre Neidhardt
  2019-10-18 17:13                       ` George Clemmer
@ 2019-10-19  8:53                       ` Pierre Neidhardt
  1 sibling, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-19  8:53 UTC (permalink / raw)
  To: George Clemmer; +Cc: Alex Kost, help-guix

[-- Attachment #1: Type: text/plain, Size: 301 bytes --]

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> The `emacs' you run is the last one in your PATH.  This is defined by
> the load-order of the profiles, as for any program.  This is not Emacs-specific.

Rectification: "the first one in your PATH".

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 483 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-18 17:13                       ` George Clemmer
@ 2019-10-19  8:57                         ` Pierre Neidhardt
  0 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-19  8:57 UTC (permalink / raw)
  To: George Clemmer; +Cc: Alex Kost, help-guix

[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]

George Clemmer <myglc2@gmail.com> writes:

> I provided an example of how I use emacs and the _non-default behavior_
> of non-default profiles that I find particularly powerful in Guix. Of
> course it's not the only way to go, but I thought it might be of
> interest for your article.

Indeed, good point!

>> The problem I'm trying to address here is that of the default behaviour
>> of non-default profiles (actually: profiles in general).
>
> It wasn't clear until the sentence above that you are limiting the
> article to _default behaviour_. IMO, this is selling non-default
> profiles short.  E.G. kinda like writing a blog about 'guix environment'
> without mentioning '--pure'.

This is a good point.  Would you have example use cases that cannot be
done using the "profile default behaviour"? (Beside Emacs)

With regard to the case of Emacs, I believe that if we fix multi-profile
support, your script could be replace with a simple

--8<---------------cut here---------------start------------->8---
GUIX_PROFILE=foo && . $GUIX_PROFILE/etc/profile && emacs
--8<---------------cut here---------------end--------------->8---

Cool, nah? :)

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-16 19:54                 ` Pierre Neidhardt
  2019-10-17 15:56                   ` George Clemmer
@ 2019-10-19 19:35                   ` Maxim Cournoyer
  2019-10-19 20:19                     ` Pierre Neidhardt
  2019-10-20 13:58                   ` Alex Kost
  2 siblings, 1 reply; 53+ messages in thread
From: Maxim Cournoyer @ 2019-10-19 19:35 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix

Hi Pierre,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Hi!
>
> I'm resurrecting this since I got bitten by this today.
>
> I'm currently writing a blog article on profiles and manifest, and I
> realized that Emacs is the only program so far that does not behave
> consistently with the rest of Guix.
>
> When I source the etc/profile where I've installed my Emacs packages,
> I'd expect the appropriate environment variables to be set so that
> `guix-emacs-autoload-packages' knows where to load the packages from.
>
> I believe the solution to be simple:
>
> 1. Make Emacs packages set XDG_DATA_DIRS in etc/profile
> 2. guix-emacs.el: Remove guix-user-profile
> 3. guix-emacs.el: Set profiles to all the paths in XDG_DATA_DIRS in the
> guix-emacs-autoload-packages function.
>
> Thoughts?

Maybe it is just my ignorance about XDG_DATA_DIRS, but, wouldn't it be
more natural to use Emacs native mean of finding packages, akin to
Python's PYTHONPATH?  Emacs has the EMACSLOADPATH for this; per the
Emacs manual:

‘EMACSLOADPATH’
     A colon-separated list of directories(1) to search for Emacs Lisp
     files.  If set, it modifies the usual initial value of the
     ‘load-path’ variable (*note Lisp Libraries::).  An empty element
     stands for the default value of ‘load-path’; e.g., using
     ‘EMACSLOADPATH="/tmp:"’ adds ‘/tmp’ to the front of the default
     ‘load-path’.  To specify an empty element in the middle of the
     list, use 2 colons in a row, as in ‘EMACSLOADPATH="/tmp::/foo"’.

The neat thing about this is that we can use the native Guix mechanism
of 'search-paths', defined on the Emacs package, that would take care of
collecting all the Emacs Lisp packages used in a profile.

I had a working branch implementing this a long time ago; I could try
reviving it if you have an interested in it.  The one thing I didn't
like about it was I had to use a loose regexp in the path to accomodate
with the somewhat loose directory under which the libraries can be
installed (share/emacs/site-lisp vs
share/emacs/site-lisp/guix.d/package-name-version).

But it was working well, and allowed declaring a profile with emacs and
the wanted libraries, and having just these available within the
profile.

Maxim

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-19 19:35                   ` Maxim Cournoyer
@ 2019-10-19 20:19                     ` Pierre Neidhardt
  2019-10-25  3:05                       ` Maxim Cournoyer
  0 siblings, 1 reply; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-19 20:19 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 631 bytes --]


Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> Maybe it is just my ignorance about XDG_DATA_DIRS, but, wouldn't it be
> more natural to use Emacs native mean of finding packages, akin to
> Python's PYTHONPATH?  Emacs has the EMACSLOADPATH for this; per the
> Emacs manual:

Well, I'd say it's my ignorance, not yours!

> I had a working branch implementing this a long time ago; I could try
> reviving it if you have an interested in it.

This seems to be the right thing to do, I'd say go ahead, I'd be happy
to review / test / send feedback for your patch!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-16 19:54                 ` Pierre Neidhardt
  2019-10-17 15:56                   ` George Clemmer
  2019-10-19 19:35                   ` Maxim Cournoyer
@ 2019-10-20 13:58                   ` Alex Kost
  2019-10-20 16:17                     ` Pierre Neidhardt
  2 siblings, 1 reply; 53+ messages in thread
From: Alex Kost @ 2019-10-20 13:58 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: myglc2, help-guix

Pierre Neidhardt (2019-10-16 21:54 +0200) wrote:

> Hi!
>
> I'm resurrecting this since I got bitten by this today.
>
> I'm currently writing a blog article on profiles and manifest, and I
> realized that Emacs is the only program so far that does not behave
> consistently with the rest of Guix.
>
> When I source the etc/profile where I've installed my Emacs packages,
> I'd expect the appropriate environment variables to be set so that
> `guix-emacs-autoload-packages' knows where to load the packages from.
>
> I believe the solution to be simple:
>
> 1. Make Emacs packages set XDG_DATA_DIRS in etc/profile
> 2. guix-emacs.el: Remove guix-user-profile
> 3. guix-emacs.el: Set profiles to all the paths in XDG_DATA_DIRS in the
> guix-emacs-autoload-packages function.
>
> Thoughts?

Hello, I'm not sure if my answer was expected, so just in case:
Please do whatever looks appropriate to you :-)

-- 
Alex

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-20 13:58                   ` Alex Kost
@ 2019-10-20 16:17                     ` Pierre Neidhardt
  0 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-20 16:17 UTC (permalink / raw)
  To: Alex Kost; +Cc: myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 222 bytes --]

Alex Kost <alezost@gmail.com> writes:

> Hello, I'm not sure if my answer was expected, so just in case:
> Please do whatever looks appropriate to you :-)

Thanks! :)

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-19 20:19                     ` Pierre Neidhardt
@ 2019-10-25  3:05                       ` Maxim Cournoyer
  2019-10-25 11:21                         ` Pierre Neidhardt
  0 siblings, 1 reply; 53+ messages in thread
From: Maxim Cournoyer @ 2019-10-25  3:05 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 1123 bytes --]

Hello Pierre,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>
>> Maybe it is just my ignorance about XDG_DATA_DIRS, but, wouldn't it be
>> more natural to use Emacs native mean of finding packages, akin to
>> Python's PYTHONPATH?  Emacs has the EMACSLOADPATH for this; per the
>> Emacs manual:
>
> Well, I'd say it's my ignorance, not yours!
>
>> I had a working branch implementing this a long time ago; I could try
>> reviving it if you have an interested in it.
>
> This seems to be the right thing to do, I'd say go ahead, I'd be happy
> to review / test / send feedback for your patch!

I've thought some more about this, and perhaps such a simple change the
patch attached could do?  It's late and I haven't tried it yet, sorry.
Will try it out later.  You'll have to rebuild just Emacs and the Emacs
packages you use.

Various cleanups could be undertaken in both Guix (no longer need the
set-emacsloadpath phase in the emacs-build-system) and Emacs-Guix (no
need for custom logic looking into ~/.guix-profile) and perhaps other
places should this get merged.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnu-emacs-Locate-Elisp-libraries-via-EMACSLOADPATH.patch --]
[-- Type: text/x-patch, Size: 1143 bytes --]

From 809bdcc447557134fbf4278c3b0d4b7d186d190d Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sat, 3 Jun 2017 12:56:36 -0700
Subject: [PATCH] gnu: emacs: Locate Elisp libraries via EMACSLOADPATH.

* gnu/packages/emacs.scm (emacs): Add a search path specification for
EMACSLOADPATH.
---
 gnu/packages/emacs.scm | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 6c6f0e4567..0831dd575a 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -185,6 +185,13 @@
 
     (native-search-paths
      (list (search-path-specification
+            (variable "EMACSLOADPATH")
+            ;; The versioned entries are for Emacs builtin libraries.
+            (files `(,(string-append "share/emacs/" version "/site-lisp/")
+                     ,(string-append "share/emacs/" version "/lisp/")
+                     "share/emacs/site-lisp/"))
+            (file-pattern ".*"))        ;recursively add any sub directory
+           (search-path-specification
             (variable "INFOPATH")
             (files '("share/info")))))
 
-- 
2.23.0


[-- Attachment #3: Type: text/plain, Size: 358 bytes --]


Maxim

--
This is perhaps obsoleted by the above, but feel free to study

Here is a branch of the two commits, based off master:
https://gitlab.com/Apteryks/guix/tree/guixify-emacs-packages-discovery.

Sadly, this is a world rebuilding change, due to having extended the
search-path-specification record so that it supported declaring a
trailing separator.

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-25  3:05                       ` Maxim Cournoyer
@ 2019-10-25 11:21                         ` Pierre Neidhardt
  2019-10-28  3:45                           ` Maxim Cournoyer
                                             ` (2 more replies)
  0 siblings, 3 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-25 11:21 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 5801 bytes --]

Looking good!

I just tried to install Emacs to a dummy profile with your patch.
Here is the result (with ":" replaced by line breaks):

--8<---------------cut here---------------start------------->8---
...
export EMACSLOADPATH=\
"${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/site-lisp/
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp/
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//calc
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//calendar
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/ede
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/analyze
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/bovine
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/decorate
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/symref
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/wisent
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/srecode
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//emacs-lisp
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//emulation
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//erc
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//eshell
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//gnus
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//image
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//international
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//language
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//leim
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//leim/ja-dic
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//leim/quail
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//mail
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//mh-e
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//net
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//nxml
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//obsolete
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//org
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//play
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//progmodes
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//term
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//textmodes
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//url
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//vc
${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/site-lisp/${EMACSLOADPATH:+:}$EMACSLOADPATH"
export ...
--8<---------------cut here---------------end--------------->8---

Then I did

--8<---------------cut here---------------start------------->8---
/home/ambrevar/projects/guix/pre-inst-env guix environment --ad-hoc emacs emacs-expand-region -- emacs -q
--8<---------------cut here---------------end--------------->8---

And I get Emacs with expand region functions, but since GUIX_ENVIRONMENT
is still effective, it's unclear what loads it.

So it seems to be the right approach, let's keep testing!

With regard to the "cleanups" you mentioned:

> Various cleanups could be undertaken in both Guix (no longer need the
> set-emacsloadpath phase in the emacs-build-system) and Emacs-Guix (no
> need for custom logic looking into ~/.guix-profile) and perhaps other
> places should this get merged.

Shall we keep guix-emacs.el (and site-start.el) at all?

What guix-emacs.el does if I'm not mistaken:

- Find autoloads: Would we still need this then?  I'm not sure.  If
  not, then it would be great to remove this because finding-autoload
  linearly increases Emacs loading time.

- Find packages in GUIX_ENVIRONMENT: I suppose we don't need this since
  EMACSLOADPATH should be in the `guix environment' as well.

- Find packages in "/run/current-system/profile": The approach used by
  other programs at the moment is to do this in /etc/profile, e.g.

--8<---------------cut here---------------start------------->8---
export MANPATH=\
$HOME/.guix-profile/share/man\
:/run/current-system/profile/share/man
--8<---------------cut here---------------end--------------->8---

Seems to me that we can remove guix-emacs.el and site-start.el.

Cheers!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-25 11:21                         ` Pierre Neidhardt
@ 2019-10-28  3:45                           ` Maxim Cournoyer
  2019-10-28  7:49                             ` Pierre Neidhardt
  2019-10-28 12:46                           ` Maxim Cournoyer
  2019-10-29  1:25                           ` Maxim Cournoyer
  2 siblings, 1 reply; 53+ messages in thread
From: Maxim Cournoyer @ 2019-10-28  3:45 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix

Hello Pierre,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Looking good!
>
> I just tried to install Emacs to a dummy profile with your patch.
> Here is the result (with ":" replaced by line breaks):
>
> ...
> export EMACSLOADPATH=\
> "${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/site-lisp/
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp/
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//calc
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//calendar
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/ede
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/analyze
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/bovine
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/decorate
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/symref
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/semantic/wisent
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//cedet/srecode
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//emacs-lisp
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//emulation
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//erc
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//eshell
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//gnus
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//image
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//international
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//language
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//leim
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//leim/ja-dic
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//leim/quail
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//mail
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//mh-e
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//net
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//nxml
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//obsolete
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//org
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//play
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//progmodes
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//term
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//textmodes
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//url
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/26.3/lisp//vc
> ${GUIX_PROFILE:-/gnu/store/g5371rkr7k5j6n5gmg0a8bhspsdfnjvy-profile}/share/emacs/site-lisp/${EMACSLOADPATH:+:}$EMACSLOADPATH"
> export ...
>
>
> Then I did
>
> /home/ambrevar/projects/guix/pre-inst-env guix environment --ad-hoc emacs emacs-expand-region -- emacs -q
>
>
> And I get Emacs with expand region functions, but since GUIX_ENVIRONMENT
> is still effective, it's unclear what loads it.

I'm not sure I understand correctly, but perhaps you'd want to use
--pure, so to make sure nothing from your current environment
interferes?

But that's still leave site-start.el to look into ~/.guix-profile, I
believe.  You could also try with emacs-minimal, which doesn't have any
of the emacs-guix additions.

> So it seems to be the right approach, let's keep testing!
>
> With regard to the "cleanups" you mentioned:
>
>> Various cleanups could be undertaken in both Guix (no longer need the
>> set-emacsloadpath phase in the emacs-build-system) and Emacs-Guix (no
>> need for custom logic looking into ~/.guix-profile) and perhaps other
>> places should this get merged.
>
> Shall we keep guix-emacs.el (and site-start.el) at all?
>
> What guix-emacs.el does if I'm not mistaken:
>
> - Find autoloads: Would we still need this then?  I'm not sure.  If
>   not, then it would be great to remove this because finding-autoload
>   linearly increases Emacs loading time.
>
> - Find packages in GUIX_ENVIRONMENT: I suppose we don't need this since
>   EMACSLOADPATH should be in the `guix environment' as well.
>
> - Find packages in "/run/current-system/profile": The approach used by
>   other programs at the moment is to do this in /etc/profile, e.g.
>
> export MANPATH=\
> $HOME/.guix-profile/share/man\
> :/run/current-system/profile/share/man
>
> Seems to me that we can remove guix-emacs.el and site-start.el.
>
> Cheers!

I also think we can do without these!  I'm rebuilding Emacs with a new
patch; will share for testing it if works okay.

Alex: I think you'll want to adapt/remove the code in Emacs-Guix which
is used to locate the Emacs libraries installed using Guix, since they'd
now be available directly to Emacs (through EMACSLOADPATH).  Of course,
to be done only after discussed patch is merged :-).

Thanks for testing!

Maxim

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-28  3:45                           ` Maxim Cournoyer
@ 2019-10-28  7:49                             ` Pierre Neidhardt
  0 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-28  7:49 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 1892 bytes --]

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> I'm not sure I understand correctly, but perhaps you'd want to use
> --pure, so to make sure nothing from your current environment
> interferes?
>
> But that's still leave site-start.el to look into ~/.guix-profile, I
> believe.  You could also try with emacs-minimal, which doesn't have any
> of the emacs-guix additions.

site-start.el loads guix-emacs.el, which in turn runs this piece of
code:

--8<---------------cut here---------------start------------->8---
(defun guix-emacs-autoload-packages (&rest profiles)
  "Autoload Emacs packages installed in PROFILES.
If PROFILES are not specified, use a default user and system
profiles.

'Autoload' means add directories with Emacs packages to
`load-path' and load 'autoloads' files matching
`guix-emacs-autoloads-regexp'."
  (interactive (list (if (fboundp 'guix-read-package-profile)
                         (funcall 'guix-read-package-profile)
                       guix-user-profile)))
  (let* ((env      (getenv "GUIX_ENVIRONMENT"))
         (profiles (or profiles
                       (append (list "/run/current-system/profile"
                                     guix-user-profile)
                               (and env (list env))))))
    (dolist (profile profiles)
      ...)))
--8<---------------cut here---------------end--------------->8---

As you can see, the GUIX_ENVIRONMENT is scanned for Emacs packages.  So
my test is moot.

Now I'm realizing I could have tested a smarted way:

- Make sure ~/.guix-profile does not have the packages being tested
  (e.g. expand-region here).
- Install patched Emacs + tested package to a new profile FOO.
- Source `FOO/etc/profile`.
- Run `FOO/bin/emacs` and see if the package is found.

Anyways, waiting for your next patch! :)

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-25 11:21                         ` Pierre Neidhardt
  2019-10-28  3:45                           ` Maxim Cournoyer
@ 2019-10-28 12:46                           ` Maxim Cournoyer
  2019-10-29  1:25                           ` Maxim Cournoyer
  2 siblings, 0 replies; 53+ messages in thread
From: Maxim Cournoyer @ 2019-10-28 12:46 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 176 bytes --]

Hello Pierre,

I just made the following patches to remove the custom site-start.el we
had in our Emacs package, but this seems to break autoloading.

To be continued.

Maxim


[-- Attachment #2: 0001-gnu-emacs-Locate-Elisp-libraries-via-EMACSLOADPATH.patch --]
[-- Type: text/x-patch, Size: 1707 bytes --]

From 518b529fec93b8a767655f54e32aadade19da89f Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sat, 3 Jun 2017 12:56:36 -0700
Subject: [PATCH 1/3] gnu: emacs: Locate Elisp libraries via EMACSLOADPATH.

* gnu/packages/emacs.scm (emacs): Add a search path specification for
EMACSLOADPATH.
---
 gnu/packages/emacs.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 6c6f0e4567..a4ded4dbb9 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -9,7 +9,7 @@
 ;;; Copyright © 2016 David Thompson <dthompson2@worcester.edu>
 ;;; Copyright © 2016 ng0 <ng0@n0.is>
 ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
-;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2017, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2017 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
@@ -185,6 +185,13 @@
 
     (native-search-paths
      (list (search-path-specification
+            (variable "EMACSLOADPATH")
+            ;; The versioned entries are for the Emacs' builtin libraries.
+            (files `(,(string-append "share/emacs/" version "/site-lisp")
+                     ,(string-append "share/emacs/" version "/lisp")
+                     "share/emacs/site-lisp"))
+            (file-pattern ".*"))        ;recursively add any sub directory
+           (search-path-specification
             (variable "INFOPATH")
             (files '("share/info")))))
 
-- 
2.23.0


[-- Attachment #3: 0002-gnu-emacs-Remove-custom-guix-emacs-code.patch --]
[-- Type: text/x-patch, Size: 8240 bytes --]

From fe39bda4f2b6f8be433f8c89d80a6900e5732182 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sun, 27 Oct 2019 23:26:51 -0400
Subject: [PATCH 2/3] gnu: emacs: Remove custom guix-emacs code.

This used to be necessary to find the Elisp library modules, but is no longer
the case.  The environment variable EMACSLOADPATH/search path specification is
now used for that purpose.

* gnu/packages/aux-files/emacs/guix-emacs.el: Remove file.
* Makefile.am (AUX_FILES): Unregister it.
* gnu/packages/emacs.scm (emacs)[phases]: Remove the 'install-site-start
phase.
[native-inputs]: Remove the "guix-emacs.el" input.
---
 Makefile.am                                |   1 -
 gnu/packages/aux-files/emacs/guix-emacs.el | 115 ---------------------
 gnu/packages/emacs.scm                     |  21 +---
 3 files changed, 2 insertions(+), 135 deletions(-)
 delete mode 100644 gnu/packages/aux-files/emacs/guix-emacs.el

diff --git a/Makefile.am b/Makefile.am
index 36767c2f47..2a4431b2c2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -315,7 +315,6 @@ dist_noinst_DATA =				\
 # Auxiliary files for packages.
 AUX_FILES =						\
   gnu/packages/aux-files/chromium/master-preferences.json		\
-  gnu/packages/aux-files/emacs/guix-emacs.el		\
   gnu/packages/aux-files/linux-libre/5.3-arm.conf	\
   gnu/packages/aux-files/linux-libre/5.3-arm-veyron.conf       \
   gnu/packages/aux-files/linux-libre/5.3-arm64.conf	\
diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
deleted file mode 100644
index 9a49e8861c..0000000000
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ /dev/null
@@ -1,115 +0,0 @@
-;;; guix-emacs.el --- Emacs packages installed with Guix
-
-;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
-;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
-
-;; This file is part of GNU Guix.
-
-;; GNU Guix is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Guix is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; This file provides auxiliary code to autoload Emacs packages
-;; installed with Guix.
-
-;;; Code:
-
-(require 'cl-lib)
-
-(defvar guix-user-profile (expand-file-name "~/.guix-profile"))
-
-(defvar guix-emacs-autoloads nil
-  "List of the last loaded Emacs autoloads.")
-
-(defvar guix-emacs-autoloads-regexp
-  (rx (group (* any) "-autoloads")
-      ".el" (zero-or-one "c") string-end)
-  "Regexp to match Emacs 'autoloads' file.")
-
-(defun guix-emacs-directory (&optional profile)
-  "Return directory with Emacs packages installed in PROFILE.
-If PROFILE is nil, use `guix-user-profile'."
-  (expand-file-name "share/emacs/site-lisp"
-                    (or profile guix-user-profile)))
-
-(defun guix-emacs-find-autoloads (directory)
-  "Return a list of Emacs 'autoloads' files in DIRECTORY.
-The files in the list do not have extensions (.el, .elc)."
-  (cl-remove-duplicates
-   (delq nil
-        (mapcar (lambda (file)
-                  (when (string-match guix-emacs-autoloads-regexp file)
-                    (match-string 1 file)))
-                (directory-files directory 'full-name nil 'no-sort)))
-   :test #'string=))
-
-(defun guix-emacs-subdirs (directory)
-  "Return list of DIRECTORY subdirectories."
-  (cl-remove-if (lambda (file)
-                  (or (string-match-p (rx "/." string-end) file)
-                      (string-match-p (rx "/.." string-end) file)
-                      (not (file-directory-p file))))
-                (directory-files directory 'full-name nil 'no-sort)))
-
-(defun guix-emacs-directories (&optional profile)
-  "Return the list of directories under PROFILE that contain Emacs packages.
-This includes both `share/emacs/site-lisp/guix.d/PACKAGE'
-sub-directories and `share/emacs/site-lisp' itself.
-
-If PROFILE is nil, use `guix-user-profile'.
-Return nil, if Emacs packages are not installed in PROFILE."
-  (let ((root-dir (guix-emacs-directory (or profile guix-user-profile))))
-    (when (file-directory-p root-dir)
-      (let* ((pkgs-dir  (expand-file-name "guix.d" root-dir))
-             (pkgs-dirs (when (file-directory-p pkgs-dir)
-                          (guix-emacs-subdirs pkgs-dir))))
-        (cons root-dir pkgs-dirs)))))
-
-;;;###autoload
-(defun guix-emacs-autoload-packages (&rest profiles)
-  "Autoload Emacs packages installed in PROFILES.
-If PROFILES are not specified, use a default user and system
-profiles.
-
-'Autoload' means add directories with Emacs packages to
-`load-path' and load 'autoloads' files matching
-`guix-emacs-autoloads-regexp'."
-  (interactive (list (if (fboundp 'guix-read-package-profile)
-                         (funcall 'guix-read-package-profile)
-                       guix-user-profile)))
-  (let* ((env      (getenv "GUIX_ENVIRONMENT"))
-         (profiles (or profiles
-                       (append (list "/run/current-system/profile"
-                                     guix-user-profile)
-                               (and env (list env))))))
-    (dolist (profile profiles)
-      (let ((dirs (guix-emacs-directories profile)))
-        (when dirs
-          (let* ((autoloads     (cl-mapcan #'guix-emacs-find-autoloads
-                                           dirs))
-                 (new-autoloads (cl-nset-difference autoloads
-                                                    guix-emacs-autoloads
-                                                    :test #'string=)))
-            (dolist (dir dirs)
-              (cl-pushnew (directory-file-name dir)
-                          load-path
-                          :test #'string=))
-            (dolist (file new-autoloads)
-              (load file 'noerror))
-            (setq guix-emacs-autoloads
-                  (append new-autoloads guix-emacs-autoloads))))))))
-
-(provide 'guix-emacs)
-
-;;; guix-emacs.el ends here
diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index a4ded4dbb9..23361d7341 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -127,23 +127,7 @@
              (substitute* (find-files "." "^Makefile\\.in$")
                (("/bin/pwd")
                 "pwd"))
-             #t))
-         (add-after 'install 'install-site-start
-           ;; Use 'guix-emacs' in "site-start.el".  This way, Emacs packages
-           ;; provided by Guix and installed in
-           ;; ~/.guix-profile/share/emacs/site-lisp/guix.d/PACKAGE-VERSION are
-           ;; automatically found.
-           (lambda* (#:key inputs outputs #:allow-other-keys)
-             (let* ((out      (assoc-ref outputs "out"))
-                    (lisp-dir (string-append out "/share/emacs/site-lisp")))
-               (copy-file (assoc-ref inputs "guix-emacs.el")
-                          (string-append lisp-dir "/guix-emacs.el"))
-               (with-output-to-file (string-append lisp-dir "/site-start.el")
-                 (lambda ()
-                   (display
-                    (string-append "(when (require 'guix-emacs nil t)\n"
-                                   "  (guix-emacs-autoload-packages))\n"))))
-               #t))))))
+             #t)))))
     (inputs
      `(("gnutls" ,gnutls)
        ("ncurses" ,ncurses)
@@ -179,8 +163,7 @@
        ("libotf" ,libotf)
        ("m17n-lib" ,m17n-lib)))
     (native-inputs
-     `(("guix-emacs.el" ,(search-auxiliary-file "emacs/guix-emacs.el"))
-       ("pkg-config" ,pkg-config)
+     `(("pkg-config" ,pkg-config)
        ("texinfo" ,texinfo)))
 
     (native-search-paths
-- 
2.23.0


[-- Attachment #4: 0003-build-system-emacs-Simplify-the-SET-EMACS-LOAD-PATH-.patch --]
[-- Type: text/x-patch, Size: 3998 bytes --]

From 1905a04b4495481991058a75469f2808cbb47bae Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Mon, 28 Oct 2019 08:09:03 -0400
Subject: [PATCH 3/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
 phase.

It is no longer necessary to search for the Elisp libraries manually, as Emacs
now include a search path specification serving that purpose.

* guix/build/emacs-build-system.scm (set-emacs-load-path): Replace by...
(add-source-to-load-path): ...this.
(%standard-phases): Adjust accordingly.
---
 guix/build/emacs-build-system.scm | 42 ++++++-------------------------
 1 file changed, 8 insertions(+), 34 deletions(-)

diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm
index 47a9eda9e6..5cd5e7656c 100644
--- a/guix/build/emacs-build-system.scm
+++ b/guix/build/emacs-build-system.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
 ;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
-;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -74,40 +74,14 @@ archive, a directory, or an Emacs Lisp file."
         #t)
       (gnu:unpack #:source source)))
 
-(define* (set-emacs-load-path #:key source inputs #:allow-other-keys)
-  (define (inputs->directories inputs)
-    "Extract the directory part from INPUTS."
-    (match inputs
-      (((names . directories) ...) directories)))
-
-  (define (input-directory->el-directory input-directory)
-    "Return the correct Emacs Lisp directory in INPUT-DIRECTORY or #f, if there
-is no Emacs Lisp directory."
-    (let ((legacy-elisp-directory (string-append input-directory %legacy-install-suffix))
-          (guix-elisp-directory
-           (string-append
-            input-directory %install-suffix "/"
-            (store-directory->elpa-name-version input-directory))))
-      (cond
-       ((file-exists? guix-elisp-directory) guix-elisp-directory)
-       ((file-exists? legacy-elisp-directory) legacy-elisp-directory)
-       (else #f))))
-
-  (define (input-directories->el-directories input-directories)
-    "Return the list of Emacs Lisp directories in INPUT-DIRECTORIES."
-    (filter-map input-directory->el-directory input-directories))
-
-  "Set the EMACSLOADPATH environment variable so that dependencies are found."
+(define* (add-source-to-load-path #:allow-other-keys)
+  "Augment the EMACSLOADPATH environment variable with the source directory."
   (let* ((source-directory (getcwd))
-         (input-elisp-directories (input-directories->el-directories
-                                   (inputs->directories inputs)))
-         (emacs-load-path-value
-          (string-join
-           (append input-elisp-directories (list source-directory))
-           ":" 'suffix)))
+         (emacs-load-path-value (string-join (getenv "EMACSLOADPATH") ":"
+                                             source-directory)))
     (setenv "EMACSLOADPATH" emacs-load-path-value)
-    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
-            emacs-load-path-value)))
+    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
+environment variable\n" source-directory)))
 
 (define* (build #:key outputs inputs #:allow-other-keys)
   "Compile .el files."
@@ -269,7 +243,7 @@ second hyphen.  This corresponds to 'name-version' as used in ELPA packages."
 (define %standard-phases
   (modify-phases gnu:%standard-phases
     (replace 'unpack unpack)
-    (add-after 'unpack 'set-emacs-load-path set-emacs-load-path)
+    (add-after 'unpack 'add-source-to-load-path add-source-to-load-path)
     (delete 'bootstrap)
     (delete 'configure)
     ;; Move the build phase after install: the .el files are byte compiled
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-25 11:21                         ` Pierre Neidhardt
  2019-10-28  3:45                           ` Maxim Cournoyer
  2019-10-28 12:46                           ` Maxim Cournoyer
@ 2019-10-29  1:25                           ` Maxim Cournoyer
  2019-10-29 10:44                             ` Pierre Neidhardt
  2 siblings, 1 reply; 53+ messages in thread
From: Maxim Cournoyer @ 2019-10-29  1:25 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 127 bytes --]

I sent a patch earlier that had unstaged changes... So I'm sorry if you
tried it but it was broken.

Here's a functional one.


[-- Attachment #2: 0001-build-system-emacs-Simplify-the-SET-EMACS-LOAD-PATH-.patch --]
[-- Type: text/x-patch, Size: 4008 bytes --]

From 1007969505b450fe12284bf81751ae6de25c367e Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Mon, 28 Oct 2019 08:09:03 -0400
Subject: [PATCH] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH phase.

It is no longer necessary to search for the Elisp libraries manually, as Emacs
now include a search path specification serving that purpose.

* guix/build/emacs-build-system.scm (set-emacs-load-path): Replace by...
(add-source-to-load-path): ...this.
(%standard-phases): Adjust accordingly.
---
 guix/build/emacs-build-system.scm | 42 ++++++-------------------------
 1 file changed, 8 insertions(+), 34 deletions(-)

diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm
index 47a9eda9e6..f0c41812f1 100644
--- a/guix/build/emacs-build-system.scm
+++ b/guix/build/emacs-build-system.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
 ;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
-;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -74,40 +74,14 @@ archive, a directory, or an Emacs Lisp file."
         #t)
       (gnu:unpack #:source source)))
 
-(define* (set-emacs-load-path #:key source inputs #:allow-other-keys)
-  (define (inputs->directories inputs)
-    "Extract the directory part from INPUTS."
-    (match inputs
-      (((names . directories) ...) directories)))
-
-  (define (input-directory->el-directory input-directory)
-    "Return the correct Emacs Lisp directory in INPUT-DIRECTORY or #f, if there
-is no Emacs Lisp directory."
-    (let ((legacy-elisp-directory (string-append input-directory %legacy-install-suffix))
-          (guix-elisp-directory
-           (string-append
-            input-directory %install-suffix "/"
-            (store-directory->elpa-name-version input-directory))))
-      (cond
-       ((file-exists? guix-elisp-directory) guix-elisp-directory)
-       ((file-exists? legacy-elisp-directory) legacy-elisp-directory)
-       (else #f))))
-
-  (define (input-directories->el-directories input-directories)
-    "Return the list of Emacs Lisp directories in INPUT-DIRECTORIES."
-    (filter-map input-directory->el-directory input-directories))
-
-  "Set the EMACSLOADPATH environment variable so that dependencies are found."
+(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
+  "Augment the EMACSLOADPATH environment variable with the source directory."
   (let* ((source-directory (getcwd))
-         (input-elisp-directories (input-directories->el-directories
-                                   (inputs->directories inputs)))
-         (emacs-load-path-value
-          (string-join
-           (append input-elisp-directories (list source-directory))
-           ":" 'suffix)))
+         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
+                                               source-directory)))
     (setenv "EMACSLOADPATH" emacs-load-path-value)
-    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
-            emacs-load-path-value)))
+    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
+environment variable\n" source-directory)))
 
 (define* (build #:key outputs inputs #:allow-other-keys)
   "Compile .el files."
@@ -269,7 +243,7 @@ second hyphen.  This corresponds to 'name-version' as used in ELPA packages."
 (define %standard-phases
   (modify-phases gnu:%standard-phases
     (replace 'unpack unpack)
-    (add-after 'unpack 'set-emacs-load-path set-emacs-load-path)
+    (add-after 'unpack 'add-source-to-load-path add-source-to-load-path)
     (delete 'bootstrap)
     (delete 'configure)
     ;; Move the build phase after install: the .el files are byte compiled
-- 
2.23.0


[-- Attachment #3: Type: text/plain, Size: 270 bytes --]


I'll rework the 'gnu: emacs: Remove custom guix-emacs code.' patch, as
removing it means losing having the autoloads definitions loaded.
Someone in the #emacs channel suggested making use of the builtin
package.el code to take care of this.  To be continued :-)

Maxim

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-29  1:25                           ` Maxim Cournoyer
@ 2019-10-29 10:44                             ` Pierre Neidhardt
  2019-10-31  5:29                               ` Maxim Cournoyer
  0 siblings, 1 reply; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-29 10:44 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 809 bytes --]

Great work, looks like you are getting close to the finish line! :)

> I'll rework the 'gnu: emacs: Remove custom guix-emacs code.' patch, as
> removing it means losing having the autoloads definitions loaded.
> Someone in the #emacs channel suggested making use of the builtin
> package.el code to take care of this.  To be continued :-)

Indeed, this is the normal workflow using package.el.  See
https://melpa.org/: the user is expected to call `package-initialize`
from their init file.

So the solution is quite simple I believe: add

--8<---------------cut here---------------start------------->8---
(require 'package)
(package-initialize)
--8<---------------cut here---------------end--------------->8---

to site-start.el.

Cheers!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-29 10:44                             ` Pierre Neidhardt
@ 2019-10-31  5:29                               ` Maxim Cournoyer
  2019-10-31 12:29                                 ` Pierre Neidhardt
  0 siblings, 1 reply; 53+ messages in thread
From: Maxim Cournoyer @ 2019-10-31  5:29 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 1145 bytes --]

Hello!

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Great work, looks like you are getting close to the finish line! :)
>
>> I'll rework the 'gnu: emacs: Remove custom guix-emacs code.' patch, as
>> removing it means losing having the autoloads definitions loaded.
>> Someone in the #emacs channel suggested making use of the builtin
>> package.el code to take care of this.  To be continued :-)
>
> Indeed, this is the normal workflow using package.el.  See
> https://melpa.org/: the user is expected to call `package-initialize`
> from their init file.
>
> So the solution is quite simple I believe: add
>
> (require 'package)
> (package-initialize)

I tried calling this in my environment where EMACSLOADPATH was defined
(after launching emacs with "emacs -Q" to make sure the actual
site-start.el had not run), and it had no effect.

Looking at 'package.el' source code, it seems to expect directories for
the packages.  It could probably be workable, but in the meantime I've
hacked the existing site-start.el to do what is needed.

Doing so I've also speeded up loading of autoloads by 2-3 times :-).

Comments/testing welcome!

Maxim

[-- Attachment #2: 0001-gnu-emacs-Locate-Elisp-libraries-via-EMACSLOADPATH.patch --]
[-- Type: text/x-patch, Size: 1717 bytes --]

From d5dc7fd8a2406939346b44457859764a98afece0 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sat, 3 Jun 2017 12:56:36 -0700
Subject: [PATCH 1/3] gnu: emacs: Locate Elisp libraries via EMACSLOADPATH.

* gnu/packages/emacs.scm (emacs): Add a search path specification for
EMACSLOADPATH.
---
 gnu/packages/emacs.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 6c6f0e4567..16f9af0a0a 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -9,7 +9,7 @@
 ;;; Copyright © 2016 David Thompson <dthompson2@worcester.edu>
 ;;; Copyright © 2016 ng0 <ng0@n0.is>
 ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
-;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2017, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2017 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
@@ -185,6 +185,13 @@
 
     (native-search-paths
      (list (search-path-specification
+            (variable "EMACSLOADPATH")
+            ;; The versioned entries are for the Emacs' builtin libraries.
+            (files (list (string-append "share/emacs/" version "/site-lisp")
+                         (string-append "share/emacs/" version "/lisp")
+                         "share/emacs/site-lisp"))
+            (file-pattern ".*"))        ;recursively add any sub directory
+           (search-path-specification
             (variable "INFOPATH")
             (files '("share/info")))))
 
-- 
2.23.0


[-- Attachment #3: 0002-build-system-emacs-Simplify-the-SET-EMACS-LOAD-PATH-.patch --]
[-- Type: text/x-patch, Size: 4014 bytes --]

From 9c4897347bee7f3b6afb97a6c766d57f0bee1b9d Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Mon, 28 Oct 2019 08:09:03 -0400
Subject: [PATCH 2/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
 phase.

It is no longer necessary to search for the Elisp libraries manually, as Emacs
now include a search path specification serving that purpose.

* guix/build/emacs-build-system.scm (set-emacs-load-path): Replace by...
(add-source-to-load-path): ...this.
(%standard-phases): Adjust accordingly.
---
 guix/build/emacs-build-system.scm | 42 ++++++-------------------------
 1 file changed, 8 insertions(+), 34 deletions(-)

diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm
index 47a9eda9e6..f0c41812f1 100644
--- a/guix/build/emacs-build-system.scm
+++ b/guix/build/emacs-build-system.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
 ;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
-;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -74,40 +74,14 @@ archive, a directory, or an Emacs Lisp file."
         #t)
       (gnu:unpack #:source source)))
 
-(define* (set-emacs-load-path #:key source inputs #:allow-other-keys)
-  (define (inputs->directories inputs)
-    "Extract the directory part from INPUTS."
-    (match inputs
-      (((names . directories) ...) directories)))
-
-  (define (input-directory->el-directory input-directory)
-    "Return the correct Emacs Lisp directory in INPUT-DIRECTORY or #f, if there
-is no Emacs Lisp directory."
-    (let ((legacy-elisp-directory (string-append input-directory %legacy-install-suffix))
-          (guix-elisp-directory
-           (string-append
-            input-directory %install-suffix "/"
-            (store-directory->elpa-name-version input-directory))))
-      (cond
-       ((file-exists? guix-elisp-directory) guix-elisp-directory)
-       ((file-exists? legacy-elisp-directory) legacy-elisp-directory)
-       (else #f))))
-
-  (define (input-directories->el-directories input-directories)
-    "Return the list of Emacs Lisp directories in INPUT-DIRECTORIES."
-    (filter-map input-directory->el-directory input-directories))
-
-  "Set the EMACSLOADPATH environment variable so that dependencies are found."
+(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
+  "Augment the EMACSLOADPATH environment variable with the source directory."
   (let* ((source-directory (getcwd))
-         (input-elisp-directories (input-directories->el-directories
-                                   (inputs->directories inputs)))
-         (emacs-load-path-value
-          (string-join
-           (append input-elisp-directories (list source-directory))
-           ":" 'suffix)))
+         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
+                                               source-directory)))
     (setenv "EMACSLOADPATH" emacs-load-path-value)
-    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
-            emacs-load-path-value)))
+    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
+environment variable\n" source-directory)))
 
 (define* (build #:key outputs inputs #:allow-other-keys)
   "Compile .el files."
@@ -269,7 +243,7 @@ second hyphen.  This corresponds to 'name-version' as used in ELPA packages."
 (define %standard-phases
   (modify-phases gnu:%standard-phases
     (replace 'unpack unpack)
-    (add-after 'unpack 'set-emacs-load-path set-emacs-load-path)
+    (add-after 'unpack 'add-source-to-load-path add-source-to-load-path)
     (delete 'bootstrap)
     (delete 'configure)
     ;; Move the build phase after install: the .el files are byte compiled
-- 
2.23.0


[-- Attachment #4: 0003-gnu-emacs-Adapt-the-autoloads-auxiliary-code-to-use-.patch --]
[-- Type: text/x-patch, Size: 6961 bytes --]

From 39b31bb30b8ecab67bd6de315b5aa1bb59a3ee20 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 29 Oct 2019 22:07:55 -0400
Subject: [PATCH 3/3] gnu: emacs: Adapt the autoloads auxiliary code to use
 EMACSLOADPATH.

The Elisp directories to scan for autoloads are now taken from EMACSLOADPATH
instead of from the user profile, environment profile or system profile.
Manually adding the Elisp directories to the `load-path' is no longer
necessary, as this is covered by Emacs when they are in EMACSLOADPATH.  The
caching logic is also removed, as this code is not typically run often and the
gain is marginal (loading autoloads files is cheap).

* gnu/packages/aux-files/emacs/guix-emacs.el (guix-emacs-directory)
(guix-emacs-subdirs, guix-emacs-directories): Remove procedures.
(guix-emacs-find-autoloads): Filter the directory entries by passing the
regexp to `directory-files' directly, which is ten times faster.  Remove
deduplication.
(guix-emacs-autoloads-regexp): Remove the group, which used to filter out the
file extension; it no longer works this way due to passing the regexp to the
`directory-files' procedure directly, which doesn't care about groups.
(guix-emacs-autoload-packages): Update doc.  Search package directories from
EMACSLOADPATH.  Do not populate the load-path.  Remove cache.
---
 gnu/packages/aux-files/emacs/guix-emacs.el | 98 ++++++----------------
 1 file changed, 24 insertions(+), 74 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 9a49e8861c..46ee557f20 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -2,6 +2,7 @@
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
 ;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
+;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 
 ;; This file is part of GNU Guix.
 
@@ -24,91 +25,40 @@
 ;; installed with Guix.
 
 ;;; Code:
-
-(require 'cl-lib)
-
-(defvar guix-user-profile (expand-file-name "~/.guix-profile"))
-
-(defvar guix-emacs-autoloads nil
-  "List of the last loaded Emacs autoloads.")
+(require 'seq)
 
 (defvar guix-emacs-autoloads-regexp
-  (rx (group (* any) "-autoloads")
-      ".el" (zero-or-one "c") string-end)
+  (rx (* any) "-autoloads.el" (zero-or-one "c") string-end)
   "Regexp to match Emacs 'autoloads' file.")
 
-(defun guix-emacs-directory (&optional profile)
-  "Return directory with Emacs packages installed in PROFILE.
-If PROFILE is nil, use `guix-user-profile'."
-  (expand-file-name "share/emacs/site-lisp"
-                    (or profile guix-user-profile)))
-
 (defun guix-emacs-find-autoloads (directory)
   "Return a list of Emacs 'autoloads' files in DIRECTORY.
 The files in the list do not have extensions (.el, .elc)."
-  (cl-remove-duplicates
-   (delq nil
-        (mapcar (lambda (file)
-                  (when (string-match guix-emacs-autoloads-regexp file)
-                    (match-string 1 file)))
-                (directory-files directory 'full-name nil 'no-sort)))
-   :test #'string=))
-
-(defun guix-emacs-subdirs (directory)
-  "Return list of DIRECTORY subdirectories."
-  (cl-remove-if (lambda (file)
-                  (or (string-match-p (rx "/." string-end) file)
-                      (string-match-p (rx "/.." string-end) file)
-                      (not (file-directory-p file))))
-                (directory-files directory 'full-name nil 'no-sort)))
-
-(defun guix-emacs-directories (&optional profile)
-  "Return the list of directories under PROFILE that contain Emacs packages.
-This includes both `share/emacs/site-lisp/guix.d/PACKAGE'
-sub-directories and `share/emacs/site-lisp' itself.
-
-If PROFILE is nil, use `guix-user-profile'.
-Return nil, if Emacs packages are not installed in PROFILE."
-  (let ((root-dir (guix-emacs-directory (or profile guix-user-profile))))
-    (when (file-directory-p root-dir)
-      (let* ((pkgs-dir  (expand-file-name "guix.d" root-dir))
-             (pkgs-dirs (when (file-directory-p pkgs-dir)
-                          (guix-emacs-subdirs pkgs-dir))))
-        (cons root-dir pkgs-dirs)))))
+  ;; `directory-files' doesn't honor group in regexp.
+  (mapcar #'file-name-sans-extension
+          (directory-files directory 'full-name guix-emacs-autoloads-regexp)))
 
 ;;;###autoload
-(defun guix-emacs-autoload-packages (&rest profiles)
-  "Autoload Emacs packages installed in PROFILES.
-If PROFILES are not specified, use a default user and system
-profiles.
+(defun guix-emacs-autoload-packages ()
+  "Autoload Emacs packages found in EMACSLOADPATH.
 
-'Autoload' means add directories with Emacs packages to
-`load-path' and load 'autoloads' files matching
+'Autoload' means to load the 'autoloads' files matching
 `guix-emacs-autoloads-regexp'."
-  (interactive (list (if (fboundp 'guix-read-package-profile)
-                         (funcall 'guix-read-package-profile)
-                       guix-user-profile)))
-  (let* ((env      (getenv "GUIX_ENVIRONMENT"))
-         (profiles (or profiles
-                       (append (list "/run/current-system/profile"
-                                     guix-user-profile)
-                               (and env (list env))))))
-    (dolist (profile profiles)
-      (let ((dirs (guix-emacs-directories profile)))
-        (when dirs
-          (let* ((autoloads     (cl-mapcan #'guix-emacs-find-autoloads
-                                           dirs))
-                 (new-autoloads (cl-nset-difference autoloads
-                                                    guix-emacs-autoloads
-                                                    :test #'string=)))
-            (dolist (dir dirs)
-              (cl-pushnew (directory-file-name dir)
-                          load-path
-                          :test #'string=))
-            (dolist (file new-autoloads)
-              (load file 'noerror))
-            (setq guix-emacs-autoloads
-                  (append new-autoloads guix-emacs-autoloads))))))))
+  ;; FIXME: The autoloads generated by the emacs-build-system are not byte
+  ;; compiled.
+  (interactive)
+  (let* ((emacs-load-path (getenv "EMACSLOADPATH"))
+         (emacs-non-core-load-path-directories
+          ;; Filter out core Elisp directories, which are already autoloaded
+          ;; by Emacs.
+          (seq-filter (lambda (dir)
+                        (string-match-p "/share/emacs/site-lisp" dir))
+                      (split-string emacs-load-path ":")))
+          (autoloads (mapcan #'guix-emacs-find-autoloads
+                             emacs-non-core-load-path-directories)))
+    (mapc (lambda (f)
+            (load f 'noerror))
+          autoloads)))
 
 (provide 'guix-emacs)
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
  2019-10-31  5:29                               ` Maxim Cournoyer
@ 2019-10-31 12:29                                 ` Pierre Neidhardt
  2019-11-01  4:25                                     ` Maxim Cournoyer
  0 siblings, 1 reply; 53+ messages in thread
From: Pierre Neidhardt @ 2019-10-31 12:29 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 1231 bytes --]

I've reviewed and tested the patch:

- review: 5/5 stars :D
- test: pass!

I've tested the following:

--8<---------------cut here---------------start------------->8---
$ /home/ambrevar/projects/guix/pre-inst-env guix package -i emacs-2048-game emacs -p ~/temp/foo
$ cd ~/temp
$ env -i $(which bash) --login --noprofile --norc
bash-5.0$ /run/current-system/profile/bin/env DISPLAY=:1 emacs
--8<---------------cut here---------------end--------------->8---

Content of *Messages*:

--8<---------------cut here---------------start------------->8---
Loading /gnu/store/ghdkfqnvrxipp4ikakags5rl7flywb72-profile/share/emacs/site-lisp/guix.d/2048-game-20151026.1233/2048-game-autoloads.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
--8<---------------cut here---------------end--------------->8---

And 

--8<---------------cut here---------------start------------->8---
M-x 2048-game RET
--8<---------------cut here---------------end--------------->8---

works!

Can we merge this on master?  We have some 700 emacs packages that are
going to be rebuilt, but it's rather light for the build farm.  What do
you think?

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-10-31 12:29                                 ` Pierre Neidhardt
@ 2019-11-01  4:25                                     ` Maxim Cournoyer
  0 siblings, 0 replies; 53+ messages in thread
From: Maxim Cournoyer @ 2019-11-01  4:25 UTC (permalink / raw)
  To: 38015, mail; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 1703 bytes --]

[+ guix-patches]

Hello!

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> I've reviewed and tested the patch:
>
> - review: 5/5 stars :D
> - test: pass!
>
> I've tested the following:
>
> $ /home/ambrevar/projects/guix/pre-inst-env guix package -i emacs-2048-game emacs -p ~/temp/foo
> $ cd ~/temp
> $ env -i $(which bash) --login --noprofile --norc
> bash-5.0$ /run/current-system/profile/bin/env DISPLAY=:1 emacs
>
>
> Content of *Messages*:
>
> Loading /gnu/store/ghdkfqnvrxipp4ikakags5rl7flywb72-profile/share/emacs/site-lisp/guix.d/2048-game-20151026.1233/2048-game-autoloads.el (source)...done
> For information about GNU Emacs and the GNU system, type C-h C-a.
>
>
> And 
>
> M-x 2048-game RET
>
> works!

I'm glad it works and fixes your use case :-).

> Can we merge this on master?  We have some 700 emacs packages that are
> going to be rebuilt, but it's rather light for the build farm.  What do
> you think?

I'm not worried about the 700 Emacs packages that will need to be
rebuild, but I'd prefer to take a bit of time to let people comment on
this non-trivial change.

The new behavior (of not always loading stuff from the user profile and
system profiles) is different and may break the flow of some people.

For one, I think restarting my Emacs server (started at login) won't be
enough to discover newly installed packages to my profile.  Emacs-Magit
may also be impacted, I haven't reviewed if it uses that autoload
function from site-start.el.

Refreshing an environment variable value for a process (such as Emacs)
is not as convenient as re-scanning a directory.

I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
to master.

Thanks for the review!

Maxim


[-- Attachment #2: 0001-gnu-emacs-Locate-Elisp-libraries-via-EMACSLOADPATH.patch --]
[-- Type: text/x-patch, Size: 1717 bytes --]

From d5dc7fd8a2406939346b44457859764a98afece0 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sat, 3 Jun 2017 12:56:36 -0700
Subject: [PATCH 1/3] gnu: emacs: Locate Elisp libraries via EMACSLOADPATH.

* gnu/packages/emacs.scm (emacs): Add a search path specification for
EMACSLOADPATH.
---
 gnu/packages/emacs.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 6c6f0e4567..16f9af0a0a 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -9,7 +9,7 @@
 ;;; Copyright © 2016 David Thompson <dthompson2@worcester.edu>
 ;;; Copyright © 2016 ng0 <ng0@n0.is>
 ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
-;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2017, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2017 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
@@ -185,6 +185,13 @@
 
     (native-search-paths
      (list (search-path-specification
+            (variable "EMACSLOADPATH")
+            ;; The versioned entries are for the Emacs' builtin libraries.
+            (files (list (string-append "share/emacs/" version "/site-lisp")
+                         (string-append "share/emacs/" version "/lisp")
+                         "share/emacs/site-lisp"))
+            (file-pattern ".*"))        ;recursively add any sub directory
+           (search-path-specification
             (variable "INFOPATH")
             (files '("share/info")))))
 
-- 
2.23.0


[-- Attachment #3: 0002-build-system-emacs-Simplify-the-SET-EMACS-LOAD-PATH-.patch --]
[-- Type: text/x-patch, Size: 4014 bytes --]

From 9c4897347bee7f3b6afb97a6c766d57f0bee1b9d Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Mon, 28 Oct 2019 08:09:03 -0400
Subject: [PATCH 2/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
 phase.

It is no longer necessary to search for the Elisp libraries manually, as Emacs
now include a search path specification serving that purpose.

* guix/build/emacs-build-system.scm (set-emacs-load-path): Replace by...
(add-source-to-load-path): ...this.
(%standard-phases): Adjust accordingly.
---
 guix/build/emacs-build-system.scm | 42 ++++++-------------------------
 1 file changed, 8 insertions(+), 34 deletions(-)

diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm
index 47a9eda9e6..f0c41812f1 100644
--- a/guix/build/emacs-build-system.scm
+++ b/guix/build/emacs-build-system.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
 ;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
-;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -74,40 +74,14 @@ archive, a directory, or an Emacs Lisp file."
         #t)
       (gnu:unpack #:source source)))
 
-(define* (set-emacs-load-path #:key source inputs #:allow-other-keys)
-  (define (inputs->directories inputs)
-    "Extract the directory part from INPUTS."
-    (match inputs
-      (((names . directories) ...) directories)))
-
-  (define (input-directory->el-directory input-directory)
-    "Return the correct Emacs Lisp directory in INPUT-DIRECTORY or #f, if there
-is no Emacs Lisp directory."
-    (let ((legacy-elisp-directory (string-append input-directory %legacy-install-suffix))
-          (guix-elisp-directory
-           (string-append
-            input-directory %install-suffix "/"
-            (store-directory->elpa-name-version input-directory))))
-      (cond
-       ((file-exists? guix-elisp-directory) guix-elisp-directory)
-       ((file-exists? legacy-elisp-directory) legacy-elisp-directory)
-       (else #f))))
-
-  (define (input-directories->el-directories input-directories)
-    "Return the list of Emacs Lisp directories in INPUT-DIRECTORIES."
-    (filter-map input-directory->el-directory input-directories))
-
-  "Set the EMACSLOADPATH environment variable so that dependencies are found."
+(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
+  "Augment the EMACSLOADPATH environment variable with the source directory."
   (let* ((source-directory (getcwd))
-         (input-elisp-directories (input-directories->el-directories
-                                   (inputs->directories inputs)))
-         (emacs-load-path-value
-          (string-join
-           (append input-elisp-directories (list source-directory))
-           ":" 'suffix)))
+         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
+                                               source-directory)))
     (setenv "EMACSLOADPATH" emacs-load-path-value)
-    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
-            emacs-load-path-value)))
+    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
+environment variable\n" source-directory)))
 
 (define* (build #:key outputs inputs #:allow-other-keys)
   "Compile .el files."
@@ -269,7 +243,7 @@ second hyphen.  This corresponds to 'name-version' as used in ELPA packages."
 (define %standard-phases
   (modify-phases gnu:%standard-phases
     (replace 'unpack unpack)
-    (add-after 'unpack 'set-emacs-load-path set-emacs-load-path)
+    (add-after 'unpack 'add-source-to-load-path add-source-to-load-path)
     (delete 'bootstrap)
     (delete 'configure)
     ;; Move the build phase after install: the .el files are byte compiled
-- 
2.23.0


[-- Attachment #4: 0003-gnu-emacs-Adapt-the-autoloads-auxiliary-code-to-use-.patch --]
[-- Type: text/x-patch, Size: 6961 bytes --]

From 39b31bb30b8ecab67bd6de315b5aa1bb59a3ee20 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 29 Oct 2019 22:07:55 -0400
Subject: [PATCH 3/3] gnu: emacs: Adapt the autoloads auxiliary code to use
 EMACSLOADPATH.

The Elisp directories to scan for autoloads are now taken from EMACSLOADPATH
instead of from the user profile, environment profile or system profile.
Manually adding the Elisp directories to the `load-path' is no longer
necessary, as this is covered by Emacs when they are in EMACSLOADPATH.  The
caching logic is also removed, as this code is not typically run often and the
gain is marginal (loading autoloads files is cheap).

* gnu/packages/aux-files/emacs/guix-emacs.el (guix-emacs-directory)
(guix-emacs-subdirs, guix-emacs-directories): Remove procedures.
(guix-emacs-find-autoloads): Filter the directory entries by passing the
regexp to `directory-files' directly, which is ten times faster.  Remove
deduplication.
(guix-emacs-autoloads-regexp): Remove the group, which used to filter out the
file extension; it no longer works this way due to passing the regexp to the
`directory-files' procedure directly, which doesn't care about groups.
(guix-emacs-autoload-packages): Update doc.  Search package directories from
EMACSLOADPATH.  Do not populate the load-path.  Remove cache.
---
 gnu/packages/aux-files/emacs/guix-emacs.el | 98 ++++++----------------
 1 file changed, 24 insertions(+), 74 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 9a49e8861c..46ee557f20 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -2,6 +2,7 @@
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
 ;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
+;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 
 ;; This file is part of GNU Guix.
 
@@ -24,91 +25,40 @@
 ;; installed with Guix.
 
 ;;; Code:
-
-(require 'cl-lib)
-
-(defvar guix-user-profile (expand-file-name "~/.guix-profile"))
-
-(defvar guix-emacs-autoloads nil
-  "List of the last loaded Emacs autoloads.")
+(require 'seq)
 
 (defvar guix-emacs-autoloads-regexp
-  (rx (group (* any) "-autoloads")
-      ".el" (zero-or-one "c") string-end)
+  (rx (* any) "-autoloads.el" (zero-or-one "c") string-end)
   "Regexp to match Emacs 'autoloads' file.")
 
-(defun guix-emacs-directory (&optional profile)
-  "Return directory with Emacs packages installed in PROFILE.
-If PROFILE is nil, use `guix-user-profile'."
-  (expand-file-name "share/emacs/site-lisp"
-                    (or profile guix-user-profile)))
-
 (defun guix-emacs-find-autoloads (directory)
   "Return a list of Emacs 'autoloads' files in DIRECTORY.
 The files in the list do not have extensions (.el, .elc)."
-  (cl-remove-duplicates
-   (delq nil
-        (mapcar (lambda (file)
-                  (when (string-match guix-emacs-autoloads-regexp file)
-                    (match-string 1 file)))
-                (directory-files directory 'full-name nil 'no-sort)))
-   :test #'string=))
-
-(defun guix-emacs-subdirs (directory)
-  "Return list of DIRECTORY subdirectories."
-  (cl-remove-if (lambda (file)
-                  (or (string-match-p (rx "/." string-end) file)
-                      (string-match-p (rx "/.." string-end) file)
-                      (not (file-directory-p file))))
-                (directory-files directory 'full-name nil 'no-sort)))
-
-(defun guix-emacs-directories (&optional profile)
-  "Return the list of directories under PROFILE that contain Emacs packages.
-This includes both `share/emacs/site-lisp/guix.d/PACKAGE'
-sub-directories and `share/emacs/site-lisp' itself.
-
-If PROFILE is nil, use `guix-user-profile'.
-Return nil, if Emacs packages are not installed in PROFILE."
-  (let ((root-dir (guix-emacs-directory (or profile guix-user-profile))))
-    (when (file-directory-p root-dir)
-      (let* ((pkgs-dir  (expand-file-name "guix.d" root-dir))
-             (pkgs-dirs (when (file-directory-p pkgs-dir)
-                          (guix-emacs-subdirs pkgs-dir))))
-        (cons root-dir pkgs-dirs)))))
+  ;; `directory-files' doesn't honor group in regexp.
+  (mapcar #'file-name-sans-extension
+          (directory-files directory 'full-name guix-emacs-autoloads-regexp)))
 
 ;;;###autoload
-(defun guix-emacs-autoload-packages (&rest profiles)
-  "Autoload Emacs packages installed in PROFILES.
-If PROFILES are not specified, use a default user and system
-profiles.
+(defun guix-emacs-autoload-packages ()
+  "Autoload Emacs packages found in EMACSLOADPATH.
 
-'Autoload' means add directories with Emacs packages to
-`load-path' and load 'autoloads' files matching
+'Autoload' means to load the 'autoloads' files matching
 `guix-emacs-autoloads-regexp'."
-  (interactive (list (if (fboundp 'guix-read-package-profile)
-                         (funcall 'guix-read-package-profile)
-                       guix-user-profile)))
-  (let* ((env      (getenv "GUIX_ENVIRONMENT"))
-         (profiles (or profiles
-                       (append (list "/run/current-system/profile"
-                                     guix-user-profile)
-                               (and env (list env))))))
-    (dolist (profile profiles)
-      (let ((dirs (guix-emacs-directories profile)))
-        (when dirs
-          (let* ((autoloads     (cl-mapcan #'guix-emacs-find-autoloads
-                                           dirs))
-                 (new-autoloads (cl-nset-difference autoloads
-                                                    guix-emacs-autoloads
-                                                    :test #'string=)))
-            (dolist (dir dirs)
-              (cl-pushnew (directory-file-name dir)
-                          load-path
-                          :test #'string=))
-            (dolist (file new-autoloads)
-              (load file 'noerror))
-            (setq guix-emacs-autoloads
-                  (append new-autoloads guix-emacs-autoloads))))))))
+  ;; FIXME: The autoloads generated by the emacs-build-system are not byte
+  ;; compiled.
+  (interactive)
+  (let* ((emacs-load-path (getenv "EMACSLOADPATH"))
+         (emacs-non-core-load-path-directories
+          ;; Filter out core Elisp directories, which are already autoloaded
+          ;; by Emacs.
+          (seq-filter (lambda (dir)
+                        (string-match-p "/share/emacs/site-lisp" dir))
+                      (split-string emacs-load-path ":")))
+          (autoloads (mapcan #'guix-emacs-find-autoloads
+                             emacs-non-core-load-path-directories)))
+    (mapc (lambda (f)
+            (load f 'noerror))
+          autoloads)))
 
 (provide 'guix-emacs)
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
@ 2019-11-01  4:25                                     ` Maxim Cournoyer
  0 siblings, 0 replies; 53+ messages in thread
From: Maxim Cournoyer @ 2019-11-01  4:25 UTC (permalink / raw)
  To: guix-patches, Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 1703 bytes --]

[+ guix-patches]

Hello!

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> I've reviewed and tested the patch:
>
> - review: 5/5 stars :D
> - test: pass!
>
> I've tested the following:
>
> $ /home/ambrevar/projects/guix/pre-inst-env guix package -i emacs-2048-game emacs -p ~/temp/foo
> $ cd ~/temp
> $ env -i $(which bash) --login --noprofile --norc
> bash-5.0$ /run/current-system/profile/bin/env DISPLAY=:1 emacs
>
>
> Content of *Messages*:
>
> Loading /gnu/store/ghdkfqnvrxipp4ikakags5rl7flywb72-profile/share/emacs/site-lisp/guix.d/2048-game-20151026.1233/2048-game-autoloads.el (source)...done
> For information about GNU Emacs and the GNU system, type C-h C-a.
>
>
> And 
>
> M-x 2048-game RET
>
> works!

I'm glad it works and fixes your use case :-).

> Can we merge this on master?  We have some 700 emacs packages that are
> going to be rebuilt, but it's rather light for the build farm.  What do
> you think?

I'm not worried about the 700 Emacs packages that will need to be
rebuild, but I'd prefer to take a bit of time to let people comment on
this non-trivial change.

The new behavior (of not always loading stuff from the user profile and
system profiles) is different and may break the flow of some people.

For one, I think restarting my Emacs server (started at login) won't be
enough to discover newly installed packages to my profile.  Emacs-Magit
may also be impacted, I haven't reviewed if it uses that autoload
function from site-start.el.

Refreshing an environment variable value for a process (such as Emacs)
is not as convenient as re-scanning a directory.

I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
to master.

Thanks for the review!

Maxim


[-- Attachment #2: 0001-gnu-emacs-Locate-Elisp-libraries-via-EMACSLOADPATH.patch --]
[-- Type: text/x-patch, Size: 1717 bytes --]

From d5dc7fd8a2406939346b44457859764a98afece0 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Sat, 3 Jun 2017 12:56:36 -0700
Subject: [PATCH 1/3] gnu: emacs: Locate Elisp libraries via EMACSLOADPATH.

* gnu/packages/emacs.scm (emacs): Add a search path specification for
EMACSLOADPATH.
---
 gnu/packages/emacs.scm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/emacs.scm b/gnu/packages/emacs.scm
index 6c6f0e4567..16f9af0a0a 100644
--- a/gnu/packages/emacs.scm
+++ b/gnu/packages/emacs.scm
@@ -9,7 +9,7 @@
 ;;; Copyright © 2016 David Thompson <dthompson2@worcester.edu>
 ;;; Copyright © 2016 ng0 <ng0@n0.is>
 ;;; Copyright © 2017 Marius Bakke <mbakke@fastmail.com>
-;;; Copyright © 2017 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2017, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2017 Alex Vong <alexvong1995@gmail.com>
 ;;; Copyright © 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
@@ -185,6 +185,13 @@
 
     (native-search-paths
      (list (search-path-specification
+            (variable "EMACSLOADPATH")
+            ;; The versioned entries are for the Emacs' builtin libraries.
+            (files (list (string-append "share/emacs/" version "/site-lisp")
+                         (string-append "share/emacs/" version "/lisp")
+                         "share/emacs/site-lisp"))
+            (file-pattern ".*"))        ;recursively add any sub directory
+           (search-path-specification
             (variable "INFOPATH")
             (files '("share/info")))))
 
-- 
2.23.0


[-- Attachment #3: 0002-build-system-emacs-Simplify-the-SET-EMACS-LOAD-PATH-.patch --]
[-- Type: text/x-patch, Size: 4014 bytes --]

From 9c4897347bee7f3b6afb97a6c766d57f0bee1b9d Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Mon, 28 Oct 2019 08:09:03 -0400
Subject: [PATCH 2/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
 phase.

It is no longer necessary to search for the Elisp libraries manually, as Emacs
now include a search path specification serving that purpose.

* guix/build/emacs-build-system.scm (set-emacs-load-path): Replace by...
(add-source-to-load-path): ...this.
(%standard-phases): Adjust accordingly.
---
 guix/build/emacs-build-system.scm | 42 ++++++-------------------------
 1 file changed, 8 insertions(+), 34 deletions(-)

diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm
index 47a9eda9e6..f0c41812f1 100644
--- a/guix/build/emacs-build-system.scm
+++ b/guix/build/emacs-build-system.scm
@@ -2,7 +2,7 @@
 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
 ;;; Copyright © 2016 Alex Kost <alezost@gmail.com>
-;;; Copyright © 2018 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2018, 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -74,40 +74,14 @@ archive, a directory, or an Emacs Lisp file."
         #t)
       (gnu:unpack #:source source)))
 
-(define* (set-emacs-load-path #:key source inputs #:allow-other-keys)
-  (define (inputs->directories inputs)
-    "Extract the directory part from INPUTS."
-    (match inputs
-      (((names . directories) ...) directories)))
-
-  (define (input-directory->el-directory input-directory)
-    "Return the correct Emacs Lisp directory in INPUT-DIRECTORY or #f, if there
-is no Emacs Lisp directory."
-    (let ((legacy-elisp-directory (string-append input-directory %legacy-install-suffix))
-          (guix-elisp-directory
-           (string-append
-            input-directory %install-suffix "/"
-            (store-directory->elpa-name-version input-directory))))
-      (cond
-       ((file-exists? guix-elisp-directory) guix-elisp-directory)
-       ((file-exists? legacy-elisp-directory) legacy-elisp-directory)
-       (else #f))))
-
-  (define (input-directories->el-directories input-directories)
-    "Return the list of Emacs Lisp directories in INPUT-DIRECTORIES."
-    (filter-map input-directory->el-directory input-directories))
-
-  "Set the EMACSLOADPATH environment variable so that dependencies are found."
+(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
+  "Augment the EMACSLOADPATH environment variable with the source directory."
   (let* ((source-directory (getcwd))
-         (input-elisp-directories (input-directories->el-directories
-                                   (inputs->directories inputs)))
-         (emacs-load-path-value
-          (string-join
-           (append input-elisp-directories (list source-directory))
-           ":" 'suffix)))
+         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
+                                               source-directory)))
     (setenv "EMACSLOADPATH" emacs-load-path-value)
-    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
-            emacs-load-path-value)))
+    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
+environment variable\n" source-directory)))
 
 (define* (build #:key outputs inputs #:allow-other-keys)
   "Compile .el files."
@@ -269,7 +243,7 @@ second hyphen.  This corresponds to 'name-version' as used in ELPA packages."
 (define %standard-phases
   (modify-phases gnu:%standard-phases
     (replace 'unpack unpack)
-    (add-after 'unpack 'set-emacs-load-path set-emacs-load-path)
+    (add-after 'unpack 'add-source-to-load-path add-source-to-load-path)
     (delete 'bootstrap)
     (delete 'configure)
     ;; Move the build phase after install: the .el files are byte compiled
-- 
2.23.0


[-- Attachment #4: 0003-gnu-emacs-Adapt-the-autoloads-auxiliary-code-to-use-.patch --]
[-- Type: text/x-patch, Size: 6961 bytes --]

From 39b31bb30b8ecab67bd6de315b5aa1bb59a3ee20 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Tue, 29 Oct 2019 22:07:55 -0400
Subject: [PATCH 3/3] gnu: emacs: Adapt the autoloads auxiliary code to use
 EMACSLOADPATH.

The Elisp directories to scan for autoloads are now taken from EMACSLOADPATH
instead of from the user profile, environment profile or system profile.
Manually adding the Elisp directories to the `load-path' is no longer
necessary, as this is covered by Emacs when they are in EMACSLOADPATH.  The
caching logic is also removed, as this code is not typically run often and the
gain is marginal (loading autoloads files is cheap).

* gnu/packages/aux-files/emacs/guix-emacs.el (guix-emacs-directory)
(guix-emacs-subdirs, guix-emacs-directories): Remove procedures.
(guix-emacs-find-autoloads): Filter the directory entries by passing the
regexp to `directory-files' directly, which is ten times faster.  Remove
deduplication.
(guix-emacs-autoloads-regexp): Remove the group, which used to filter out the
file extension; it no longer works this way due to passing the regexp to the
`directory-files' procedure directly, which doesn't care about groups.
(guix-emacs-autoload-packages): Update doc.  Search package directories from
EMACSLOADPATH.  Do not populate the load-path.  Remove cache.
---
 gnu/packages/aux-files/emacs/guix-emacs.el | 98 ++++++----------------
 1 file changed, 24 insertions(+), 74 deletions(-)

diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index 9a49e8861c..46ee557f20 100644
--- a/gnu/packages/aux-files/emacs/guix-emacs.el
+++ b/gnu/packages/aux-files/emacs/guix-emacs.el
@@ -2,6 +2,7 @@
 
 ;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
 ;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
+;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 
 ;; This file is part of GNU Guix.
 
@@ -24,91 +25,40 @@
 ;; installed with Guix.
 
 ;;; Code:
-
-(require 'cl-lib)
-
-(defvar guix-user-profile (expand-file-name "~/.guix-profile"))
-
-(defvar guix-emacs-autoloads nil
-  "List of the last loaded Emacs autoloads.")
+(require 'seq)
 
 (defvar guix-emacs-autoloads-regexp
-  (rx (group (* any) "-autoloads")
-      ".el" (zero-or-one "c") string-end)
+  (rx (* any) "-autoloads.el" (zero-or-one "c") string-end)
   "Regexp to match Emacs 'autoloads' file.")
 
-(defun guix-emacs-directory (&optional profile)
-  "Return directory with Emacs packages installed in PROFILE.
-If PROFILE is nil, use `guix-user-profile'."
-  (expand-file-name "share/emacs/site-lisp"
-                    (or profile guix-user-profile)))
-
 (defun guix-emacs-find-autoloads (directory)
   "Return a list of Emacs 'autoloads' files in DIRECTORY.
 The files in the list do not have extensions (.el, .elc)."
-  (cl-remove-duplicates
-   (delq nil
-        (mapcar (lambda (file)
-                  (when (string-match guix-emacs-autoloads-regexp file)
-                    (match-string 1 file)))
-                (directory-files directory 'full-name nil 'no-sort)))
-   :test #'string=))
-
-(defun guix-emacs-subdirs (directory)
-  "Return list of DIRECTORY subdirectories."
-  (cl-remove-if (lambda (file)
-                  (or (string-match-p (rx "/." string-end) file)
-                      (string-match-p (rx "/.." string-end) file)
-                      (not (file-directory-p file))))
-                (directory-files directory 'full-name nil 'no-sort)))
-
-(defun guix-emacs-directories (&optional profile)
-  "Return the list of directories under PROFILE that contain Emacs packages.
-This includes both `share/emacs/site-lisp/guix.d/PACKAGE'
-sub-directories and `share/emacs/site-lisp' itself.
-
-If PROFILE is nil, use `guix-user-profile'.
-Return nil, if Emacs packages are not installed in PROFILE."
-  (let ((root-dir (guix-emacs-directory (or profile guix-user-profile))))
-    (when (file-directory-p root-dir)
-      (let* ((pkgs-dir  (expand-file-name "guix.d" root-dir))
-             (pkgs-dirs (when (file-directory-p pkgs-dir)
-                          (guix-emacs-subdirs pkgs-dir))))
-        (cons root-dir pkgs-dirs)))))
+  ;; `directory-files' doesn't honor group in regexp.
+  (mapcar #'file-name-sans-extension
+          (directory-files directory 'full-name guix-emacs-autoloads-regexp)))
 
 ;;;###autoload
-(defun guix-emacs-autoload-packages (&rest profiles)
-  "Autoload Emacs packages installed in PROFILES.
-If PROFILES are not specified, use a default user and system
-profiles.
+(defun guix-emacs-autoload-packages ()
+  "Autoload Emacs packages found in EMACSLOADPATH.
 
-'Autoload' means add directories with Emacs packages to
-`load-path' and load 'autoloads' files matching
+'Autoload' means to load the 'autoloads' files matching
 `guix-emacs-autoloads-regexp'."
-  (interactive (list (if (fboundp 'guix-read-package-profile)
-                         (funcall 'guix-read-package-profile)
-                       guix-user-profile)))
-  (let* ((env      (getenv "GUIX_ENVIRONMENT"))
-         (profiles (or profiles
-                       (append (list "/run/current-system/profile"
-                                     guix-user-profile)
-                               (and env (list env))))))
-    (dolist (profile profiles)
-      (let ((dirs (guix-emacs-directories profile)))
-        (when dirs
-          (let* ((autoloads     (cl-mapcan #'guix-emacs-find-autoloads
-                                           dirs))
-                 (new-autoloads (cl-nset-difference autoloads
-                                                    guix-emacs-autoloads
-                                                    :test #'string=)))
-            (dolist (dir dirs)
-              (cl-pushnew (directory-file-name dir)
-                          load-path
-                          :test #'string=))
-            (dolist (file new-autoloads)
-              (load file 'noerror))
-            (setq guix-emacs-autoloads
-                  (append new-autoloads guix-emacs-autoloads))))))))
+  ;; FIXME: The autoloads generated by the emacs-build-system are not byte
+  ;; compiled.
+  (interactive)
+  (let* ((emacs-load-path (getenv "EMACSLOADPATH"))
+         (emacs-non-core-load-path-directories
+          ;; Filter out core Elisp directories, which are already autoloaded
+          ;; by Emacs.
+          (seq-filter (lambda (dir)
+                        (string-match-p "/share/emacs/site-lisp" dir))
+                      (split-string emacs-load-path ":")))
+          (autoloads (mapcan #'guix-emacs-find-autoloads
+                             emacs-non-core-load-path-directories)))
+    (mapc (lambda (f)
+            (load f 'noerror))
+          autoloads)))
 
 (provide 'guix-emacs)
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-01  4:25                                     ` Maxim Cournoyer
@ 2019-11-01 19:06                                       ` Pierre Neidhardt
  -1 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-01 19:06 UTC (permalink / raw)
  To: maxim.cournoyer, 38015; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> For one, I think restarting my Emacs server (started at login) won't be
> enough to discover newly installed packages to my profile.

Hmmm, I don't understand why this would be an issue.  With updated
environment variables, a new instance of Emacs should successfully find
everything, shouldn't it?

> I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
> to master.

Sounds great, thanks for this awesome fix!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
@ 2019-11-01 19:06                                       ` Pierre Neidhardt
  0 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-01 19:06 UTC (permalink / raw)
  To: Maxim Cournoyer, guix-patches; +Cc: Alex Kost, myglc2, help-guix

[-- Attachment #1: Type: text/plain, Size: 547 bytes --]

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> For one, I think restarting my Emacs server (started at login) won't be
> enough to discover newly installed packages to my profile.

Hmmm, I don't understand why this would be an issue.  With updated
environment variables, a new instance of Emacs should successfully find
everything, shouldn't it?

> I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
> to master.

Sounds great, thanks for this awesome fix!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-01 19:06                                       ` Pierre Neidhardt
@ 2019-11-02  1:12                                         ` Maxim Cournoyer
  -1 siblings, 0 replies; 53+ messages in thread
From: Maxim Cournoyer @ 2019-11-02  1:12 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: alezost, myglc2, help-guix, 38015

Hello Pierre,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>
>> For one, I think restarting my Emacs server (started at login) won't be
>> enough to discover newly installed packages to my profile.
>
> Hmmm, I don't understand why this would be an issue.  With updated
> environment variables, a new instance of Emacs should successfully find
> everything, shouldn't it?

Yes, when the instance is really *new*, forked from a session where
EMACSLOADPATH is set right.  I typically start Emacs in server mode
using a shepherd user service, so rarely restart Emacs.  And even if I
was to do 'herd restart emacs', its variables would still be inherited
from the login process that spawned its service.

But that's not too big an issue for Emacs when using Emacs-Guix, as one
can do `guix-set-emacs-environment' and choose a profile to re-read and
set (in Emacs itself) its environment variables.  Re-running
'guix-emacs-autoload-packages' would then refresh the autoloads
corectly, given that EMACSLOADPATH would have been refreshed with an
updated profile.

>> I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
>> to master.
>
> Sounds great, thanks for this awesome fix!

Thank you for your interested in it, you motivated me to dust off a year
old (maybe more) patch and fix the remaining bits.

Maxim

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
@ 2019-11-02  1:12                                         ` Maxim Cournoyer
  0 siblings, 0 replies; 53+ messages in thread
From: Maxim Cournoyer @ 2019-11-02  1:12 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: Alex Kost, myglc2, help-guix, guix-patches

Hello Pierre,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>
>> For one, I think restarting my Emacs server (started at login) won't be
>> enough to discover newly installed packages to my profile.
>
> Hmmm, I don't understand why this would be an issue.  With updated
> environment variables, a new instance of Emacs should successfully find
> everything, shouldn't it?

Yes, when the instance is really *new*, forked from a session where
EMACSLOADPATH is set right.  I typically start Emacs in server mode
using a shepherd user service, so rarely restart Emacs.  And even if I
was to do 'herd restart emacs', its variables would still be inherited
from the login process that spawned its service.

But that's not too big an issue for Emacs when using Emacs-Guix, as one
can do `guix-set-emacs-environment' and choose a profile to re-read and
set (in Emacs itself) its environment variables.  Re-running
'guix-emacs-autoload-packages' would then refresh the autoloads
corectly, given that EMACSLOADPATH would have been refreshed with an
updated profile.

>> I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
>> to master.
>
> Sounds great, thanks for this awesome fix!

Thank you for your interested in it, you motivated me to dust off a year
old (maybe more) patch and fix the remaining bits.

Maxim

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-02  1:12                                         ` Maxim Cournoyer
@ 2019-11-02  9:41                                           ` Pierre Neidhardt
  -1 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-02  9:41 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: alezost, myglc2, help-guix, 38015

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> But that's not too big an issue for Emacs when using Emacs-Guix, as one
> can do `guix-set-emacs-environment' and choose a profile to re-read and
> set (in Emacs itself) its environment variables.  Re-running
> 'guix-emacs-autoload-packages' would then refresh the autoloads
> corectly, given that EMACSLOADPATH would have been refreshed with an
> updated profile.

Damn, didn't know about those 2 functions, it's awesome!
I could have used them many times in the past, had I known about them :p

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in multiple profiles
@ 2019-11-02  9:41                                           ` Pierre Neidhardt
  0 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-02  9:41 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Alex Kost, myglc2, help-guix, guix-patches

[-- Attachment #1: Type: text/plain, Size: 610 bytes --]

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> But that's not too big an issue for Emacs when using Emacs-Guix, as one
> can do `guix-set-emacs-environment' and choose a profile to re-read and
> set (in Emacs itself) its environment variables.  Re-running
> 'guix-emacs-autoload-packages' would then refresh the autoloads
> corectly, given that EMACSLOADPATH would have been refreshed with an
> updated profile.

Damn, didn't know about those 2 functions, it's awesome!
I could have used them many times in the past, had I known about them :p

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-01  4:25                                     ` Maxim Cournoyer
@ 2019-11-12  5:14                                       ` Chris Marusich
  -1 siblings, 0 replies; 53+ messages in thread
From: Chris Marusich @ 2019-11-12  5:14 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: myglc2, 38015, mail, help-guix, Alex Kost

[-- Attachment #1: Type: text/plain, Size: 2421 bytes --]

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> [+ guix-patches]
>
> Hello!
>
> Pierre Neidhardt <mail@ambrevar.xyz> writes:
>
>> I've reviewed and tested the patch:
>>
>> - review: 5/5 stars :D
>> - test: pass!
>>
>> I've tested the following:
>>
>> $ /home/ambrevar/projects/guix/pre-inst-env guix package -i emacs-2048-game emacs -p ~/temp/foo
>> $ cd ~/temp
>> $ env -i $(which bash) --login --noprofile --norc
>> bash-5.0$ /run/current-system/profile/bin/env DISPLAY=:1 emacs
>>
>>
>> Content of *Messages*:
>>
>> Loading /gnu/store/ghdkfqnvrxipp4ikakags5rl7flywb72-profile/share/emacs/site-lisp/guix.d/2048-game-20151026.1233/2048-game-autoloads.el (source)...done
>> For information about GNU Emacs and the GNU system, type C-h C-a.
>>
>>
>> And 
>>
>> M-x 2048-game RET
>>
>> works!
>
> I'm glad it works and fixes your use case :-).
>
>> Can we merge this on master?  We have some 700 emacs packages that are
>> going to be rebuilt, but it's rather light for the build farm.  What do
>> you think?
>
> I'm not worried about the 700 Emacs packages that will need to be
> rebuild, but I'd prefer to take a bit of time to let people comment on
> this non-trivial change.
>
> The new behavior (of not always loading stuff from the user profile and
> system profiles) is different and may break the flow of some people.
>
> For one, I think restarting my Emacs server (started at login) won't be
> enough to discover newly installed packages to my profile.  Emacs-Magit
> may also be impacted, I haven't reviewed if it uses that autoload
> function from site-start.el.
>
> Refreshing an environment variable value for a process (such as Emacs)
> is not as convenient as re-scanning a directory.
>
> I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
> to master.
>
> Thanks for the review!
>
> Maxim

I'd like to test this, but I can't build Guix, so I can't test it.  I
don't know when I'll be able to test it, since I don't know when I'll be
able to build Guix:

"configure: error: Guix requires zlib."
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=38175

Is there a specific commit that you can recommend I use when applying
the patches?  Perhaps one you built successfully yourself?  If you could
also give me your currently installed Guix version so I can "guix pull"
to it, that would be helpful.

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [bug#38015] Emacs in multiple profiles
@ 2019-11-12  5:14                                       ` Chris Marusich
  0 siblings, 0 replies; 53+ messages in thread
From: Chris Marusich @ 2019-11-12  5:14 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: myglc2, 38015, help-guix, Alex Kost

[-- Attachment #1: Type: text/plain, Size: 2421 bytes --]

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> [+ guix-patches]
>
> Hello!
>
> Pierre Neidhardt <mail@ambrevar.xyz> writes:
>
>> I've reviewed and tested the patch:
>>
>> - review: 5/5 stars :D
>> - test: pass!
>>
>> I've tested the following:
>>
>> $ /home/ambrevar/projects/guix/pre-inst-env guix package -i emacs-2048-game emacs -p ~/temp/foo
>> $ cd ~/temp
>> $ env -i $(which bash) --login --noprofile --norc
>> bash-5.0$ /run/current-system/profile/bin/env DISPLAY=:1 emacs
>>
>>
>> Content of *Messages*:
>>
>> Loading /gnu/store/ghdkfqnvrxipp4ikakags5rl7flywb72-profile/share/emacs/site-lisp/guix.d/2048-game-20151026.1233/2048-game-autoloads.el (source)...done
>> For information about GNU Emacs and the GNU system, type C-h C-a.
>>
>>
>> And 
>>
>> M-x 2048-game RET
>>
>> works!
>
> I'm glad it works and fixes your use case :-).
>
>> Can we merge this on master?  We have some 700 emacs packages that are
>> going to be rebuilt, but it's rather light for the build farm.  What do
>> you think?
>
> I'm not worried about the 700 Emacs packages that will need to be
> rebuild, but I'd prefer to take a bit of time to let people comment on
> this non-trivial change.
>
> The new behavior (of not always loading stuff from the user profile and
> system profiles) is different and may break the flow of some people.
>
> For one, I think restarting my Emacs server (started at login) won't be
> enough to discover newly installed packages to my profile.  Emacs-Magit
> may also be impacted, I haven't reviewed if it uses that autoload
> function from site-start.el.
>
> Refreshing an environment variable value for a process (such as Emacs)
> is not as convenient as re-scanning a directory.
>
> I'll let some time pass (2 weeks), and if nobody objects, I'll merge it
> to master.
>
> Thanks for the review!
>
> Maxim

I'd like to test this, but I can't build Guix, so I can't test it.  I
don't know when I'll be able to test it, since I don't know when I'll be
able to build Guix:

"configure: error: Guix requires zlib."
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=38175

Is there a specific commit that you can recommend I use when applying
the patches?  Perhaps one you built successfully yourself?  If you could
also give me your currently installed Guix version so I can "guix pull"
to it, that would be helpful.

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-12  5:14                                       ` Chris Marusich
@ 2019-11-12  7:16                                         ` Pierre Neidhardt
  -1 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-12  7:16 UTC (permalink / raw)
  To: Chris Marusich, Maxim Cournoyer; +Cc: 38015, myglc2, help-guix, Alex Kost

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

My guix describe:


  guix 2ffae26
    repository URL: https://git.savannah.gnu.org/git/guix.git
    branch: master
    commit: 2ffae2689aef8efb325f97ec54abcdeee8588aa0

Note that I'm using substitutes.

Good luck!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [bug#38015] Emacs in multiple profiles
@ 2019-11-12  7:16                                         ` Pierre Neidhardt
  0 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-12  7:16 UTC (permalink / raw)
  To: Chris Marusich, Maxim Cournoyer; +Cc: 38015, myglc2, help-guix, Alex Kost

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

My guix describe:


  guix 2ffae26
    repository URL: https://git.savannah.gnu.org/git/guix.git
    branch: master
    commit: 2ffae2689aef8efb325f97ec54abcdeee8588aa0

Note that I'm using substitutes.

Good luck!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-12  7:16                                         ` Pierre Neidhardt
@ 2019-11-13  7:18                                           ` Chris Marusich
  -1 siblings, 0 replies; 53+ messages in thread
From: Chris Marusich @ 2019-11-13  7:18 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: 38015, myglc2, help-guix, Alex Kost, Maxim Cournoyer

[-- Attachment #1: Type: text/plain, Size: 5150 bytes --]

Hi Pierre and Maxim,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Good luck!

Thank you, Pierre - and Maxim!  I was able to apply the 3 patches (using
commit 18a69803e2eea4f7555d6eafb6497a645c2d094f, which is on master)
cleanly.  I built a profile using the following manifest:

--8<---------------cut here---------------start------------->8---
(use-modules (gnu packages))

(specifications->manifest
 '(
   "emacs"
   "emacs-bbdb"
   ;; ... a whole lot of omitted packages ...
   "emacs-sr-speedbar"
   "emacs-terraform-mode"
   ))
--8<---------------cut here---------------end--------------->8---

I installed it like this:

  ./pre-inst-env guix package -m  /home/marusich/Documents/guix-manifests/emacs.scm -p ~/.guix-extra-profiles/emacs/emacs

I then emptied my default profile and added this to ~/.bash_profile:

--8<---------------cut here---------------start------------->8---
GUIX_EXTRA_PROFILES="$HOME/.guix-extra-profiles"
for i in $GUIX_EXTRA_PROFILES/*; do
	profile=$i/$(basename "$i")
	if [ -f "$profile"/etc/profile ]; then
		GUIX_PROFILE="$profile"
		. "$profile"/etc/profile
        export INFOPATH="$profile/share/info${INFOPATH:+:}$INFOPATH"
        export MANPATH="$profile/share/man${MANPATH:+:}$MANPATH"
	fi
	unset profile
done
--8<---------------cut here---------------end--------------->8---

I logged out and logged back in.  It seems to work so far.  I started
Emacs from a GNOME terminal bash shell.  There were no errors in my
Messages buffer after I started Emacs.  There were no error messages
from the Emacs process, either.  I'm enjoying my new Emacs right now!

So far, I've noticed three things:

- The fonts were different than I remember.  Not sure why it happened,
  but I'm guessing it had to do with the fact that I emptied my default
  profile, and thus got rid of a lot of fonts accidentally.  At this
  time, I doubt it's because of your changes.

- In the GNOME application picker, when I type "emacs" into the search
  bar, there are no longer any results.  Previously, Emacs showed up in
  the search.  This is true for IceCat, too, which I also moved into its
  own separate profile, so I think it's probably an issue with our GNOME
  package instead of your changes.

- Aspell does not work: "ispell-init-process: Error: No word lists can
  be found for the language "en_US"."  I think this happens because
  the Guix package for aspell refers to the default profile:

  (add-after 'install 'wrap-aspell
   (lambda* (#:key outputs #:allow-other-keys)
     (let ((bin/aspell (string-append (assoc-ref outputs "out")
                                      "/bin/aspell")))
       (wrap-program bin/aspell
         '("ASPELL_CONF" "" =
           ("${ASPELL_CONF:-\"dict-dir ${GUIX_PROFILE:-$HOME/.guix-profile}/lib/aspell\"}")))
       #t)))

We should probably follow up on these issues in separate bug reports.
Other than the above, it all just works.  I don't see any reason not to
merge it into master, since even with these issues it is a strict
improvement over the current situation in which we cannot use Emacs
nearly at all in non-default profiles.

If I notice anything else, I'll let you know!

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> Subject: [PATCH 1/3] gnu: emacs: Locate Elisp libraries via EMACSLOADPATH.

LGTM!

> Subject: [PATCH 2/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
>  phase.
>
> +(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
> +  "Augment the EMACSLOADPATH environment variable with the source directory."
>    (let* ((source-directory (getcwd))
> -         (input-elisp-directories (input-directories->el-directories
> -                                   (inputs->directories inputs)))
> -         (emacs-load-path-value
> -          (string-join
> -           (append input-elisp-directories (list source-directory))
> -           ":" 'suffix)))
> +         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
> +                                               source-directory)))
>      (setenv "EMACSLOADPATH" emacs-load-path-value)
> -    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
> -            emacs-load-path-value)))
> +    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
> +environment variable\n" source-directory)))

It looks like the change is as follows: previously, we added multiple
directories, including the source-directory, to the load path; after
this change, we append just the source-directory to the EMACSLOADPATH.
Can you remind me why we don't need to add the other elisp directories
to the EMACSLOADPATH, too?  It seems to work, so I'm probably just
missing something obvious.

> Subject: [PATCH 3/3] gnu: emacs: Adapt the autoloads auxiliary code to use
>  EMACSLOADPATH.

As far as I can tell, this looks good to me, too.

Finally: do you anticipate that this will cause any user-visible or
backwards-incompatible changes that we should mention in the Guix
channel's news file (and in the Guix NEWS file)?

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [bug#38015] Emacs in multiple profiles
@ 2019-11-13  7:18                                           ` Chris Marusich
  0 siblings, 0 replies; 53+ messages in thread
From: Chris Marusich @ 2019-11-13  7:18 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: 38015, myglc2, help-guix, Alex Kost

[-- Attachment #1: Type: text/plain, Size: 5150 bytes --]

Hi Pierre and Maxim,

Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Good luck!

Thank you, Pierre - and Maxim!  I was able to apply the 3 patches (using
commit 18a69803e2eea4f7555d6eafb6497a645c2d094f, which is on master)
cleanly.  I built a profile using the following manifest:

--8<---------------cut here---------------start------------->8---
(use-modules (gnu packages))

(specifications->manifest
 '(
   "emacs"
   "emacs-bbdb"
   ;; ... a whole lot of omitted packages ...
   "emacs-sr-speedbar"
   "emacs-terraform-mode"
   ))
--8<---------------cut here---------------end--------------->8---

I installed it like this:

  ./pre-inst-env guix package -m  /home/marusich/Documents/guix-manifests/emacs.scm -p ~/.guix-extra-profiles/emacs/emacs

I then emptied my default profile and added this to ~/.bash_profile:

--8<---------------cut here---------------start------------->8---
GUIX_EXTRA_PROFILES="$HOME/.guix-extra-profiles"
for i in $GUIX_EXTRA_PROFILES/*; do
	profile=$i/$(basename "$i")
	if [ -f "$profile"/etc/profile ]; then
		GUIX_PROFILE="$profile"
		. "$profile"/etc/profile
        export INFOPATH="$profile/share/info${INFOPATH:+:}$INFOPATH"
        export MANPATH="$profile/share/man${MANPATH:+:}$MANPATH"
	fi
	unset profile
done
--8<---------------cut here---------------end--------------->8---

I logged out and logged back in.  It seems to work so far.  I started
Emacs from a GNOME terminal bash shell.  There were no errors in my
Messages buffer after I started Emacs.  There were no error messages
from the Emacs process, either.  I'm enjoying my new Emacs right now!

So far, I've noticed three things:

- The fonts were different than I remember.  Not sure why it happened,
  but I'm guessing it had to do with the fact that I emptied my default
  profile, and thus got rid of a lot of fonts accidentally.  At this
  time, I doubt it's because of your changes.

- In the GNOME application picker, when I type "emacs" into the search
  bar, there are no longer any results.  Previously, Emacs showed up in
  the search.  This is true for IceCat, too, which I also moved into its
  own separate profile, so I think it's probably an issue with our GNOME
  package instead of your changes.

- Aspell does not work: "ispell-init-process: Error: No word lists can
  be found for the language "en_US"."  I think this happens because
  the Guix package for aspell refers to the default profile:

  (add-after 'install 'wrap-aspell
   (lambda* (#:key outputs #:allow-other-keys)
     (let ((bin/aspell (string-append (assoc-ref outputs "out")
                                      "/bin/aspell")))
       (wrap-program bin/aspell
         '("ASPELL_CONF" "" =
           ("${ASPELL_CONF:-\"dict-dir ${GUIX_PROFILE:-$HOME/.guix-profile}/lib/aspell\"}")))
       #t)))

We should probably follow up on these issues in separate bug reports.
Other than the above, it all just works.  I don't see any reason not to
merge it into master, since even with these issues it is a strict
improvement over the current situation in which we cannot use Emacs
nearly at all in non-default profiles.

If I notice anything else, I'll let you know!

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> Subject: [PATCH 1/3] gnu: emacs: Locate Elisp libraries via EMACSLOADPATH.

LGTM!

> Subject: [PATCH 2/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
>  phase.
>
> +(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
> +  "Augment the EMACSLOADPATH environment variable with the source directory."
>    (let* ((source-directory (getcwd))
> -         (input-elisp-directories (input-directories->el-directories
> -                                   (inputs->directories inputs)))
> -         (emacs-load-path-value
> -          (string-join
> -           (append input-elisp-directories (list source-directory))
> -           ":" 'suffix)))
> +         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
> +                                               source-directory)))
>      (setenv "EMACSLOADPATH" emacs-load-path-value)
> -    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
> -            emacs-load-path-value)))
> +    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
> +environment variable\n" source-directory)))

It looks like the change is as follows: previously, we added multiple
directories, including the source-directory, to the load path; after
this change, we append just the source-directory to the EMACSLOADPATH.
Can you remind me why we don't need to add the other elisp directories
to the EMACSLOADPATH, too?  It seems to work, so I'm probably just
missing something obvious.

> Subject: [PATCH 3/3] gnu: emacs: Adapt the autoloads auxiliary code to use
>  EMACSLOADPATH.

As far as I can tell, this looks good to me, too.

Finally: do you anticipate that this will cause any user-visible or
backwards-incompatible changes that we should mention in the Guix
channel's news file (and in the Guix NEWS file)?

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-13  7:18                                           ` Chris Marusich
@ 2019-11-13 11:08                                             ` Pierre Neidhardt
  -1 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-13 11:08 UTC (permalink / raw)
  To: Chris Marusich; +Cc: 38015, myglc2, help-guix, Alex Kost, Maxim Cournoyer

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

Hi Chris,

Thanks for testing!

> - The fonts were different than I remember.  Not sure why it happened,
>   but I'm guessing it had to do with the fact that I emptied my default
>   profile, and thus got rid of a lot of fonts accidentally.  At this
>   time, I doubt it's because of your changes.

Indeed, Emacs will only load fonts from the default profile.  Not sure
why.  But this is unrelated to this change (it also affects current Guix).

> - Aspell does not work: "ispell-init-process: Error: No word lists can
>   be found for the language "en_US"."  I think this happens because
>   the Guix package for aspell refers to the default profile:
>
>   (add-after 'install 'wrap-aspell
>    (lambda* (#:key outputs #:allow-other-keys)
>      (let ((bin/aspell (string-append (assoc-ref outputs "out")
>                                       "/bin/aspell")))
>        (wrap-program bin/aspell
>          '("ASPELL_CONF" "" =
>            ("${ASPELL_CONF:-\"dict-dir ${GUIX_PROFILE:-$HOME/.guix-profile}/lib/aspell\"}")))
>        #t)))

More precisely, it's because of the patch applied to ASPELL.
See bug #29686 for a discussion.  I have a clue how to patch this
properly, just need to get down to it.

> Finally: do you anticipate that this will cause any user-visible or
> backwards-incompatible changes that we should mention in the Guix
> channel's news file (and in the Guix NEWS file)?

As far I can see, the only incompatibility would arise if the user
explicitly referred to the guix-emacs.el variables that are now gone.

This change is cool enough I'm all for a NEWS entry nonetheless!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [bug#38015] Emacs in multiple profiles
@ 2019-11-13 11:08                                             ` Pierre Neidhardt
  0 siblings, 0 replies; 53+ messages in thread
From: Pierre Neidhardt @ 2019-11-13 11:08 UTC (permalink / raw)
  To: Chris Marusich; +Cc: 38015, myglc2, help-guix, Alex Kost

[-- Attachment #1: Type: text/plain, Size: 1686 bytes --]

Hi Chris,

Thanks for testing!

> - The fonts were different than I remember.  Not sure why it happened,
>   but I'm guessing it had to do with the fact that I emptied my default
>   profile, and thus got rid of a lot of fonts accidentally.  At this
>   time, I doubt it's because of your changes.

Indeed, Emacs will only load fonts from the default profile.  Not sure
why.  But this is unrelated to this change (it also affects current Guix).

> - Aspell does not work: "ispell-init-process: Error: No word lists can
>   be found for the language "en_US"."  I think this happens because
>   the Guix package for aspell refers to the default profile:
>
>   (add-after 'install 'wrap-aspell
>    (lambda* (#:key outputs #:allow-other-keys)
>      (let ((bin/aspell (string-append (assoc-ref outputs "out")
>                                       "/bin/aspell")))
>        (wrap-program bin/aspell
>          '("ASPELL_CONF" "" =
>            ("${ASPELL_CONF:-\"dict-dir ${GUIX_PROFILE:-$HOME/.guix-profile}/lib/aspell\"}")))
>        #t)))

More precisely, it's because of the patch applied to ASPELL.
See bug #29686 for a discussion.  I have a clue how to patch this
properly, just need to get down to it.

> Finally: do you anticipate that this will cause any user-visible or
> backwards-incompatible changes that we should mention in the Guix
> channel's news file (and in the Guix NEWS file)?

As far I can see, the only incompatibility would arise if the user
explicitly referred to the guix-emacs.el variables that are now gone.

This change is cool enough I'm all for a NEWS entry nonetheless!

-- 
Pierre Neidhardt
https://ambrevar.xyz/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Emacs in server mode using a Shepherd user service (Was: Re: Emacs in multiple profiles)
  2019-11-02  1:12                                         ` Maxim Cournoyer
  (?)
  (?)
@ 2019-11-17 23:10                                         ` Chris Marusich
  2019-11-18 20:55                                           ` brettg
  -1 siblings, 1 reply; 53+ messages in thread
From: Chris Marusich @ 2019-11-17 23:10 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: myglc2, Alex Kost, help-guix

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

Hi Maxim,

Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> I typically start Emacs in server mode using a shepherd user service,
> so rarely restart Emacs.

If it isn't too much to ask, could you share the configuration you use
to accomplish this?  I'd like to do something similar, and I suspect
it's probably one of those things that is "easy to do" if you already
know exactly what to do, and rather time-consuming to figure out
otherwise.  Perhaps we could make another Cook Book section about it?

-- 
Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [bug#38015] Emacs in multiple profiles
  2019-11-13  7:18                                           ` Chris Marusich
@ 2019-11-18  5:50                                             ` Maxim Cournoyer
  -1 siblings, 0 replies; 53+ messages in thread
From: Maxim Cournoyer @ 2019-11-18  5:50 UTC (permalink / raw)
  To: Chris Marusich; +Cc: myglc2, 38015, Pierre Neidhardt, help-guix, Alex Kost

Hello Chris,

Chris Marusich <cmmarusich@gmail.com> writes:

[...]

I've skipped your previous questions, as I believe they were well
answered by Pierre (thank you, Pierre!).

>> Subject: [PATCH 2/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
>>  phase.
>>
>> +(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
>> +  "Augment the EMACSLOADPATH environment variable with the source directory."
>>    (let* ((source-directory (getcwd))
>> -         (input-elisp-directories (input-directories->el-directories
>> -                                   (inputs->directories inputs)))
>> -         (emacs-load-path-value
>> -          (string-join
>> -           (append input-elisp-directories (list source-directory))
>> -           ":" 'suffix)))
>> +         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
>> +                                               source-directory)))
>>      (setenv "EMACSLOADPATH" emacs-load-path-value)
>> -    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
>> -            emacs-load-path-value)))
>> +    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
>> +environment variable\n" source-directory)))
>
> It looks like the change is as follows: previously, we added multiple
> directories, including the source-directory, to the load path; after
> this change, we append just the source-directory to the EMACSLOADPATH.
> Can you remind me why we don't need to add the other elisp directories
> to the EMACSLOADPATH, too?  It seems to work, so I'm probably just
> missing something obvious.

The magic is in the set-paths phase that is inherited from the
gnu-build-system.  It uses the search path specification now specified in
the Emacs package to set the EMACSLOADPATH environment variable itself.

When building Elisp packages, it is useful to add the current source
directory to that environment variable, so that 'require' directives are
able to find the package's own modules (say, when running its test
suite).

>> Subject: [PATCH 3/3] gnu: emacs: Adapt the autoloads auxiliary code to use
>>  EMACSLOADPATH.
>
> As far as I can tell, this looks good to me, too.
>
> Finally: do you anticipate that this will cause any user-visible or
> backwards-incompatible changes that we should mention in the Guix
> channel's news file (and in the Guix NEWS file)?

Thanks for the review!  I can't anticipate any user-visible changes
except the current (incorrect) behavior.

This change is now live on master, with commit
47b3b4c2aa49e21f4cc32c97ff7bbbd069bb849c.  Thanks for testing :-).

Maxim

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [bug#38015] Emacs in multiple profiles
@ 2019-11-18  5:50                                             ` Maxim Cournoyer
  0 siblings, 0 replies; 53+ messages in thread
From: Maxim Cournoyer @ 2019-11-18  5:50 UTC (permalink / raw)
  To: Chris Marusich; +Cc: myglc2, 38015, help-guix, Alex Kost

Hello Chris,

Chris Marusich <cmmarusich@gmail.com> writes:

[...]

I've skipped your previous questions, as I believe they were well
answered by Pierre (thank you, Pierre!).

>> Subject: [PATCH 2/3] build-system: emacs: Simplify the SET-EMACS-LOAD-PATH
>>  phase.
>>
>> +(define* (add-source-to-load-path #:key dummy #:allow-other-keys)
>> +  "Augment the EMACSLOADPATH environment variable with the source directory."
>>    (let* ((source-directory (getcwd))
>> -         (input-elisp-directories (input-directories->el-directories
>> -                                   (inputs->directories inputs)))
>> -         (emacs-load-path-value
>> -          (string-join
>> -           (append input-elisp-directories (list source-directory))
>> -           ":" 'suffix)))
>> +         (emacs-load-path-value (string-append (getenv "EMACSLOADPATH") ":"
>> +                                               source-directory)))
>>      (setenv "EMACSLOADPATH" emacs-load-path-value)
>> -    (format #t "environment variable `EMACSLOADPATH' set to ~a\n"
>> -            emacs-load-path-value)))
>> +    (format #t "source directory ~s appended to the `EMACSLOADPATH' \
>> +environment variable\n" source-directory)))
>
> It looks like the change is as follows: previously, we added multiple
> directories, including the source-directory, to the load path; after
> this change, we append just the source-directory to the EMACSLOADPATH.
> Can you remind me why we don't need to add the other elisp directories
> to the EMACSLOADPATH, too?  It seems to work, so I'm probably just
> missing something obvious.

The magic is in the set-paths phase that is inherited from the
gnu-build-system.  It uses the search path specification now specified in
the Emacs package to set the EMACSLOADPATH environment variable itself.

When building Elisp packages, it is useful to add the current source
directory to that environment variable, so that 'require' directives are
able to find the package's own modules (say, when running its test
suite).

>> Subject: [PATCH 3/3] gnu: emacs: Adapt the autoloads auxiliary code to use
>>  EMACSLOADPATH.
>
> As far as I can tell, this looks good to me, too.
>
> Finally: do you anticipate that this will cause any user-visible or
> backwards-incompatible changes that we should mention in the Guix
> channel's news file (and in the Guix NEWS file)?

Thanks for the review!  I can't anticipate any user-visible changes
except the current (incorrect) behavior.

This change is now live on master, with commit
47b3b4c2aa49e21f4cc32c97ff7bbbd069bb849c.  Thanks for testing :-).

Maxim

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in server mode using a Shepherd user service (Was: Re: Emacs in multiple profiles)
  2019-11-17 23:10                                         ` Emacs in server mode using a Shepherd user service (Was: Re: Emacs in multiple profiles) Chris Marusich
@ 2019-11-18 20:55                                           ` brettg
  2019-11-19 21:57                                             ` Emacs in server mode using a Shepherd user service Maxim Cournoyer
  0 siblings, 1 reply; 53+ messages in thread
From: brettg @ 2019-11-18 20:55 UTC (permalink / raw)
  To: Chris Marusich; +Cc: Alex Kost, myglc2, help-guix, Help-Guix



On 18.11.2019 00:10, Chris Marusich wrote:
> Hi Maxim,
> 
> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
> 
>> I typically start Emacs in server mode using a shepherd user service,
>> so rarely restart Emacs.
> 
> If it isn't too much to ask, could you share the configuration you use
> to accomplish this?  I'd like to do something similar, and I suspect
> it's probably one of those things that is "easy to do" if you already
> know exactly what to do, and rather time-consuming to figure out
> otherwise.  Perhaps we could make another Cook Book section about it?

Seconding Chris' comment

Brett Gilio

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in server mode using a Shepherd user service
  2019-11-18 20:55                                           ` brettg
@ 2019-11-19 21:57                                             ` Maxim Cournoyer
  2019-11-19 21:58                                               ` brettg
  0 siblings, 1 reply; 53+ messages in thread
From: Maxim Cournoyer @ 2019-11-19 21:57 UTC (permalink / raw)
  To: brettg; +Cc: myglc2, Alex Kost, help-guix, Help-Guix

Hello!

brettg@posteo.net writes:

> On 18.11.2019 00:10, Chris Marusich wrote:
>> Hi Maxim,
>>
>> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>>
>>> I typically start Emacs in server mode using a shepherd user service,
>>> so rarely restart Emacs.
>>
>> If it isn't too much to ask, could you share the configuration you use
>> to accomplish this?  I'd like to do something similar, and I suspect
>> it's probably one of those things that is "easy to do" if you already
>> know exactly what to do, and rather time-consuming to figure out
>> otherwise.  Perhaps we could make another Cook Book section about it?
>
> Seconding Chris' comment
>
> Brett Gilio

A Cook Book section would indeed be great!  I originally was enlightened
by Dave Thompson on how to go about it.

In my ~/.config/shepherd directory, I have two Scheme files:

init.scm
--8<---------------cut here---------------start------------->8---
;;; Shepherd User Services
(load "services.scm")

(register-services
 emacs
 gpg-agent
 jackd
 ibus-daemon
 workrave)

;; Send shepherd into the background.
(action 'shepherd 'daemonize)

;; Services to start when shepherd starts:
(for-each start '(emacs
		  gpg-agent
		  ibus-daemon
		  workrave))
--8<---------------cut here---------------end--------------->8---

services.scm
--8<---------------cut here---------------start------------->8---
(define emacs
  (make <service>
    #:provides '(emacs)
    #:requires '()
    #:start (make-system-constructor "emacs --daemon")
    #:stop (make-system-destructor "emacsclient --eval \"(kill-emacs)\"")))

(define ibus-daemon
  (make <service>
    #:provides '(ibus-daemon)
    #:requires '()
    #:start (make-system-constructor "ibus-daemon --xim --daemonize --replace")
    #:stop (make-system-destructor "pkill ibus-daemon")))

(define jackd
  (make <service>
    #:provides '(jackd)
    #:requires '()
    #:start (make-system-constructor "jackd -d alsa &")
    #:stop (make-system-destructor "pkill jackd")))

(define gpg-agent
  (let ((pinentry (string-append (getenv "HOME")
				 "/.guix-profile/bin/pinentry")))
    (make <service>
      #:provides '(gpg-agent)
      #:requires '()
      #:start (make-system-constructor
	       (string-append "gpg-agent --daemon "
			      "--pinentry-program " pinentry))
      #:stop (make-system-destructor "gpgconf --kill gpg-agent"))))

(define workrave
  (make <service>
    #:provides '(workrave)
    #:requires '()
    #:start (make-system-constructor "workrave &")
    #:stop (make-system-destructor "pkill workrave")))
--8<---------------cut here---------------end--------------->8---

I've included all the services I currently use in case they might be of
interest.

The last bit that is needed (other than having the required software
installed to your profile, including shepherd), is to launch shepherd
when your session starts:

For me, that is simply calling 'shepherd' in my ~/.xsession, just before
the call to my window manager (ratpoison).

I then start Emacs using 'emacsclient -c'.

HTH!

Maxim

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in server mode using a Shepherd user service
  2019-11-19 21:57                                             ` Emacs in server mode using a Shepherd user service Maxim Cournoyer
@ 2019-11-19 21:58                                               ` brettg
  2019-11-19 22:03                                                 ` brettg
  0 siblings, 1 reply; 53+ messages in thread
From: brettg @ 2019-11-19 21:58 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: myglc2, Alex Kost, help-guix, Help-Guix



On 19.11.2019 22:57, Maxim Cournoyer wrote:
> Hello!
> 
> brettg@posteo.net writes:
> 
>> On 18.11.2019 00:10, Chris Marusich wrote:
>>> Hi Maxim,
>>> 
>>> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>>> 
>>>> I typically start Emacs in server mode using a shepherd user 
>>>> service,
>>>> so rarely restart Emacs.
>>> 
>>> If it isn't too much to ask, could you share the configuration you 
>>> use
>>> to accomplish this?  I'd like to do something similar, and I suspect
>>> it's probably one of those things that is "easy to do" if you already
>>> know exactly what to do, and rather time-consuming to figure out
>>> otherwise.  Perhaps we could make another Cook Book section about it?
>> 
>> Seconding Chris' comment
>> 
>> Brett Gilio
> 
> A Cook Book section would indeed be great!  I originally was 
> enlightened
> by Dave Thompson on how to go about it.
> 
> In my ~/.config/shepherd directory, I have two Scheme files:
> 
> init.scm
> --8<---------------cut here---------------start------------->8---
> ;;; Shepherd User Services
> (load "services.scm")
> 
> (register-services
>  emacs
>  gpg-agent
>  jackd
>  ibus-daemon
>  workrave)
> 
> ;; Send shepherd into the background.
> (action 'shepherd 'daemonize)
> 
> ;; Services to start when shepherd starts:
> (for-each start '(emacs
> 		  gpg-agent
> 		  ibus-daemon
> 		  workrave))
> --8<---------------cut here---------------end--------------->8---
> 
> services.scm
> --8<---------------cut here---------------start------------->8---
> (define emacs
>   (make <service>
>     #:provides '(emacs)
>     #:requires '()
>     #:start (make-system-constructor "emacs --daemon")
>     #:stop (make-system-destructor "emacsclient --eval 
> \"(kill-emacs)\"")))
> 
> (define ibus-daemon
>   (make <service>
>     #:provides '(ibus-daemon)
>     #:requires '()
>     #:start (make-system-constructor "ibus-daemon --xim --daemonize 
> --replace")
>     #:stop (make-system-destructor "pkill ibus-daemon")))
> 
> (define jackd
>   (make <service>
>     #:provides '(jackd)
>     #:requires '()
>     #:start (make-system-constructor "jackd -d alsa &")
>     #:stop (make-system-destructor "pkill jackd")))
> 
> (define gpg-agent
>   (let ((pinentry (string-append (getenv "HOME")
> 				 "/.guix-profile/bin/pinentry")))
>     (make <service>
>       #:provides '(gpg-agent)
>       #:requires '()
>       #:start (make-system-constructor
> 	       (string-append "gpg-agent --daemon "
> 			      "--pinentry-program " pinentry))
>       #:stop (make-system-destructor "gpgconf --kill gpg-agent"))))
> 
> (define workrave
>   (make <service>
>     #:provides '(workrave)
>     #:requires '()
>     #:start (make-system-constructor "workrave &")
>     #:stop (make-system-destructor "pkill workrave")))
> --8<---------------cut here---------------end--------------->8---
> 
> I've included all the services I currently use in case they might be of
> interest.
> 
> The last bit that is needed (other than having the required software
> installed to your profile, including shepherd), is to launch shepherd
> when your session starts:
> 
> For me, that is simply calling 'shepherd' in my ~/.xsession, just 
> before
> the call to my window manager (ratpoison).
> 
> I then start Emacs using 'emacsclient -c'.
> 
> HTH!
> 
> Maxim

Perfect, thank you Maxim!

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: Emacs in server mode using a Shepherd user service
  2019-11-19 21:58                                               ` brettg
@ 2019-11-19 22:03                                                 ` brettg
  0 siblings, 0 replies; 53+ messages in thread
From: brettg @ 2019-11-19 22:03 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: Alex Kost, myglc2, help-guix, Help-Guix



On 19.11.2019 22:58, brettg@posteo.net wrote:
> On 19.11.2019 22:57, Maxim Cournoyer wrote:
>> Hello!
>> 
>> brettg@posteo.net writes:
>> 
>>> On 18.11.2019 00:10, Chris Marusich wrote:
>>>> Hi Maxim,
>>>> 
>>>> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>>>> 
>>>>> I typically start Emacs in server mode using a shepherd user 
>>>>> service,
>>>>> so rarely restart Emacs.
>>>> 
>>>> If it isn't too much to ask, could you share the configuration you 
>>>> use
>>>> to accomplish this?  I'd like to do something similar, and I suspect
>>>> it's probably one of those things that is "easy to do" if you 
>>>> already
>>>> know exactly what to do, and rather time-consuming to figure out
>>>> otherwise.  Perhaps we could make another Cook Book section about 
>>>> it?
>>> 
>>> Seconding Chris' comment
>>> 
>>> Brett Gilio
>> 
>> A Cook Book section would indeed be great!  I originally was 
>> enlightened
>> by Dave Thompson on how to go about it.
>> 
>> In my ~/.config/shepherd directory, I have two Scheme files:
>> 
>> init.scm
>> --8<---------------cut here---------------start------------->8---
>> ;;; Shepherd User Services
>> (load "services.scm")
>> 
>> (register-services
>>  emacs
>>  gpg-agent
>>  jackd
>>  ibus-daemon
>>  workrave)
>> 
>> ;; Send shepherd into the background.
>> (action 'shepherd 'daemonize)
>> 
>> ;; Services to start when shepherd starts:
>> (for-each start '(emacs
>> 		  gpg-agent
>> 		  ibus-daemon
>> 		  workrave))
>> --8<---------------cut here---------------end--------------->8---
>> 
>> services.scm
>> --8<---------------cut here---------------start------------->8---
>> (define emacs
>>   (make <service>
>>     #:provides '(emacs)
>>     #:requires '()
>>     #:start (make-system-constructor "emacs --daemon")
>>     #:stop (make-system-destructor "emacsclient --eval 
>> \"(kill-emacs)\"")))
>> 
>> (define ibus-daemon
>>   (make <service>
>>     #:provides '(ibus-daemon)
>>     #:requires '()
>>     #:start (make-system-constructor "ibus-daemon --xim --daemonize 
>> --replace")
>>     #:stop (make-system-destructor "pkill ibus-daemon")))
>> 
>> (define jackd
>>   (make <service>
>>     #:provides '(jackd)
>>     #:requires '()
>>     #:start (make-system-constructor "jackd -d alsa &")
>>     #:stop (make-system-destructor "pkill jackd")))
>> 
>> (define gpg-agent
>>   (let ((pinentry (string-append (getenv "HOME")
>> 				 "/.guix-profile/bin/pinentry")))
>>     (make <service>
>>       #:provides '(gpg-agent)
>>       #:requires '()
>>       #:start (make-system-constructor
>> 	       (string-append "gpg-agent --daemon "
>> 			      "--pinentry-program " pinentry))
>>       #:stop (make-system-destructor "gpgconf --kill gpg-agent"))))
>> 
>> (define workrave
>>   (make <service>
>>     #:provides '(workrave)
>>     #:requires '()
>>     #:start (make-system-constructor "workrave &")
>>     #:stop (make-system-destructor "pkill workrave")))
>> --8<---------------cut here---------------end--------------->8---
>> 
>> I've included all the services I currently use in case they might be 
>> of
>> interest.
>> 
>> The last bit that is needed (other than having the required software
>> installed to your profile, including shepherd), is to launch shepherd
>> when your session starts:
>> 
>> For me, that is simply calling 'shepherd' in my ~/.xsession, just 
>> before
>> the call to my window manager (ratpoison).
>> 
>> I then start Emacs using 'emacsclient -c'.
>> 
>> HTH!
>> 
>> Maxim
> 
> Perfect, thank you Maxim!

I also want to throw Alex's git repo out there which is relevant

https://github.com/alezost/shepherd-config

^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2019-11-19 22:03 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-22 16:47 Emacs in multiple profiles Konrad Hinsen
2018-03-22 21:21 ` Alex Kost
2018-03-23  7:57   ` Konrad Hinsen
2018-03-23 17:25     ` Alex Kost
2018-03-24 12:14       ` Konrad Hinsen
2018-03-24 16:07         ` Alex Kost
2018-03-26  8:24           ` Konrad Hinsen
2018-03-27 15:38             ` Alex Kost
2018-04-18 19:49               ` myglc2
2018-05-05 16:01                 ` Konrad Hinsen
2019-10-16 19:54                 ` Pierre Neidhardt
2019-10-17 15:56                   ` George Clemmer
2019-10-18  8:42                     ` Pierre Neidhardt
2019-10-18 17:13                       ` George Clemmer
2019-10-19  8:57                         ` Pierre Neidhardt
2019-10-19  8:53                       ` Pierre Neidhardt
2019-10-19 19:35                   ` Maxim Cournoyer
2019-10-19 20:19                     ` Pierre Neidhardt
2019-10-25  3:05                       ` Maxim Cournoyer
2019-10-25 11:21                         ` Pierre Neidhardt
2019-10-28  3:45                           ` Maxim Cournoyer
2019-10-28  7:49                             ` Pierre Neidhardt
2019-10-28 12:46                           ` Maxim Cournoyer
2019-10-29  1:25                           ` Maxim Cournoyer
2019-10-29 10:44                             ` Pierre Neidhardt
2019-10-31  5:29                               ` Maxim Cournoyer
2019-10-31 12:29                                 ` Pierre Neidhardt
2019-11-01  4:25                                   ` [bug#38015] " Maxim Cournoyer
2019-11-01  4:25                                     ` Maxim Cournoyer
2019-11-01 19:06                                     ` [bug#38015] " Pierre Neidhardt
2019-11-01 19:06                                       ` Pierre Neidhardt
2019-11-02  1:12                                       ` [bug#38015] " Maxim Cournoyer
2019-11-02  1:12                                         ` Maxim Cournoyer
2019-11-02  9:41                                         ` [bug#38015] " Pierre Neidhardt
2019-11-02  9:41                                           ` Pierre Neidhardt
2019-11-17 23:10                                         ` Emacs in server mode using a Shepherd user service (Was: Re: Emacs in multiple profiles) Chris Marusich
2019-11-18 20:55                                           ` brettg
2019-11-19 21:57                                             ` Emacs in server mode using a Shepherd user service Maxim Cournoyer
2019-11-19 21:58                                               ` brettg
2019-11-19 22:03                                                 ` brettg
2019-11-12  5:14                                     ` [bug#38015] Emacs in multiple profiles Chris Marusich
2019-11-12  5:14                                       ` Chris Marusich
2019-11-12  7:16                                       ` Pierre Neidhardt
2019-11-12  7:16                                         ` Pierre Neidhardt
2019-11-13  7:18                                         ` Chris Marusich
2019-11-13  7:18                                           ` Chris Marusich
2019-11-13 11:08                                           ` Pierre Neidhardt
2019-11-13 11:08                                             ` Pierre Neidhardt
2019-11-18  5:50                                           ` Maxim Cournoyer
2019-11-18  5:50                                             ` Maxim Cournoyer
2019-10-20 13:58                   ` Alex Kost
2019-10-20 16:17                     ` Pierre Neidhardt
2018-04-20 20:52           ` Ricardo Wurmus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.