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:
}
`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)