From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.devel Subject: Re: request for hack: readline fixes Date: Sat, 30 Oct 2010 16:30:20 +0100 Message-ID: <8762wjpoxz.fsf@ossau.uklinux.net> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1288459928 22398 80.91.229.12 (30 Oct 2010 17:32:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 30 Oct 2010 17:32:08 +0000 (UTC) Cc: guile-devel To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Oct 30 19:32:04 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PCFHe-0006Ic-CW for guile-devel@m.gmane.org; Sat, 30 Oct 2010 19:32:02 +0200 Original-Received: from localhost ([127.0.0.1]:59432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PCFHd-0000Sz-P5 for guile-devel@m.gmane.org; Sat, 30 Oct 2010 13:32:01 -0400 Original-Received: from [140.186.70.92] (port=51974 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PCFHP-0000Sd-BJ for guile-devel@gnu.org; Sat, 30 Oct 2010 13:31:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PCFHK-0000RH-DK for guile-devel@gnu.org; Sat, 30 Oct 2010 13:31:47 -0400 Original-Received: from mail3.uklinux.net ([80.84.72.33]:59936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PCFHJ-0000Qo-ST for guile-devel@gnu.org; Sat, 30 Oct 2010 13:31:42 -0400 Original-Received: from arudy (unknown [78.149.124.242]) by mail3.uklinux.net (Postfix) with ESMTP id 558501F67E6; Sat, 30 Oct 2010 18:31:41 +0100 (BST) Original-Received: from neil-laptop (unknown [192.168.1.5]) by arudy (Postfix) with ESMTP id 13EB638013; Sat, 30 Oct 2010 18:32:12 +0100 (BST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11088 Archived-At: --=-=-= Andy Wingo writes: > * History: Expression-oriented, please! > > It would be great if going back in the history cycled through entire > expressions, not line-by-line. Again I know that readline can do > this. Please fix? :) The attached seems to work for me. Does it look OK? Regards, Neil --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Expression-oriented-readline-history.patch >From 77c260435092f9bbfba17b6b2b4e4c8b1c5623d9 Mon Sep 17 00:00:00 2001 From: Neil Jerram Date: Sat, 30 Oct 2010 16:28:54 +0100 Subject: [PATCH] Expression-oriented readline history * guile-readline/ice-9/readline.scm (make-readline-port): Instead of calling add-history after every %readline call, do it only when starting a new read. Other times, append the line just read to an internal buffer. --- guile-readline/ice-9/readline.scm | 43 +++++++++++++++++++++++++------------ 1 files changed, 29 insertions(+), 14 deletions(-) diff --git a/guile-readline/ice-9/readline.scm b/guile-readline/ice-9/readline.scm index 4879bab..36f805f 100644 --- a/guile-readline/ice-9/readline.scm +++ b/guile-readline/ice-9/readline.scm @@ -80,20 +80,35 @@ (define read-hook #f) (define (make-readline-port) - (make-line-buffered-input-port (lambda (continuation?) - (let* ((prompt (if continuation? - continuation-prompt - new-input-prompt)) - (str (%readline (if (string? prompt) - prompt - (prompt)) - input-port - output-port - read-hook))) - (or (eof-object? str) - (string=? str "") - (add-history str)) - str)))) + (let ((history-buffer #f)) + (make-line-buffered-input-port (lambda (continuation?) + ;; When starting a new read, add + ;; the previously read expression + ;; to the history. + (if (and (not continuation?) + history-buffer) + (begin + (add-history history-buffer) + (set! history-buffer #f))) + ;; Set up prompts and read a line. + (let* ((prompt (if continuation? + continuation-prompt + new-input-prompt)) + (str (%readline (if (string? prompt) + prompt + (prompt)) + input-port + output-port + read-hook))) + (or (eof-object? str) + (string=? str "") + (set! history-buffer + (if history-buffer + (string-append history-buffer + " " + str) + str))) + str))))) ;;; We only create one readline port. There's no point in having ;;; more, since they would all share the tty and history --- -- 1.7.1 --=-=-=--