Re: Emacs in server mode using a Shepherd user service (Was: Re: Emacs in multiple profiles)

2019-11-18 Thread brettg




On 18.11.2019 00:10, Chris Marusich wrote:

Hi Maxim,

Maxim Cournoyer  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



Re: [bug#38015] Emacs in multiple profiles

2019-11-17 Thread Maxim Cournoyer
Hello Chris,

Chris Marusich  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



Emacs in server mode using a Shepherd user service (Was: Re: Emacs in multiple profiles)

2019-11-17 Thread Chris Marusich
Hi Maxim,

Maxim Cournoyer  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


signature.asc
Description: PGP signature


Re: [bug#38015] Emacs in multiple profiles

2019-11-13 Thread Pierre Neidhardt
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/


signature.asc
Description: PGP signature


Re: [bug#38015] Emacs in multiple profiles

2019-11-12 Thread Chris Marusich
Hi Pierre and Maxim,

Pierre Neidhardt  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  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 

Re: [bug#38015] Emacs in multiple profiles

2019-11-11 Thread Chris Marusich
Maxim Cournoyer  writes:

> [+ guix-patches]
>
> Hello!
>
> Pierre Neidhardt  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


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2019-11-02 Thread Pierre Neidhardt
Maxim Cournoyer  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/


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2019-11-01 Thread Maxim Cournoyer
Hello Pierre,

Pierre Neidhardt  writes:

> Maxim Cournoyer  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



Re: Emacs in multiple profiles

2019-11-01 Thread Pierre Neidhardt
Maxim Cournoyer  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/


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2019-10-31 Thread Maxim Cournoyer
[+ guix-patches]

Hello!

Pierre Neidhardt  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

>From d5dc7fd8a2406939346b44457859764a98afece0 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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 
 ;;; Copyright © 2016 ng0 
 ;;; Copyright © 2017 Marius Bakke 
-;;; Copyright © 2017 Maxim Cournoyer 
+;;; Copyright © 2017, 2019 Maxim Cournoyer 
 ;;; Copyright © 2017 Alex Vong 
 ;;; Copyright © 2017, 2018 Ricardo Wurmus 
 ;;; Copyright © 2017 Jan Nieuwenhuizen 
@@ -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

>From 9c4897347bee7f3b6afb97a6c766d57f0bee1b9d Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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 
 ;;; Copyright © 2016 David Thompson 
 ;;; Copyright © 2016 Alex Kost 
-;;; Copyright © 2018 Maxim Cournoyer 
+;;; Copyright © 2018, 2019 Maxim Cournoyer 
 ;;;
 ;;; 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 "/"
-

Re: Emacs in multiple profiles

2019-10-30 Thread Maxim Cournoyer
Hello!

Pierre Neidhardt  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
>From d5dc7fd8a2406939346b44457859764a98afece0 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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 
 ;;; Copyright © 2016 ng0 
 ;;; Copyright © 2017 Marius Bakke 
-;;; Copyright © 2017 Maxim Cournoyer 
+;;; Copyright © 2017, 2019 Maxim Cournoyer 
 ;;; Copyright © 2017 Alex Vong 
 ;;; Copyright © 2017, 2018 Ricardo Wurmus 
 ;;; Copyright © 2017 Jan Nieuwenhuizen 
@@ -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

>From 9c4897347bee7f3b6afb97a6c766d57f0bee1b9d Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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 
 ;;; Copyright © 2016 David Thompson 
 ;;; Copyright © 2016 Alex Kost 
-;;; Copyright © 2018 Maxim Cournoyer 
+;;; Copyright © 2018, 2019 Maxim Cournoyer 
 ;;;
 ;;; 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)

Re: Emacs in multiple profiles

2019-10-29 Thread Pierre Neidhardt
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/


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2019-10-28 Thread Maxim Cournoyer
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.

>From 1007969505b450fe12284bf81751ae6de25c367e Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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 
 ;;; Copyright © 2016 David Thompson 
 ;;; Copyright © 2016 Alex Kost 
-;;; Copyright © 2018 Maxim Cournoyer 
+;;; Copyright © 2018, 2019 Maxim Cournoyer 
 ;;;
 ;;; 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


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


Re: Emacs in multiple profiles

2019-10-28 Thread Maxim Cournoyer
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

>From 518b529fec93b8a767655f54e32aadade19da89f Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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 
 ;;; Copyright © 2016 ng0 
 ;;; Copyright © 2017 Marius Bakke 
-;;; Copyright © 2017 Maxim Cournoyer 
+;;; Copyright © 2017, 2019 Maxim Cournoyer 
 ;;; Copyright © 2017 Alex Vong 
 ;;; Copyright © 2017, 2018 Ricardo Wurmus 
 ;;; Copyright © 2017 Jan Nieuwenhuizen 
@@ -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

>From fe39bda4f2b6f8be433f8c89d80a6900e5732182 Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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..00
--- 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 
-;; Copyright © 2017 Kyle Meyer 
-
-;; 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 .
-
-;;; 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 ( 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)."
-  

Re: Emacs in multiple profiles

2019-10-27 Thread Maxim Cournoyer
Hello Pierre,

Pierre Neidhardt  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 

Re: Emacs in multiple profiles

2019-10-24 Thread Maxim Cournoyer
Hello Pierre,

Pierre Neidhardt  writes:

> Maxim Cournoyer  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.

>From 809bdcc447557134fbf4278c3b0d4b7d186d190d Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer 
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


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.


Re: Emacs in multiple profiles

2019-10-20 Thread Pierre Neidhardt
Alex Kost  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/


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2019-10-20 Thread Alex Kost
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



Re: Emacs in multiple profiles

2019-10-19 Thread Maxim Cournoyer
Hi Pierre,

Pierre Neidhardt  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



Re: Emacs in multiple profiles

2019-10-19 Thread Pierre Neidhardt
George Clemmer  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/


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2019-10-19 Thread Pierre Neidhardt
Pierre Neidhardt  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/


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2019-10-18 Thread George Clemmer


Hi Pierre,

Pierre Neidhardt  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



Re: Emacs in multiple profiles

2019-10-17 Thread George Clemmer


Pierre Neidhardt  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



Re: Emacs in multiple profiles

2019-10-16 Thread Pierre Neidhardt
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/


signature.asc
Description: PGP signature


Re: Emacs in multiple profiles

2018-05-05 Thread Konrad Hinsen
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.



Re: Emacs in multiple profiles

2018-04-20 Thread Ricardo Wurmus

Alex Kost  writes:

> Konrad Hinsen (2018-03-24 13:14 +0100) wrote:
>
>> Alex Kost  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





Re: Emacs in multiple profiles

2018-04-18 Thread myglc2
On 03/27/2018 at 18:38 Alex Kost writes:

> Konrad Hinsen (2018-03-26 10:24 +0200) wrote:
>
>> Alex Kost  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  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



emacs.scm
Description: Binary data


init0.el
Description: application/emacs-lisp


Re: Emacs in multiple profiles

2018-03-27 Thread Alex Kost
Konrad Hinsen (2018-03-26 10:24 +0200) wrote:

> Alex Kost  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  about it.  Perhaps other people
will agree with your point.

-- 
Alex



Re: Emacs in multiple profiles

2018-03-24 Thread Konrad Hinsen
Alex Kost  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.



Re: Emacs in multiple profiles

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

> Alex Kost  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



Re: Emacs in multiple profiles

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

> Hi Alex,
>
> Alex Kost  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



Re: Emacs in multiple profiles

2018-03-23 Thread Konrad Hinsen
Hi Alex,

Alex Kost  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.