There doesn't seem to be any indentation in the default inferior scheme. At least, when I do
M-x run-scheme the resulting repl doesn't indent my code at all.
How can I change this? Preferably without anything like geiser or other wrappers.
I think the issue is that
RET is probably mapped to
comint-send-input, which doesn't do any indentation.
What I do is map
newline-and-indent and leave
RET mapped to
comint-send-input. So I press
C-j to enter a newline, and indent the new line, or
RET to actually send the form for evaluation. (Actually I map
newline-and-indent should work if you're not using Paredit).
Of course, you could reverse those and use
As an example of mapping one of these keys, this will map
(with-eval-after-load 'cmuscheme (define-key inferior-scheme-mode-map (kbd "C-j") #'newline-and-indent))
cmuscheme is, for historical reasons, the name of the package that implements
inferior-scheme-mode, i.e. the Scheme REPL.)
Here's something that seems to work, though I haven't tested it extensively:
(defun comint-send-input-indent () (interactive) (comint-send-input) (unless (save-excursion (forward-char -1) (eq (field-at-pos (point)) 'output)) (indent-for-tab-command))) (with-eval-after-load 'cmuscheme (define-key inferior-scheme-mode-map (kbd "RET") #'comint-send-input-indent))
The idea is to call
comint-send-input, then check if point (the cursor) is immediately before the prompt. If it's not (because
comint-send-input just entered a newline), call
indent-for-tab-command, which indents the line appropriately.
On second thought, I think this definition probably makes more sense:
(defun comint-send-input-indent () (interactive) (let ((parens (or (car (syntax-ppss)) 0))) (if (zerop parens) (comint-send-input) (newline-and-indent))))
C-h f syntax-ppss RET (and, better,
C-h f parse-partial-sexp RET) for more information. The short version is that they can tell us how deep the paren nesting is at point, so we can use that to decide whether to