Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

readline/readline: add history loading and saving #161

Closed
wants to merge 2 commits into from

1 participant

@ghost

I made a simple change to readline/readline to have history loading and saving functions.
The documentation has been updated as well.

@ghost

Will recreate the pull request as it was done on my master branch instead of a feature branch :(

@ghost ghost closed this
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 24, 2012
  1. @telephil
Commits on Nov 6, 2012
  1. @telephil
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 2 deletions.
  1. +18 −2 collects/readline/mzrl.rkt
  2. +9 −0 collects/readline/readline.scrbl
View
20 collects/readline/mzrl.rkt
@@ -1,9 +1,9 @@
#lang scheme/base
-(require mzlib/foreign (only-in '#%foreign ffi-obj)) (unsafe!)
+(require racket/file mzlib/foreign (only-in '#%foreign ffi-obj)) (unsafe!)
(provide readline readline-bytes
add-history add-history-bytes
- history-length history-get history-delete
+ history-length history-get history-delete history-load history-save
set-completion-function!)
;; libtermcap needed on some platforms
@@ -50,6 +50,22 @@
(let ([hb (ffi-obj #"history_base" libreadline)])
(lambda () (ptr-ref hb _int))))
+;; history-load : string? -> void
+(define (history-load filename)
+ (when (file-exists? filename)
+ (for-each (lambda (line)
+ (add-history line))
+ (file->lines filename))))
+
+;; history-save : string? -> void
+(define (history-save filename)
+ (with-output-to-file filename #:exists 'replace
+ (lambda ()
+ (for ([index (in-range (history-length))])
+ (displayln (history-get index))))))
+
+
+
;; The history library has this great feature: *some* function consume
;; an index that is relative to history_base, and *some* get a plain
;; offset. Someone just had so much fun they had to share. This
View
9 collects/readline/readline.scrbl
@@ -229,6 +229,15 @@ second-to-last, etc.)}
Deletes the history string at the @racket[idx] position. The position
is specified in the same way as the argument for @racket[history-get].}
+@defproc[(history-save [filename string?]) void?]{
+
+Save history to file @racket[filename]. The file is replaced if
+ it already exists}
+
+@defproc[(history-load [filename string?]) void?]{
+
+Load history from file @racket[filename].}
+
@defproc[(set-completion-function! [proc ((or/c string? bytes?)
. -> . (listof (or/c string? bytes?)))]
Something went wrong with that request. Please try again.