--- readline.scm 2014-12-11 01:57:27.105532179 -0700 +++ readline.scm.new 2014-12-11 01:41:14.946431613 -0700 @@ -102,6 +102,12 @@ gnu-readline-truncate-history gnu-history-new-lines gnu-history-install-file-manager + gnu-history-line + gnu-history-position + gnu-search-history + gnu-search-history-forward + gnu-search-history-backward + gnu-history-list-length gnu-readline-parse-and-bind gnu-readline-set-bounce-ms @@ -169,6 +175,43 @@ (define gnu-history-new-lines (foreign-lambda int "gnu_history_new_lines")) +;; (gnu-history-line (> offset 0)) -> next history line +;; (gnu-history-line (< offset 0)) -> previous history line +;; (gnu-history-line) -> current history line +;; returns #f on fail +(define (gnu-history-line #!optional offset) + ((foreign-lambda c-string "gnu_history_get_line" int) (or offset 0))) + +;; (gnu-history-search "string" -1) -> search through previous entries +;; (gnu-history-search "string" 0+) -> search through subsequent entries. +;; returns match on succ, #f on fail. +;; XXX use `(get-keyword)' to access offset:, match:, and index: +;; XXX `index:' corresponds to the history-position within history_list of the match +(define (gnu-search-history string direction) + (define offset ((foreign-lambda int "history_search" c-string int) + string direction)) + (if (= offset -1) + #f + (list offset: offset + match: (gnu-history-line 0) + index: (gnu-history-position)))) + +(define (gnu-search-history-backward string) + (gnu-search-history string -1)) + +(define (gnu-search-history-forward string) + (gnu-search-history string 0)) + +(define gnu-history-list-length + (foreign-lambda int "gnu_history_list_length")) + +;; (gnu-history-position pos) -> sets the current history position: 0 succ, 1 fail +;; (gnu-history-position) -> current history position within history_list +(define (gnu-history-position #!optional pos) + (if pos + (= 1 ((foreign-lambda int "history_set_pos" int) pos)) + ((foreign-lambda int "where_history")))) + ;; Useful... (define gnu-readline-parse-and-bind (foreign-lambda int "rl_parse_and_bind" c-string))