# Emacs key bindings in Guile REPL?

**URL:** <https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202>\
**Category:** Guix\
**Created:** [February 4, 2024, 5:32pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202 "2024-02-04T17:32:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 4, 2024, 5:32pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/1 "2024-02-04T17:32:48Z")

</div>

Anyone here figured how to get the guile REPL to enable Emacs key-bindings? LLM suggested changes to ~/.inputrc to specify Emacs mode but that didn’t seem to work. Also, looking at the linked libs for the guile binary suggests perhaps no readline?

---

<div class="post-metadata">

**Author:** ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)\
**Post date:** [February 4, 2024, 6:21pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/2 "2024-02-04T18:21:17Z")

</div>

This is answered within `man guile` \[1\]:

> FILES
> 
> ```auto
> ~/.guile
> 
> ```
> 
> A Guile script that is executed before any other processing occurs. For example, the following `.guile` activates guile’s readline interface:
> 
> ```scheme
> (use-modules (ice-9 readline))
> (activate-readline)
> 
> ```

Tested it on Guile 3.0.9@msys2 and 3.0.7@ubuntu, works fine 🙂

* * *

1. But I originally found the answer on StackOveflow: [terminal - How to use arrow keys in mzscheme/guile REPL? - Stack Overflow](https://stackoverflow.com/a/18631127/1139697)

---

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 4, 2024, 6:33pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/3 "2024-02-04T18:33:51Z")

</div>

Correct that the guix `guile` package does not include readline support. Must install `guile-readline` and then reload the GUIX /etc/profile or just get a new login shell.

Without that package the changes to `~/.guile` causes REPL to throw error at startup.

ref: [Error starting Guile with `readline` support - Stack Overflow](https://stackoverflow.com/questions/71042830/error-starting-guile-with-readline-support)

---

<div class="post-metadata">

**Author:** ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)\
**Post date:** [February 4, 2024, 7:19pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/4 "2024-02-04T19:19:40Z")

</div>

Ah, I’m not on Guix, seems like both msys2 and Ubuntu/Debian distribute that module by default.

---

<div class="post-metadata">

**Author:** ![ryuslash](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ryuslash/32/66_2.png) [@ryuslash](https://forum.systemcrafters.net/u/ryuslash)\
**Post date:** [February 5, 2024, 12:03am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/5 "2024-02-05T00:03:32Z")

</div>

Or you could use guix-home to set it up 🙂

> **[dotfiles/oni/home/services/guile.scm at master](https://code.ryuslash.org/ryuslash/dotfiles/src/branch/master/oni/home/services/guile.scm)**
>
> dotfiles - My current dotfiles

And then just use

```scheme
(home-environment
 # ...
 (services
  (list
   # ...
   home-guile-service)))
```

---

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 5, 2024, 1:49am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/6 "2024-02-05T01:49:29Z")

</div>

Previous attempts at guix-home failed. Mostly due to lack of guile experience. Working on that though.

---

<div class="post-metadata">

**Author:** ![daviwil](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/daviwil/32/1_2.png) [@daviwil](https://forum.systemcrafters.net/u/daviwil)\
**Post date:** [February 5, 2024, 8:56am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/7 "2024-02-05T08:56:18Z")

</div>

`guix shell` is a better option for one-off command executions like this:

```sh
guix shell guile guile-readline -- guile

```

That will launch the Guile command line REPL with the `guile-readline` package available as a package.

---

<div class="post-metadata">

**Author:** ![ashraz](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ashraz/32/509_2.png) [@ashraz](https://forum.systemcrafters.net/u/ashraz)\
**Post date:** [February 5, 2024, 9:16am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/8 "2024-02-05T09:16:32Z")

</div>

I don’t know Guix custom configuration language, but doesn’t your service definition as-is _not_ enable `readline`, as it is disabled by default? 😅

---

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 5, 2024, 4:39pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/9 "2024-02-05T16:39:30Z")

</div>

For me it was not sufficient to just install the package. I also had to barf a couple of lines into a dotfile to enable. I don’t know enough about guix-home to know if that service definition is a custom thing which might include the dotfile stuff or … I’d like to know though as one of the two goals I have coming out of the guile-beginner’s course is to figure out if I want to replace stow + dotfiles with guile ecosystem tooling.

---

<div class="post-metadata">

**Author:** ![daviwil](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/daviwil/32/1_2.png) [@daviwil](https://forum.systemcrafters.net/u/daviwil)\
**Post date:** [February 5, 2024, 5:24pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/10 "2024-02-05T17:24:50Z")

</div>

Guix Home is a lot more powerful than a plain Stow setup, but it’s also a bit more complex if the stuff you’re trying to configure doesn’t have pre-existing home services.

I currently use a mix of Stow and Guix Home because I haven’t bothered writing home services for everything yet 🙂

---

<div class="post-metadata">

**Author:** ![ryuslash](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ryuslash/32/66_2.png) [@ryuslash](https://forum.systemcrafters.net/u/ryuslash)\
**Post date:** [February 5, 2024, 6:13pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/11 "2024-02-05T18:13:40Z")

</div>

I believe you have found a bug, because it does actually work 😆 but you’re right, they should be off by default.

I must’ve overlooked it because this service produces the exact thing I want and didn’t question it that it worked as I wanted, not as I intended 🙂

**Edit** : No, it was just me being stupid… `home-guile-service` is actually a reference to a variable somewhere else:

```scheme
(define home-guile-service
  (service home-guile-service-type
           (home-guile-configuration
            (use-readline #t)
            (use-colorized #t))))

```

I have more than 1 machine configured with Guix Home that shares some configuration (like this) and I haven’t quite figured out how I want to do that, so I have about 3 different ways of doing it 😅

---

<div class="post-metadata">

**Author:** ![ryuslash](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/ryuslash/32/66_2.png) [@ryuslash](https://forum.systemcrafters.net/u/ryuslash)\
**Post date:** [February 5, 2024, 6:15pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/12 "2024-02-05T18:15:49Z")

</div>

The downside of using guix home specifically (I don’t know about other guile ecosystem tooling) is that (as far as I know) you’re dependent on Guix.

This is great for machines where I run Guix, but also means I need something else for those where I don’t 🙂 I haven’t quite figured out what I want yet, so yeah right now I also have a mix of Stow and guix home 🙂

---

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 5, 2024, 6:52pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/13 "2024-02-05T18:52:21Z")

</div>

In my last attempt at a guix-home config the one place where I stopped before a river crossing was because I run Debian 12 with a Guix userland binary install. I wanted to manage services but that would mean systemd and not, uh…what is it in Guix…herd. I wasn’t sure how far off the ranch I would be trying to manage systemd stuff. Note that it being _possible_ was less of a concern than would I be _nearly the only one attempting it_.

Once I learn more guile perhaps I’ll wade back in and see if I make it across.

---

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 5, 2024, 7:00pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/14 "2024-02-05T19:00:00Z")

</div>

Perhaps this exists but it would be kinda cool if guix had a construct for leveraging ~/.dotfiles and stow “virtualized”. Borrowing a term from, like Puppet or Terraform, the home “Provider” could be configured to clone a repo and then do stow magic.

That would would allow ~/.dotfiles to be leveraged on less advanced ( 😉 ) OSes which do not have any guix-y tooling.

---

<div class="post-metadata">

**Author:** ![shom](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/shom/32/291_2.png) [@shom](https://forum.systemcrafters.net/u/shom)\
**Post date:** [February 9, 2024, 2:23am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/15 "2024-02-09T02:23:09Z")

</div>

I’m able to do this in my guix shell and readline is activated once I activated in the ~/.guile file with

```lisp
(use-modules (ice-9 readline))
(activate-readline)

```

However, I can’t get the REPL inside emacs `run-geiser` to pick up readline support. I didn’t see any packages for guile-readline in the `package-install` either. Any pointers?

---

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 9, 2024, 5:19am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/16 "2024-02-09T05:19:41Z")

</div>

Wish I could help you. In my Emacs (vanilla…no Doom etc) the Emacs key-bindings carry through after an M-x run-guile. I’m using Emacs and Guile stuff from Guix.

---

<div class="post-metadata">

**Author:** ![daviwil](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/daviwil/32/1_2.png) [@daviwil](https://forum.systemcrafters.net/u/daviwil)\
**Post date:** [February 9, 2024, 8:41am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/17 "2024-02-09T08:41:47Z")

</div>

That’s strange, Geiser itself should take care of REPL history for you and Emacs’ own built in key bindings should take care of the rest. As far as I know, the readline module shouldn’t be needed in the context of Geiser, only the terminal Guile REPL.

---

<div class="post-metadata">

**Author:** ![shom](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/shom/32/291_2.png) [@shom](https://forum.systemcrafters.net/u/shom)\
**Post date:** [February 9, 2024, 4:18pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/18 "2024-02-09T16:18:10Z")

</div>

Maybe it’s because I’m an evil user?  
I can go into normal mode when I’m at the prompt and then I can use c-p and c-n to access history. But that’s it, I can’t use any other readline commands like c-a or c-e. Also I need to be exactly where the prompt is to enter back into insert mode, so that’s a bit painful.

---

<div class="post-metadata">

**Author:** ![unruffled\_lumiere](https://avatars.discourse-cdn.com/v4/letter/u/82dd89/32.png) [@unruffled\_lumiere](https://forum.systemcrafters.net/u/unruffled_lumiere)\
**Post date:** [February 9, 2024, 6:36pm UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/19 "2024-02-09T18:36:39Z")

</div>

That seems very likely to me. I’ve never actually used Evil in anger but I do seem to recall that there are certain modes where it needs to be manually adjusted. Perhaps there’s an override of some sort necessary for the REPL.

---

<div class="post-metadata">

**Author:** ![shom](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/shom/32/291_2.png) [@shom](https://forum.systemcrafters.net/u/shom)\
**Post date:** [February 10, 2024, 12:15am UTC](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202/20 "2024-02-10T00:15:51Z")

</div>

For anyone else stumbling here later, I just added some keybindings for evil-collection. Here’s my full snippet:

```lisp
(use-package geiser-guile
  :straight t
  :after org
  :config
  (evil-collection-define-key 'normal 'geiser-repl-mode-map
	"k" 'comint-previous-input
	"j" 'comint-next-input)
  (org-babel-do-load-languages
   'org-babel-load-languages
   '((scheme . t))))

```

So now in normal mode I can access the previous commands entered which is the biggest thing I needed.

For org-babel here’s the src block header I’m using:

```org
#+begin_src scheme :tangle yes :noweb yes :results output :session UniqueName

```

If values are not printed then the `:results` needs to be changed to `value` to see the return values. Only the last return value is shown.

[Next page](https://forum.systemcrafters.net/t/emacs-key-bindings-in-guile-repl/202.md?page=2)
