]> git.neil.brown.name Git - edlib.git/commitdiff
mode-emacs: improve path completion in shell commands
authorNeilBrown <neil@brown.name>
Sun, 20 Aug 2023 21:48:46 +0000 (07:48 +1000)
committerNeilBrown <neil@brown.name>
Mon, 21 Aug 2023 12:28:15 +0000 (22:28 +1000)
1/ Allow a ':' or '=' to identify where the path starts as long as it
   starts '/'.
2/ Give message when directory cannot be opened or no completions can be
   found.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
mode-emacs.c

index 00f258debb2cfde02df23a092fafee1386da778c..7b050d871f5c6a4ddc7676574233a60dc352a118 100644 (file)
@@ -35,7 +35,7 @@ the file.
       so markup can be tested more directly.
 - [X] in search-replace if you repeat :A-Enter, chars get deleted - if
        replacement string is shorter.  If longer, they get added.
-- [ ] path completion in shell command.  If cannot find look for '/'
+- [X] path completion in shell command.  If cannot find look for '/'
       following punctuation (=) and try there.
 - [ ] resolve shift-left vs shift_left distinction - add a "fixed" suffix?
 - [ ] should zoom affect whole window, not just pane?
index fdb824c598365d787493d51d65ee43a6fde31338..793c3fb3b401a504ce3264c3b01272430ebae293 100644 (file)
@@ -1490,9 +1490,17 @@ REDEF_CMD(emacs_file_complete)
        if (wholebuf) {
                d = str;
        } else {
+               /* Need guess which part of the buf is the file name.
+                * This probably needs to be configurable, but lets
+                * decide the file name starts immediately after a
+                * space, or a '=' or ':' which is followed by a
+                * '/'.
+                */
                initial = "";
                d = str + strlen(str);
-               while (d > str && d[-1] != ' ')
+               while (d > str &&
+                      !(d[-1] == ' ' ||
+                        (strchr(":=", d[-1]) && d[0] == '/')))
                        d -= 1;
        }
        d = file_normalize(ci->focus, d, initial);
@@ -1506,6 +1514,8 @@ REDEF_CMD(emacs_file_complete)
        }
        fd = open(d, O_DIRECTORY|O_RDONLY);
        if (fd < 0) {
+               call("Message:modal", ci->focus, 0, NULL,
+                    strconcat(ci->focus, "Cannot open directory \"", d, "\""));
                return Efail;
        }
        /* 32 means quiet */
@@ -1550,6 +1560,10 @@ REDEF_CMD(emacs_file_complete)
                call("doc:char", ci->focus, -strlen(b), start);
                call("Replace", ci->focus, 1, start, cr.s);
                mark_free(start);
+       } else {
+               call("Message:modal", ci->focus, 0, NULL,
+                    strconcat(ci->focus, "No completion found for \"", b, "\"",
+                              " in \"", d, "\""));
        }
        /* Now need to close the popup */
        pane_close(pop);