1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

batch-mode? in terms of *repl-level*

* module/ice-9/boot-9.scm (*repl-level*): New global fluid, moved here
  from (system repl common).
  (batch-mode?): Reimplement in terms of *repl-level*.
  (ensure-batch-mode!): A replacement for set-batch-mode?!.

* module/ice-9/deprecated.scm (set-batch-mode?!): Deprecate.

* module/ice-9/popen.scm (open-process): Use ensure-batch-mode!.

* module/ice-9/scm-style-repl.scm (error-catching-loop): Override
  ensure-batch-mode!.

* module/system/repl/common.scm: Remove *repl-level*.
This commit is contained in:
Andy Wingo 2010-06-18 12:28:18 +02:00
parent 410e83c012
commit 9346b857af
5 changed files with 35 additions and 17 deletions

View file

@ -2661,6 +2661,7 @@ module '(ice-9 q) '(make-q q-length))}."
;;; Currently Guile represents unspecified values via one particular value,
;;; which may be obtained by evaluating (if #f #f). It would be nice in the
;;; future if we could replace this with a return of 0 values, though.
;;;
(define-syntax *unspecified*
(identifier-syntax (if #f #f)))
@ -2691,10 +2692,20 @@ module '(ice-9 q) '(make-q q-length))}."
(define abort-hook (make-hook))
;; these definitions are used if running a script.
;; otherwise redefined in error-catching-loop.
(define (set-batch-mode?! arg) #t)
(define (batch-mode?) #t)
;; Programs can call `batch-mode?' to see if they are running as part of a
;; script or if they are running interactively. REPL implementations ensure that
;; `batch-mode?' returns #f during their extent.
;;
;; Programs can re-enter batch mode, for example after a fork, by calling
;; `ensure-batch-mode!'. This will also restore signal handlers. It's not a
;; great interface, though; it would be better to abort to the outermost prompt,
;; and call a thunk there.
(define *repl-level* (make-fluid))
(define (batch-mode?)
(negative? (or (fluid-ref *repl-level*) -1)))
(define (ensure-batch-mode!)
(fluid-set! *repl-level* #f)
(restore-signals))
;;(define the-last-stack (make-fluid)) Defined by scm_init_backtrace ()
(define before-signal-stack (make-fluid))

View file

@ -54,7 +54,8 @@
assert-repl-silence
assert-repl-print-unspecified
assert-repl-verbosity
set-repl-prompt!)
set-repl-prompt!
set-batch-mode?!)
#:replace (module-ref-submodule module-define-submodule!))
@ -595,3 +596,15 @@ better yet, use the repl from `(system repl repl)'.")
"`set-repl-prompt!' is deprecated. Use `repl-default-prompt-set!' from
the `(system repl common)' module.")
((@ (system repl common) repl-default-prompt-set!) v))
(define (set-batch-mode?! arg)
(cond
(arg
(issue-deprecation-warning
"`set-batch-mode?!' is deprecated. Use `ensure-batch-mode!' instead.")
(ensure-batch-mode!))
(else
(issue-deprecation-warning
"`set-batch-mode?!' with an argument of `#f' is deprecated. Use the
`*repl-level*' fluid instead.")
#t)))

View file

@ -1,6 +1,6 @@
;; popen emulation, for non-stdio based ports.
;;;; Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006 Free Software Foundation, Inc.
;;;; Copyright (C) 1998, 1999, 2000, 2001, 2003, 2006, 2010 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
@ -59,7 +59,7 @@
(let ((pid (primitive-fork)))
(cond ((= pid 0)
;; child
(set-batch-mode?! #t)
(ensure-batch-mode!)
;; select the three file descriptors to be used as
;; standard descriptors 0, 1, 2 for the new

View file

@ -129,12 +129,9 @@
default-pre-unwind-handler)))
(if next (loop next) status)))
(set! set-batch-mode?! (lambda (arg)
(cond (arg
(set! interactive #f)
(restore-signals))
(#t
(error "sorry, not implemented")))))
(set! ensure-batch-mode! (lambda ()
(set! interactive #f)
(restore-signals)))
(set! batch-mode? (lambda () (not interactive)))
(call-with-blocked-asyncs
(lambda () (loop (lambda () #t))))))

View file

@ -30,8 +30,7 @@
repl-parse repl-print repl-option-ref repl-option-set!
repl-default-option-set! repl-default-prompt-set!
puts ->string user-error
*warranty* *copying* *version*
*repl-level*))
*warranty* *copying* *version*))
(define *version*
(format #f "GNU Guile ~A
@ -95,8 +94,6 @@ copy of the Program in return for a fee.
See <http://www.gnu.org/licenses/lgpl.html>, for more details.")
(define *repl-level* (make-fluid))
;;;
;;; Repl type