diff options
| author | Brian Leung <leungbk@posteo.net> | 2022-02-10 00:59:02 -0800 |
|---|---|---|
| committer | Tom Dalziel <33435574+tomdl89@users.noreply.github.com> | 2022-02-14 00:00:33 +0100 |
| commit | e7c019291bb2746fc8243e140dc95229728aee50 (patch) | |
| tree | 7265a14ef1442bb05d9db8735038980a1b7544fe | |
| parent | 0646631de42db7f93c002d4430191f86f7718b63 (diff) | |
evil-read: Perform % and # substitutions for shell cmds
| -rw-r--r-- | evil-commands.el | 18 | ||||
| -rw-r--r-- | evil-tests.el | 12 |
2 files changed, 23 insertions, 7 deletions
diff --git a/evil-commands.el b/evil-commands.el index d09da35..7c6a299 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -3195,15 +3195,19 @@ If no FILE is specified, reload the current buffer from disk." (when (or (not (zerop (forward-line (or count 1)))) (not (bolp))) (insert "\n")) - (if (/= (aref file 0) ?!) - (let ((result (insert-file-contents file))) - (save-excursion - (forward-char (cadr result)) - (unless (bolp) (insert "\n")))) - (shell-command (substring file 1) t) + (cond + ((/= (aref file 0) ?!) + (when (member file '("#" "%")) + (setq file (evil-ex-replace-special-filenames file))) + (let ((result (insert-file-contents file))) + (save-excursion + (forward-char (cadr result)) + (unless (bolp) (insert "\n"))))) + (t + (shell-command (evil-ex-replace-special-filenames (substring file 1)) t) (save-excursion (goto-char (mark)) - (unless (bolp) (insert "\n")))))) + (unless (bolp) (insert "\n"))))))) (evil-define-command evil-show-files () "Shows the file-list. diff --git a/evil-tests.el b/evil-tests.el index 73eed9e..eb638cf 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -8137,6 +8137,18 @@ maybe we need one line more with some text\n") "[l]line 1\nline 2" (":read!echo cmd line 1" [return]) "line 1\n[c]md line 1\nline 2"))) + (ert-info ("Test substitution of % in shell commands") + (evil-with-temp-file name + "3\n2\n1\n" + (evil-test-buffer + ((vconcat ":e " name [return])) + "[3]\n2\n1\n" + ((vconcat ":read !echo %" [return])) + ((vconcat ":w " [return])) + (file name (concat "3\n" + (buffer-file-name) "\n" + "2\n" + "1\n"))))) (ert-info ("Test insertion of shell command without trailing newline") (ert-info ("with space") (evil-test-buffer |
