1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-04 08:40:21 +02:00
guile/module/system/repl/reader.scm
Andy Wingo f930af2737 Move implementation of hooks to Scheme module
* module/ice-9/hooks.scm: New file.
* am/bootstrap.am: Add new file.
* module/ice-9/deprecated.scm: Add trampolines to (ice-9 hooks).
* module/ice-9/scm-style-repl.scm:
* module/ice-9/session.scm:
* module/ice-9/top-repl.scm:
* module/scripts/scan-api.scm:
* guile-readline/ice-9/readline.scm:
* benchmark-suite/benchmark-suite/lib.scm:
* module/system/repl/command.scm:
* module/system/repl/common.scm:
* module/system/repl/debug.scm:
* module/system/repl/error-handling.scm:
* module/system/repl/hooks.scm:
* module/system/repl/reader.scm:
* module/system/repl/repl.scm:
* module/ice-9/history.scm:
* test-suite/tests/hooks.test: Use the new module.
* module/oop/goops.scm: Remove <hook> class definition.
* libguile/vm.c:
* libguile/init.c:
* libguile/Makefile.am:
* libguile.h: Remove hooks.h includes.
* libguile/hooks.c:
* libguile/hooks.h: Remove.
* libguile/deprecated.h:
* libguile/deprecated.c: Add deprecation shims for C API.
2025-06-16 13:11:28 +02:00

60 lines
2.3 KiB
Scheme
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; Copyright (C) 2025 Free Software Foundation, Inc.
;;;
;;; This library is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser General Public License as
;;; published by the Free Software Foundation, either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; This library 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
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
;;; Commentary:
;;;
;;;
;;; Code:
(define-module (system repl reader)
#:use-module (ice-9 hooks)
#:use-module (system repl hooks)
;; FIXME: #:export instead of #:replace once deprecated code is
;; removed.
#:replace (repl-reader)
#:export (set-repl-reader!))
;;; The default repl-reader function. We may override this if we've
;;; the readline library.
(define repl-reader
(lambda* (prompt #:optional (reader (fluid-ref current-reader)))
(unless (char-ready?)
(display (if (string? prompt) prompt (prompt)))
;; An interesting situation. The printer resets the column to 0
;; by printing a newline, but we then advance it by printing the
;; prompt. However the port-column of the output port does not
;; typically correspond with the actual column on the screen,
;; because the input is echoed back! Since the input is
;; line-buffered and thus ends with a newline, the output will
;; really start on column zero. So, here we zero it out. See bug
;; 9664.
;;
;; Note that for similar reasons, the output-line will not reflect
;; the actual line on the screen. But given the possibility of
;; multiline input, the fix is not as straightforward, so we don't
;; bother.
;;
;; Also note that the readline implementation papers over these
;; concerns, because it's readline itself printing the prompt, and
;; not Guile.
(set-port-column! (current-output-port) 0))
(force-output)
(run-hook before-read-hook)
((or reader read) (current-input-port))))
(define (set-repl-reader! reader)
(set! repl-reader reader))