Creating home-emacs-service-type

  • Done
  • quality assurance status badge
Details
6 participants
  • Joshua Branson
  • Liliana Marie Prikler
  • Liliana Marie Prikler
  • Christopher Baines
  • (
  • Zain Jabbar
Owner
unassigned
Submitted by
Zain Jabbar
Severity
normal
Merged with
Z
Z
Zain Jabbar wrote on 20 Oct 2022 03:59
CAH+UbWQRoqsgSWpFyb5xjvGsepp0mG86W6g_a4SU04yHFc_mgw@mail.gmail.com
Aloha Guix Development Team,

First submission of a patch to this mail service. Hopefully this
works. I welcome any and all feedback.

Attached is a patch which creates a new file
=/gnu/home/services/emacs.scm= which defines a new service
=home-emacs-service-type= and a configuration for said service
=home-emacs-configuration=. The configuration contains a list of
packages to add to the home-profile, and a list of expressions to add
into Emacs' =init.el= and =early-init.el=.

Here is an example of a home environment file which:

Adds the following packages:
- =bash=
- =emacs-next=
- =emacs-debbugs=
- =emacs-evil=
- =emacs-paredit=
- =emacs-anzu=

Overwrites the =.config/emacs/init.el= with:
#+BEGIN_SRC emacs-lisp
(evil-mode 1)
#+END_SRC

Overwrites the =.config/emacs/early-init.el= with:
#+BEGIN_SRC emacs-lisp
(setq warning-suppress-log-types '((comp) (comp))) (setq
warning-suppress-types '((comp) (comp)))
#+END_SRC

#+BEGIN_SRC scheme
(use-modules (gnu home services emacs)
(gnu home)
(gnu packages)
(ice-9 pretty-print)
(gnu services))

(define-public minimal-home-environment
(home-environment
(services
(list
(service home-emacs-service-type
(home-emacs-configuration
(packages
(list
(specification->package "bash")
(specification->package "emacs-next")
(specification->package "emacs-debbugs")
(specification->package "emacs-evil")
(specification->package "emacs-paredit")
(specification->package "emacs-anzu")))
(init '((evil-mode 1)))
(early-init '((setq warning-suppress-log-types '((comp) (comp)))
(setq warning-suppress-types '((comp) (comp)))))))))))

minimal-home-environment
#+END_SRC

Saving this text into a file =minimal-working-example.scm= allows us
to run this configuration with =guix home -N --share=/tmp container
./minimal-working-example.scm=.

--
Mahalo,
Zain Jabbar
Toggle diff (69 lines)
diff --git a/gnu/home/services/emacs.scm b/gnu/home/services/emacs.scm
deleted file mode 100644
index a3951c2a85..0000000000
--- a/gnu/home/services/emacs.scm
+++ /dev/null
@@ -1,63 +0,0 @@
-;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2022 Zain Jabbar <zaijab2000@gmail.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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
-
-(define-module (gnu home services emacs)
- #:use-module (gnu home)
- #:use-module (gnu packages)
- #:use-module (gnu services)
- #:use-module (gnu home services)
- #:use-module (gnu services)
- #:use-module (gnu services configuration)
- #:use-module (guix gexp)
-
- #:export (home-emacs-service-type
- home-emacs-configuration))
-
-(define file-likes? (list-of file-like?))
-
-(define-configuration/no-serialization home-emacs-configuration
- (packages
- (file-likes (list (specification->package "emacs")))
- "The packages this configuration will add to home-profile. Usually these will be emacs-* packages.")
- (early-init
- (list '())
- "A list whose contents will inserted into @file{$XDG_CONFIG_HOME/emacs/early-init.el}")
- (init
- (list '())
- "A list whose contents will inserted into @file{$XDG_CONFIG_HOME/emacs/init.el}"))
-
-(define home-emacs-service-type
- (service-type (name 'emacs-configuration)
- (extensions
- (list (service-extension
- home-profile-service-type
- (lambda (config) (home-emacs-configuration-packages config)))
- (service-extension
- home-xdg-configuration-files-service-type
- (lambda (config)
- (list
- `("emacs/early-init.el"
- ,(scheme-file "early-init.el"
- (home-emacs-configuration-early-init config)
- #:splice? #:t))
- `("emacs/init.el"
- ,(scheme-file "init.el"
- (home-emacs-configuration-init config)
- #:splice? #:t)))))))
- (default-value (home-emacs-configuration))
- (description "Configures Emacs and installs packages to home-profile.")))
L
L
Liliana Marie Prikler wrote on 20 Oct 2022 14:53
495a0fab9b20dd40f9fb1aef2261b60e053bf5cd.camel@ist.tugraz.at
Am Mittwoch, dem 19.10.2022 um 15:59 -1000 schrieb Zain Jabbar:
Toggle quote (11 lines)
> Aloha Guix Development Team,
>
> First submission of a patch to this mail service. Hopefully this
> works. I welcome any and all feedback.
>
> Attached is a patch which creates a new file
> =/gnu/home/services/emacs.scm= which defines a new service
> =home-emacs-service-type= and a configuration for said service
> =home-emacs-configuration=. The configuration contains a list of
> packages to add to the home-profile, and a list of expressions to add
> into Emacs' =init.el= and =early-init.el=.
Note that you reverted the patch direction.

Toggle quote (49 lines)
> Here is an example of a home environment file which:
>
> Adds the following packages:
> - =bash=
> - =emacs-next=
> - =emacs-debbugs=
> - =emacs-evil=
> - =emacs-paredit=
> - =emacs-anzu=
>
> Overwrites the =.config/emacs/init.el= with:
> #+BEGIN_SRC emacs-lisp
> (evil-mode 1)
> #+END_SRC
>
> Overwrites the =.config/emacs/early-init.el= with:
> #+BEGIN_SRC emacs-lisp
> (setq warning-suppress-log-types '((comp) (comp))) (setq
> warning-suppress-types '((comp) (comp)))
> #+END_SRC
>
> #+BEGIN_SRC scheme
> (use-modules (gnu home services emacs)
>      (gnu home)
>      (gnu packages)
>      (ice-9 pretty-print)
>      (gnu services))
>
> (define-public minimal-home-environment
>   (home-environment
>    (services
>     (list
>      (service home-emacs-service-type
>       (home-emacs-configuration
>        (packages
> (list
> (specification->package "bash")
> (specification->package "emacs-next")
> (specification->package "emacs-debbugs")
> (specification->package "emacs-evil")
> (specification->package "emacs-paredit")
> (specification->package "emacs-anzu")))
>        (init '((evil-mode 1)))
>        (early-init '((setq warning-suppress-log-types '((comp)
> (comp)))
>      (setq warning-suppress-types '((comp) (comp)))))))))))
>
> minimal-home-environment
> #+END_SRC
You should also take an extra-files argument, e.g. to add custom.el or
other elisp files that init.el might refer to.

Also, I'm not certain if "scheme-file" is the right primitve here –
Emacs Lisp does differ from Scheme, e.g. in keyword syntax among
others.

Cheers
Z
Z
Zain Jabbar wrote on 20 Oct 2022 23:30
(name . Liliana Marie Prikler)(address . liliana.prikler@ist.tugraz.at)
CAH+UbWSRquXwawF80ghL36sf91Zp4rxKTdEXLoVFrq0pHLZVZw@mail.gmail.com
Aloha All,

Thank you for your input.

Toggle quote (2 lines)
> Note that you reverted the patch direction.

Please forgive me for that. Is it possible to explain what I did
wrong? I will outline my steps to help you figure out what I did
incorrectly.

1. I cloned the repo
2. Used =guix shell -D guix=
3. Ran =./bootstrap=
4. Ran =./configure --localstatedir=/var=
5. Ran =make && make check=. By the way, my =make check= had a failed
test, I don't know if that was expected.
6. Made some commits
7. I used =git diff HEAD origin/HEAD > my-guix-patch.patch=.

I might have messed around too much in my cloned repo, throwing something off.

Toggle quote (3 lines)
> You should also take an extra-files argument, e.g. to add custom.el or
> other elisp files that init.el might refer to.

Understood. Attached as a new patch. =home-emacs-configuration= now
has an extra field =extra-files=. To use it, input a list of file
objects. The service will splice them into
=$XDG_CONFIG_HOME/emacs/{FILE}=. Here is an example configuration.
Using =guix home container= will allow you to see the file =greetings=
with contents "hello world" in =.config/emacs/=.

#+BEGIN_SRC scheme
(use-modules (gnu home services emacs)
(gnu home)
(guix gexp)
(gnu packages)
(ice-9 pretty-print)
(gnu services))

(home-environment
(services
(list
(service home-emacs-service-type
(home-emacs-configuration
(packages
(list
(specification->package "bash")
(specification->package "emacs-next")))
(extra-files (list (scheme-file "greetings" '(hello world)
#:splice? #:t))))))))
#+END_SRC

Toggle quote (4 lines)
> Also, I'm not certain if "scheme-file" is the right primitive here –
> Emacs Lisp does differ from Scheme, e.g. in keyword syntax among
> others.

I agree; using =scheme-file= for =emacs-lisp= feels blasphemous. There
are some odd errors associated with this method too. For example,
=#'foo= is the shorthand for =(function foo)= in Emacs Lisp but gets
turned into =(syntax foo)= when using Guile. Meaning a pure drag and
drop =init.el >> guile-sexp= has some things that need to be changed.
The fact that Emacs-Lisp and Guile Scheme use S-Expressions was
something I wanted to leverage. It becomes easy to write Elisp in the
parens of the =init= parameter because there is no context switching
(e.g. lispy works, cape-symbols works for Elisp in Scheme).

I am open to other forms of inputting the text in the files. This is a
bit high maka maka, but I would also like to see how "elegant" the
other methods of inserting Elisp look. That is, can we make it
desirable for people to integrate Elisp into Guile Scheme moreso than
a =local-file= declaration. Using backquotes and S-Expressions allows
for some variables from Guile to be placed into the Emacs
configuration like the system type, user names, and emails.

On Thu, Oct 20, 2022 at 2:54 AM Liliana Marie Prikler
<liliana.prikler@ist.tugraz.at> wrote:
Toggle quote (75 lines)
>
> Am Mittwoch, dem 19.10.2022 um 15:59 -1000 schrieb Zain Jabbar:
> > Aloha Guix Development Team,
> >
> > First submission of a patch to this mail service. Hopefully this
> > works. I welcome any and all feedback.
> >
> > Attached is a patch which creates a new file
> > =/gnu/home/services/emacs.scm= which defines a new service
> > =home-emacs-service-type= and a configuration for said service
> > =home-emacs-configuration=. The configuration contains a list of
> > packages to add to the home-profile, and a list of expressions to add
> > into Emacs' =init.el= and =early-init.el=.
> Note that you reverted the patch direction.
>
> > Here is an example of a home environment file which:
> >
> > Adds the following packages:
> > - =bash=
> > - =emacs-next=
> > - =emacs-debbugs=
> > - =emacs-evil=
> > - =emacs-paredit=
> > - =emacs-anzu=
> >
> > Overwrites the =.config/emacs/init.el= with:
> > #+BEGIN_SRC emacs-lisp
> > (evil-mode 1)
> > #+END_SRC
> >
> > Overwrites the =.config/emacs/early-init.el= with:
> > #+BEGIN_SRC emacs-lisp
> > (setq warning-suppress-log-types '((comp) (comp))) (setq
> > warning-suppress-types '((comp) (comp)))
> > #+END_SRC
> >
> > #+BEGIN_SRC scheme
> > (use-modules (gnu home services emacs)
> > (gnu home)
> > (gnu packages)
> > (ice-9 pretty-print)
> > (gnu services))
> >
> > (define-public minimal-home-environment
> > (home-environment
> > (services
> > (list
> > (service home-emacs-service-type
> > (home-emacs-configuration
> > (packages
> > (list
> > (specification->package "bash")
> > (specification->package "emacs-next")
> > (specification->package "emacs-debbugs")
> > (specification->package "emacs-evil")
> > (specification->package "emacs-paredit")
> > (specification->package "emacs-anzu")))
> > (init '((evil-mode 1)))
> > (early-init '((setq warning-suppress-log-types '((comp)
> > (comp)))
> > (setq warning-suppress-types '((comp) (comp)))))))))))
> >
> > minimal-home-environment
> > #+END_SRC
> You should also take an extra-files argument, e.g. to add custom.el or
> other elisp files that init.el might refer to.
>
> Also, I'm not certain if "scheme-file" is the right primitve here –
> Emacs Lisp does differ from Scheme, e.g. in keyword syntax among
> others.
>
> Cheers



--
Mahalo,
Zain Jabbar
L
L
Liliana Marie Prikler wrote on 21 Oct 2022 08:05
(name . Zain Jabbar)(address . zaijab2000@gmail.com)
77fbe7e648edfc15c8007616199a867dbae72b71.camel@ist.tugraz.at
Am Donnerstag, dem 20.10.2022 um 11:30 -1000 schrieb Zain Jabbar:
Toggle quote (21 lines)
> Aloha All,
>
> Thank you for your input.
>
> > Note that you reverted the patch direction.
>
> Please forgive me for that. Is it possible to explain what I did
> wrong? I will outline my steps to help you figure out what I did
> incorrectly.
>
> 1. I cloned the repo
> 2. Used =guix shell -D guix=
> 3. Ran =./bootstrap=
> 4. Ran =./configure --localstatedir=/var=
> 5. Ran =make && make check=. By the way, my =make check= had a failed
> test, I don't know if that was expected.
> 6. Made some commits
> 7. I used =git diff HEAD origin/HEAD > my-guix-patch.patch=.
>
> I might have messed around too much in my cloned repo, throwing
> something off.
Instead of 6+7, write a single commit and use =git format-patch=.

You can of course do multi-patch series, but this feature seems not to
be one that requires that. Always clean up your commit log after a
hacking session ;)

Toggle quote (31 lines)
> > You should also take an extra-files argument, e.g. to add custom.el
> > or other elisp files that init.el might refer to.
>
> Understood. Attached as a new patch. =home-emacs-configuration= now
> has an extra field =extra-files=. To use it, input a list of file
> objects. The service will splice them into
> =$XDG_CONFIG_HOME/emacs/{FILE}=. Here is an example configuration.
> Using =guix home container= will allow you to see the file
> =greetings=
> with contents "hello world" in =.config/emacs/=.
>
> #+BEGIN_SRC scheme
> (use-modules (gnu home services emacs)
>      (gnu home)
>      (guix gexp)
>      (gnu packages)
>      (ice-9 pretty-print)
>      (gnu services))
>
> (home-environment
>  (services
>   (list
>    (service home-emacs-service-type
>     (home-emacs-configuration
>      (packages
>       (list
>        (specification->package "bash")
>        (specification->package "emacs-next")))
>      (extra-files (list (scheme-file "greetings" '(hello world)
> #:splice? #:t))))))))
> #+END_SRC
Is that #:splice? #t meant to be there?

Also, why is bash required here? You should perhaps also distinguish
the emacs package and the emacs-* packages like so:

(emacs emacs-next)
(packages (list emacs-dash emacs-tempel))

As a future extension, it'd be nice if we could use this service to
easily specify native compilation for emacs packages, but for this one
would have to lay some groundwork in emacs-build-system.

Toggle quote (14 lines)
> > Also, I'm not certain if "scheme-file" is the right primitive here
> > – Emacs Lisp does differ from Scheme, e.g. in keyword syntax among
> > others.
>
> I agree; using =scheme-file= for =emacs-lisp= feels blasphemous.
> There are some odd errors associated with this method too. For
> example, =#'foo= is the shorthand for =(function foo)= in Emacs Lisp
> but gets turned into =(syntax foo)= when using Guile. Meaning a pure
> drag and drop =init.el >> guile-sexp= has some things that need to be
> changed.
> The fact that Emacs-Lisp and Guile Scheme use S-Expressions was
> something I wanted to leverage. It becomes easy to write Elisp in the
> parens of the =init= parameter because there is no context switching
> (e.g. lispy works, cape-symbols works for Elisp in Scheme).
Note that Guile has an elisp reader, albeit a broken one, but no means
to switch languages inside files.

Toggle quote (7 lines)
> I am open to other forms of inputting the text in the files. This is
> a bit high maka maka, but I would also like to see how "elegant" the
> other methods of inserting Elisp look. That is, can we make it
> desirable for people to integrate Elisp into Guile Scheme moreso than
> a =local-file= declaration. Using backquotes and S-Expressions allows
> for some variables from Guile to be placed into the Emacs
> configuration like the system type, user names, and emails.
I think taking a list of file-like objects and concatenating their
contents might be worth considering. That's a bit more overhead, but
we'd have a cleaner separation between fragments that have the same
semantics in Scheme and those that don't.

Cheers
J
J
Joshua Branson wrote on 21 Oct 2022 17:42
(name . Liliana Marie Prikler)(address . liliana.prikler@ist.tugraz.at)
87o7u55gkg.fsf@dismail.de
Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> writes:

Toggle quote (28 lines)
> Am Donnerstag, dem 20.10.2022 um 11:30 -1000 schrieb Zain Jabbar:
>> Aloha All,
>>
>> Thank you for your input.
>>
>> > Note that you reverted the patch direction.
>>
>> Please forgive me for that. Is it possible to explain what I did
>> wrong? I will outline my steps to help you figure out what I did
>> incorrectly.
>>
>> 1. I cloned the repo
>> 2. Used =guix shell -D guix=
>> 3. Ran =./bootstrap=
>> 4. Ran =./configure --localstatedir=/var=
>> 5. Ran =make && make check=. By the way, my =make check= had a failed
>> test, I don't know if that was expected.
>> 6. Made some commits
>> 7. I used =git diff HEAD origin/HEAD > my-guix-patch.patch=.
>>
>> I might have messed around too much in my cloned repo, throwing
>> something off.
> Instead of 6+7, write a single commit and use =git format-patch=.
>
> You can of course do multi-patch series, but this feature seems not to
> be one that requires that. Always clean up your commit log after a
> hacking session ;)

I personally find it really easy to use git send-email. :)

Assuming you are in the guix git directory, then this command will send
the latest commit as a patch to the guix-patches email list.

#+BEGIN_SRC sh
git send-email --to='guix-patches@gnu.org' \
--cc='efraim@flashner.co.il' \
--subject-prefix='Patch staging ' --annotate HEAD^
#+END_SRC

This website will walk you through setting up git send email.

Z
Z
Zain Jabbar wrote on 22 Oct 2022 09:09
(name . Liliana Marie Prikler)(address . liliana.prikler@ist.tugraz.at)
CAH+UbWRC5qOjsTnsanmkmRA0RQQwR_A-NNLes6kyvJ1EXrOKgg@mail.gmail.com
Aloha All,

Apologies for the delay.

Toggle quote (2 lines)
> Instead of 6+7, write a single commit and use =git format-patch=.

Understood. Used =git format-patch HEAD~1= after =git reset --hard
origin/HEAD= to only have a single commit.

Toggle quote (2 lines)
> Is that #:splice? #t meant to be there?

Yes, I believe so. Without the =#:splice? #:t= everything within the
file is surrounded by parenthesis. For example

#+BEGIN_SRC scheme
(use-modules (gnu home services emacs)
(gnu home)
(guix gexp)
(gnu packages)
(ice-9 pretty-print)
(gnu services))


(home-environment
(services
(list
(service home-emacs-service-type
(home-emacs-configuration
(packages
(list
(specification->package "bash")
(specification->package "emacs-next")))
(extra-files (list (scheme-file "greetings" '((setq x 42) (setq y
10)) #:splice? #:t))))))))
#+END_SRC

Places =(setq x 42)(setq y 10)= (no whitespace so it's kind of hard to
read) in =greetings=. That would properly run as Elisp. Without the
splicing we obtain =((setq x 42) (setq y 10))= which assumes we will
call a function =(setq x 42)= on the argument =(setq y 10)= which will
not work.

Toggle quote (2 lines)
> Also, why is bash required here?

Bash was there for debugging purposes. You are right though, it does
not make a lot of sense to be there. It should be in the
=home-environment= =packages= not in the =home-emacs-configuration=.
Surprisingly if =bash= was not installed, =sh= was nowhere to be found
from within =guix home container ${FILE}= and Emacs info manuals were
not readable (something Joshua Branson helped me iron out).

Toggle quote (5 lines)
> You should perhaps also distinguish
> the emacs package and the emacs-* packages like so:
> (emacs emacs-next)
> (packages (list emacs-dash emacs-tempel))

Attached is a patch with =emacs= as a configuration type and here is
an example =home-environment= where =bash= installed using the
=packages= slot.

#+BEGIN_SRC scheme
(use-modules (gnu home services emacs)
(gnu home)
(guix gexp)
(gnu packages)
(ice-9 pretty-print)
(gnu services))

(home-environment
(packages (list (specification->package "bash")))
(services
(list
(service home-emacs-service-type))))
#+END_SRC

In the guix-dev mailing list, it has been discussed that Andrew
Tropin's method of declaring a config is worthwhile inspiration. Here
is an example configuration block.

#+BEGIN_SRC scheme
(define emacs-configure-rde-keymaps
(rde-emacs-configuration-package
'rde-keymaps
`((defvar rde-app-map nil "Prefix keymap for applications.")
(define-prefix-command 'rde-app-map nil)
(defvar rde-toggle-map nil "\
Prefix keymap for binding various minor modes for toggling functionalitty.")
(define-prefix-command 'rde-toggle-map nil))
#:summary "Keymaps inteded for reuse among configure-* packages"))
#+END_SRC

This is a bit closer to the current patch using S-Expressions over
files. Perhaps I should wait for more people to chime in. Maybe I can
try to please both sides. Make a conditional, if the =init= or
=early-init= form is empty (as it is by default) then allow for a file
named =init.el= in the =extra-files= argument.

On Thu, Oct 20, 2022 at 8:06 PM Liliana Marie Prikler
<liliana.prikler@ist.tugraz.at> wrote:
Toggle quote (105 lines)
>
> Am Donnerstag, dem 20.10.2022 um 11:30 -1000 schrieb Zain Jabbar:
> > Aloha All,
> >
> > Thank you for your input.
> >
> > > Note that you reverted the patch direction.
> >
> > Please forgive me for that. Is it possible to explain what I did
> > wrong? I will outline my steps to help you figure out what I did
> > incorrectly.
> >
> > 1. I cloned the repo
> > 2. Used =guix shell -D guix=
> > 3. Ran =./bootstrap=
> > 4. Ran =./configure --localstatedir=/var=
> > 5. Ran =make && make check=. By the way, my =make check= had a failed
> > test, I don't know if that was expected.
> > 6. Made some commits
> > 7. I used =git diff HEAD origin/HEAD > my-guix-patch.patch=.
> >
> > I might have messed around too much in my cloned repo, throwing
> > something off.
> Instead of 6+7, write a single commit and use =git format-patch=.
>
> You can of course do multi-patch series, but this feature seems not to
> be one that requires that. Always clean up your commit log after a
> hacking session ;)
>
> > > You should also take an extra-files argument, e.g. to add custom.el
> > > or other elisp files that init.el might refer to.
> >
> > Understood. Attached as a new patch. =home-emacs-configuration= now
> > has an extra field =extra-files=. To use it, input a list of file
> > objects. The service will splice them into
> > =$XDG_CONFIG_HOME/emacs/{FILE}=. Here is an example configuration.
> > Using =guix home container= will allow you to see the file
> > =greetings=
> > with contents "hello world" in =.config/emacs/=.
> >
> > #+BEGIN_SRC scheme
> > (use-modules (gnu home services emacs)
> > (gnu home)
> > (guix gexp)
> > (gnu packages)
> > (ice-9 pretty-print)
> > (gnu services))
> >
> > (home-environment
> > (services
> > (list
> > (service home-emacs-service-type
> > (home-emacs-configuration
> > (packages
> > (list
> > (specification->package "bash")
> > (specification->package "emacs-next")))
> > (extra-files (list (scheme-file "greetings" '(hello world)
> > #:splice? #:t))))))))
> > #+END_SRC
> Is that #:splice? #t meant to be there?
>
> Also, why is bash required here? You should perhaps also distinguish
> the emacs package and the emacs-* packages like so:
>
> (emacs emacs-next)
> (packages (list emacs-dash emacs-tempel))
>
> As a future extension, it'd be nice if we could use this service to
> easily specify native compilation for emacs packages, but for this one
> would have to lay some groundwork in emacs-build-system.
>
> > > Also, I'm not certain if "scheme-file" is the right primitive here
> > > – Emacs Lisp does differ from Scheme, e.g. in keyword syntax among
> > > others.
> >
> > I agree; using =scheme-file= for =emacs-lisp= feels blasphemous.
> > There are some odd errors associated with this method too. For
> > example, =#'foo= is the shorthand for =(function foo)= in Emacs Lisp
> > but gets turned into =(syntax foo)= when using Guile. Meaning a pure
> > drag and drop =init.el >> guile-sexp= has some things that need to be
> > changed.
> > The fact that Emacs-Lisp and Guile Scheme use S-Expressions was
> > something I wanted to leverage. It becomes easy to write Elisp in the
> > parens of the =init= parameter because there is no context switching
> > (e.g. lispy works, cape-symbols works for Elisp in Scheme).
> Note that Guile has an elisp reader, albeit a broken one, but no means
> to switch languages inside files.
>
> > I am open to other forms of inputting the text in the files. This is
> > a bit high maka maka, but I would also like to see how "elegant" the
> > other methods of inserting Elisp look. That is, can we make it
> > desirable for people to integrate Elisp into Guile Scheme moreso than
> > a =local-file= declaration. Using backquotes and S-Expressions allows
> > for some variables from Guile to be placed into the Emacs
> > configuration like the system type, user names, and emails.
> I think taking a list of file-like objects and concatenating their
> contents might be worth considering. That's a bit more overhead, but
> we'd have a cleaner separation between fragments that have the same
> semantics in Scheme and those that don't.
>
> Cheers



--
Mahalo,
Zain Jabbar
From e39ea1708d5b7121cac9a9f6c7953c15633b01c0 Mon Sep 17 00:00:00 2001
From: Zain Jabbar <zaijab2000@gmail.com>
Date: Fri, 21 Oct 2022 20:48:31 -1000
Subject: [PATCH] Adding =home-emacs-service-type= and
=home-emacs-configuration=. A service to configure emacs using guix home.

---
gnu/home/services/emacs.scm | 72 +++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
create mode 100644 gnu/home/services/emacs.scm

Toggle diff (80 lines)
diff --git a/gnu/home/services/emacs.scm b/gnu/home/services/emacs.scm
new file mode 100644
index 0000000000..1da6987411
--- /dev/null
+++ b/gnu/home/services/emacs.scm
@@ -0,0 +1,72 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Zain Jabbar <zaijab2000@gmail.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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu home services emacs)
+ #:use-module (gnu home)
+ #:use-module (gnu packages)
+ #:use-module (gnu services)
+ #:use-module (gnu home services)
+ #:use-module (gnu services)
+ #:use-module (gnu services configuration)
+ #:use-module (guix gexp)
+
+ #:export (home-emacs-service-type
+ home-emacs-configuration))
+
+(define file-likes? (list-of file-like?))
+
+(define-configuration/no-serialization home-emacs-configuration
+ (emacs
+ (file-like (specification->package "emacs-next"))
+ "The Emacs package to use.")
+ (packages
+ (file-likes '())
+ "The packages this configuration will add to home-profile. Usually these will be emacs-* packages.")
+ (early-init
+ (list '())
+ "A list whose contents will inserted into @file{$XDG_CONFIG_HOME/emacs/early-init.el}")
+ (init
+ (list '())
+ "A list whose contents will inserted into @file{$XDG_CONFIG_HOME/emacs/init.el}")
+ (extra-files
+ (file-likes '())
+ "A list of files to be placed in @file{$XDG_CONFIG_HOME/emacs/}."))
+
+(define home-emacs-service-type
+ (service-type (name 'emacs-configuration)
+ (extensions
+ (list (service-extension
+ home-profile-service-type
+ (lambda (config) `(,(home-emacs-configuration-emacs config)
+ ,@(home-emacs-configuration-packages config))))
+ (service-extension
+ home-xdg-configuration-files-service-type
+ (lambda (config)
+ `(("emacs/early-init.el"
+ ,(scheme-file "early-init.el"
+ (home-emacs-configuration-early-init config)
+ #:splice? #:t))
+ ("emacs/init.el"
+ ,(scheme-file "init.el"
+ (home-emacs-configuration-init config)
+ #:splice? #:t))
+ ,@(map (lambda (file) (list (string-append "emacs/" (scheme-file-name file))
+ file))
+ (home-emacs-configuration-extra-files config)))))))
+ (default-value (home-emacs-configuration))
+ (description "Configures Emacs and installs packages to home-profile.")))
--
2.38.0
L
L
Liliana Marie Prikler wrote on 22 Oct 2022 11:41
Re: [PATCH 1/1] gnu: home: Add home-emacs-service-type.
(address . control@debbugs.gnu.org)
9c453dd100e4d66d458a217f448c0b2362adc2f2.camel@gmail.com
merge 58693 58652
thanks

Am Freitag, dem 21.10.2022 um 20:24 +0100 schrieb (:
Toggle quote (51 lines)
> +(define-configuration/no-serialization home-emacs-configuration
> +  (emacs
> +   (file-like emacs)
> +   "The package providing @file{/bin/emacs}.")
> +  (packages
> +   (list-of-file-likes '())
> +   "Packages to add to the Emacs plugin load path.")
> +  (native-compile?
> +   (boolean #f)
> +   "Whether to compile the @code{packages} using the Emacs package
> +provided as the value of the @code{emacs} field, which will enable
> +native compilation if the @code{emacs} package supports it.")
> +  (init-file
> +   (file-like (plain-file "init.el" ""))
> +   "File-like to use as the initialisation Lisp file.")
> +  (early-init-file
> +   (file-like (plain-file "early-init.el" ""))
> +   "File-like to use as the pre-initialisation Lisp file.")
> +  (debug?
> +   (boolean #f)
> +   "Whether to enable debugging."))
> +
> +(define (home-emacs-profile-packages config)
> +  (list (home-emacs-configuration-emacs config)))
> +
> +(define (home-emacs-transformed-packages config)
> +  (map (if (home-emacs-configuration-native-compile? config)
> +           (package-input-rewriting
> +            `((,emacs-minimal
> +              . ,(home-emacs-configuration-emacs config))))
> +           identity)
> +       (let ((packages (home-emacs-configuration-packages config)))
> +         (concatenate
> +          (cons packages
> +                (map (compose (cute map second <>)
> +                              package-transitive-propagated-inputs)
> +                     packages))))))
> +
> +(define (home-emacs-shepherd-services config)
> +  (list (shepherd-service
> +         (provision '(emacs))
> +         (documentation "Start the Emacs daemon.")
> +         (modules '((ice-9 ftw)
> +                    (srfi srfi-1)
> +                    (srfi srfi-26)))
> +         (start
> +          #~(make-forkexec-constructor
> +             (list #$(file-append
> +                      (home-emacs-configuration-emacs config)
> +                      "/bin/emacs")
> +                   "--fg-daemon" "--eval"
You should probably use a systemd-style constructor/destructor pair.

Toggle quote (10 lines)
> +                   (format #f "~s"
> +                           `(progn
> +                             (setq custom-file
> +                                   (concat (or (getenv
> "XDG_CONFIG_HOME")
> +                                               (concat (getenv
> "HOME")
> +                                                       "/.config"))
> +                                           "/emacs/custom.el"))
> +                             (load custom-file)))
This one should be customizable by the user using init.el or early-
init.el -- alternatively, you could set up a custom-file parameter and
use that *if given*.

Toggle quote (8 lines)
> +                   #$@(if (home-emacs-configuration-debug? config)
> +                          (list "--debug-init")
> +                          '()))
> +             #:log-file
> +             (format #f "~a/emacs.log"
> +                     (or (getenv "XDG_LOG_HOME")
> +                         (format #f "~a/.local/var/log"
> +                                 (getenv "HOME"))))
XDG_LOG_HOME and ~/.local/var are guix home idiosyncrasies that ought
to be removed. The XDG-supported variable/value pair is XDG_STATE_HOME
and ~/.local/state.

Toggle quote (35 lines)
> +             #:environment-variables
> +             (let ((env-var
> +                    (lambda (name path)
> +                      (define (regular-directory? directory)
> +                        (not (member directory (list "." ".."))))
> +
> +                      (define (package-paths package)
> +                        (let ((directory (string-append package "/"
> path)))
> +                          (if (file-exists? directory)
> +                              (cons directory
> +                                    (map (cute string-append
> directory "/" <>)
> +                                         (scandir directory regular-
> directory?)))
> +                              '())))
> +
> +                      (let ((old-value (getenv name)))
> +                        (string-append
> +                         name "="
> +                         (string-join
> +                          (append-map
> +                           package-paths
> +                           (list #$@(home-emacs-transformed-packages
> config)))
> +                          ":" (if old-value
> +                                  'suffix
> +                                  'infix))
> +                         (or old-value ""))))))
> +               (append (default-environment-variables)
> +                       (list (env-var "EMACSLOADPATH"
> +                                      "share/emacs/site-lisp")
> +                             (env-var "EMACSNATIVELOADPATH"
> +                                      "lib/emacs/native-site-
> lisp"))))))
You should collect the emacs package plus lisp packages into a profile.
This will make it easier to set emacs-related variables.
Alternatively, you could use (guix search-paths) directly.

Toggle quote (12 lines)
> +         (stop
> +          #~(make-forkexec-constructor
> +             (list #$(file-append
> +                      (home-emacs-configuration-emacs config)
> +                      "/bin/emacsclient")
> +                   "--eval" "(kill-emacs)"))))))
> +
> +(define (home-emacs-xdg-configuration-files config)
> +  `(("emacs/early-init.el"
> +     ,(home-emacs-configuration-early-init-file config))
> +    ("emacs/init.el"
> +     ,(home-emacs-configuration-init-file config))))
You're missing an escape hatch for additional elisp files like
custom.el

Cheers
C
C
Christopher Baines wrote on 3 Nov 2022 17:15
tag 58693 moreinfo
(address . control@debbugs.gnu.org)
87bkpodng5.fsf@cbaines.net
tags 58693 + moreinfo
quit
(
Superseded
(address . control@debbugs.gnu.org)
CRJY94RLQVVE.2KS5EOOGXQDHL@guix-framework
close 58693
thanks

Superseded by 62549.

-- (
-----BEGIN PGP SIGNATURE-----

iQGzBAABCgAdFiEE6Vh10NblKE5doNlW7ImHg/nqI20FAmQl3PUACgkQ7ImHg/nq
I21cwQv/aXtTZ1l053bit113L8wSRhhyBQxBHj8UPhP2EFcrbDyqINf5WE8JHwcc
dOm28jKYWUhB4BkuiUlRiDQns91e9A4uAi4rwzE+902k6UFr2sfO4EA9j1iXNqWb
fBedyaUsvsKQqjkJ7DB2uH7gY304bFYspoEXP3ID4OT2xq2skF9pa+J3twvlhZaO
2RAvGQ2AkoCVW0KEeKCpTZYTQv451/gq2RXUBG/uPEuZ6dOx+qXlHMyOx9ECgRcL
S9XxqQGAIPRQKhU97rkWd7Q0MmtU2GxjP2UIK/p+lR713fnMwiyJaH8Yh+B3Bm7s
zMlzPbDFxE8D66EhilFiiRc/FdKjsLDrOzLDBOmaWDiVC7BdY83SuDw/OJ3ekTK3
+vpH9EfnkY9g48ky8CiqMz0wZwYJPul1/CNoJk+lAWxId7jLqIAl1psQtrGoB4Bn
3hiH+RKJlTNtUeLk2nGVWi3KDOQWH4z/rIA8T/Cu/ASgMHn7fvVL+F72BCiJQeko
t7BxHJiU
=lV7R
-----END PGP SIGNATURE-----


?