Search code examples
emacsschemechicken-scheme

How to add indentation an inferior scheme (REPL) in emacs?


I'm using Chicken-scheme.I use M-x run-scheme to start a scheme repl, and then I use things like C-c C-l to test my work.

However, this is an indentation nightmare. Things generally look like this:

> (+ 1 
(* 2
3)
4)

instead of the desired:

> (+ 1
     (* 2
        3)
     4)

How can I easily fix this? I know I can start a chicken repl with geiser, but that breaks keybindings and I'd really just prefer to not make stuff more complicated than it is. I just want it to correctly indent when I press enter, just like in my non-repl buffer, that's all.

I'd just like the simplest possible solution to get some nice indentation, like is standard for lisp. I'd like to add that my buffer in which I edit the file is totally fine, it's just the repl that doesn't work.


Solution

  • Bind RET to

    (defun comint-send-input-indent ()
      (interactive)
      (let ((parens (or (car (syntax-ppss)) 0)))
        (if (zerop parens)
            (comint-send-input)
          (newline-and-indent))))
    

    As found here