diff --git a/repl.lua b/repl.lua index 0d28a4b..2da2740 100644 --- a/repl.lua +++ b/repl.lua @@ -54,7 +54,22 @@ local function expand_mentions(line, on_status) local at_start = (i == 1) or line:sub(i - 1, i - 1):match("%s") ~= nil if at_start and line:sub(i, i) == "@" then local path_end = line:find("%s", i + 1) or (#line + 1) - local path = line:sub(i + 1, path_end - 1) + local raw = line:sub(i + 1, path_end - 1) + -- Peel one or more trailing punctuation chars (,.;:?!) if the + -- full path doesn't resolve — handles natural prose like + -- "look at @README.md, then..." or "@foo.lua." at sentence end. + local path, trail = raw, "" + while #path > 0 do + local f = io.open(path, "rb") + if f then f:close(); break end + local last = path:sub(-1) + if last:match("[%.,;:?!)]") then + trail = last .. trail + path = path:sub(1, -2) + else + break + end + end if path ~= "" then local content, truncated = _read_truncated(path) if content then @@ -62,12 +77,12 @@ local function expand_mentions(line, on_status) on_status(("@%s expanded (%d bytes%s)"):format( path, #content, truncated and ", truncated" or "")) end - out[#out + 1] = ("```%s path=%s\n%s\n```"):format( - _lang_of(path), path, content) + out[#out + 1] = ("```%s path=%s\n%s\n```%s"):format( + _lang_of(path), path, content, trail) i = path_end else if on_status then - on_status(("@%s: not found"):format(path)) + on_status(("@%s: not found"):format(raw)) end out[#out + 1] = line:sub(i, path_end - 1) i = path_end