[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Filename completion in repl
From: |
Jeff Binder |
Subject: |
Filename completion in repl |
Date: |
Mon, 10 Feb 2003 20:56:30 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021105 |
By default the tab-completion in the repl uses apropos, which is usually
right. However, this doesn't accomplish much inside a string literal.
This patch sets up the repl to use filename completion when the cursor
is inside a literal, and apropos completion otherwise. This is useful,
for example, when using the 'load' function interactively.
Jeff Binder
--------------
--- guile-readline/readline.c 8 Jan 2003 21:36:20 -0000 1.46
+++ guile-readline/readline.c 11 Feb 2003 04:11:37 -0000
@@ -390,6 +390,28 @@
}
#undef FUNC_NAME
+
+SCM_DEFINE (scm_readline_line_buffer, "readline-line-buffer", 0, 0, 0,
+ (),
+"")
+#define FUNC_NAME s_scm_readline_line_buffer
+{
+ if (!rl_line_buffer)
+ return SCM_BOOL_F;
+ return scm_makfrom0str (rl_line_buffer);
+}
+#undef FUNC_NAME
+
+
+SCM_DEFINE (scm_readline_point, "readline-point", 0, 0, 0,
+ (),
+"")
+#define FUNC_NAME s_scm_readline_point
+{
+ return SCM_MAKINUM (rl_point);
+}
+#undef FUNC_NAME
+
/*
* The following has been modified from code contributed by
* Andrew Archibald <address@hidden>
--- guile-readline/readline.scm 21 Oct 2002 11:22:04 -0000 1.19
+++ guile-readline/readline.scm 11 Feb 2003 04:11:37 -0000
@@ -197,4 +197,16 @@
(lambda ()
(set! *readline-completion-function* old-completer)))))
+(define (quotes-unbalanced?)
+ (let ((buf (readline-line-buffer))
+ (point (readline-point))
+ (odd-num? #f))
+ (while (positive? point)
+ (set! point (- point 1))
+ (if (and (eq? (string-ref buf point) #\")
+ (or (= point 0)
+ (not (eq? (string-ref buf (- point 1)) #\\))))
+ (set! odd-num? (not odd-num?))))
+ odd-num?))
+
(define-public (activate-readline)
@@ -213,3 +213,10 @@
(set-readline-read-hook! read-hook))
- (lambda () (read))
+ (lambda ()
+ (with-readline-completion-function
+ (lambda (text cont?)
+ ((if (quotes-unbalanced?)
+ filename-completion-function
+ apropos-completion-function)
+ text cont?))
+ read))
(lambda ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Filename completion in repl,
Jeff Binder <=