2010-07-10 10:44:29 +02:00
|
|
|
|
;;;; Copyright (C) 2000, 2001, 2004, 2006, 2010 Free Software Foundation, Inc.
|
2001-03-17 15:32:17 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; 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
|
2009-06-17 00:22:09 +01:00
|
|
|
|
;;;; version 3 of the License, or (at your option) any later version.
|
2001-03-17 15:32:17 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; This library is distributed in the hope that it will be useful,
|
2001-03-17 15:32:17 +00:00
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
;;;; Lesser General Public License for more details.
|
2001-03-17 15:32:17 +00:00
|
|
|
|
;;;;
|
2003-04-05 19:15:35 +00:00
|
|
|
|
;;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License along with this library; if not, write to the Free Software
|
2005-05-23 19:57:22 +00:00
|
|
|
|
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-03-17 15:32:17 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
;;;; A simple value history support
|
|
|
|
|
|
|
2010-07-10 10:44:29 +02:00
|
|
|
|
(define-module (ice-9 history)
|
2010-07-10 11:16:16 +02:00
|
|
|
|
#:export (value-history-enabled? enable-value-history! disable-value-history!
|
2010-07-10 10:44:29 +02:00
|
|
|
|
clear-value-history!))
|
2001-03-17 15:32:17 +00:00
|
|
|
|
|
2010-11-20 00:47:12 +01:00
|
|
|
|
(define-module* '(value-history))
|
2001-04-05 21:12:17 +00:00
|
|
|
|
|
2010-07-10 11:16:16 +02:00
|
|
|
|
(define *value-history-enabled?* #f)
|
|
|
|
|
|
(define (value-history-enabled?)
|
|
|
|
|
|
*value-history-enabled?*)
|
2010-07-10 10:44:29 +02:00
|
|
|
|
|
2001-03-17 15:32:17 +00:00
|
|
|
|
(define (use-value-history x)
|
|
|
|
|
|
(module-use! (current-module)
|
2004-05-24 20:57:20 +00:00
|
|
|
|
(resolve-interface '(value-history))))
|
2001-03-17 15:32:17 +00:00
|
|
|
|
|
|
|
|
|
|
(define save-value-history
|
|
|
|
|
|
(let ((count 0)
|
|
|
|
|
|
(history (resolve-module '(value-history))))
|
|
|
|
|
|
(lambda (v)
|
|
|
|
|
|
(if (not (unspecified? v))
|
|
|
|
|
|
(let* ((c (1+ count))
|
|
|
|
|
|
(s (string->symbol (simple-format #f "$~A" c))))
|
|
|
|
|
|
(simple-format #t "~A = " s)
|
|
|
|
|
|
(module-define! history s v)
|
2004-05-24 20:57:20 +00:00
|
|
|
|
(module-export! history (list s))
|
2001-03-17 15:32:17 +00:00
|
|
|
|
(set! count c))))))
|
|
|
|
|
|
|
2010-07-10 10:44:29 +02:00
|
|
|
|
(define (enable-value-history!)
|
2010-07-10 11:16:16 +02:00
|
|
|
|
(if (not (value-history-enabled?))
|
2010-07-10 10:44:29 +02:00
|
|
|
|
(begin
|
|
|
|
|
|
(add-hook! before-eval-hook use-value-history)
|
|
|
|
|
|
(add-hook! before-print-hook save-value-history)
|
2010-07-10 11:16:16 +02:00
|
|
|
|
(set! *value-history-enabled?* #t))))
|
2010-07-10 10:44:29 +02:00
|
|
|
|
|
|
|
|
|
|
(define (disable-value-history!)
|
2010-07-10 11:16:16 +02:00
|
|
|
|
(if (value-history-enabled?)
|
2010-07-10 10:44:29 +02:00
|
|
|
|
(begin
|
|
|
|
|
|
(remove-hook! before-eval-hook use-value-history)
|
|
|
|
|
|
(remove-hook! before-print-hook save-value-history)
|
2010-07-10 11:16:16 +02:00
|
|
|
|
(set! *value-history-enabled?* #f))))
|
2010-07-10 10:44:29 +02:00
|
|
|
|
|
|
|
|
|
|
(define (clear-value-history!)
|
|
|
|
|
|
(let ((history (resolve-module '(value-history))))
|
|
|
|
|
|
(hash-clear! (module-obarray history))
|
|
|
|
|
|
(hash-clear! (module-obarray (module-public-interface history)))))
|
|
|
|
|
|
|
|
|
|
|
|
(enable-value-history!)
|