Commit b79d2d62 authored by Christophe Rhodes's avatar Christophe Rhodes
Browse files

escape names when searching for completions

otherwise extended regexp metacharacters, particularly ".", get
interpreted as those metacharacters rather than literals.  (bug #12)
parent a4e616b4
......@@ -42,7 +42,7 @@
Logged here so that I don't forget it if I sort out #9 first: we
need to be able to indicate "no repl result please" if we open a new
temporary buffer to display the result.
* OPEN #12 need to be more careful when searching for completions :NORMAL:
* RESOLVED #12 escaping when searching for completions :NORMAL:FIXED:
Gets thoroughly confused on completing "read." because the "." is
treated as a regexp "any character" pattern.
* COMMENT:
......
......@@ -430,14 +430,17 @@ computeRestartsForEmacs <- function (sldbState) {
}
`swank:simple-completions` <- function(slimeConnection, sldbState, prefix, package) {
## fails multiply if prefix contains regexp metacharacters
matches <- apropos(sprintf("^%s", prefix), ignore.case=FALSE)
literal2rx <- function(string) {
## list of ERE metacharacters from ?regexp
gsub("([.\\|()[{^$*+?])", "\\\\\\1", string)
}
matches <- apropos(sprintf("^%s", literal2rx(prefix)), ignore.case=FALSE)
nmatches <- length(matches)
if(nmatches == 0) {
list(list(), "")
} else {
longest <- matches[order(nchar(matches))][1]
while(length(grep(sprintf("^%s", longest), matches)) < nmatches) {
while(length(grep(sprintf("^%s", literal2rx(longest)), matches)) < nmatches) {
longest <- substr(longest, 1, nchar(longest)-1)
}
list(as.list(matches), longest)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment