From: NeilBrown Date: Sun, 20 Aug 2023 21:48:46 +0000 (+1000) Subject: mode-emacs: improve path completion in shell commands X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=922a2e9206402ef7d41b481c1fc6658c06228b20;p=edlib.git mode-emacs: improve path completion in shell commands 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 --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 00f258de..7b050d87 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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? diff --git a/mode-emacs.c b/mode-emacs.c index fdb824c5..793c3fb3 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -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);