diff options
| author | Jim Porter | 2023-01-22 13:20:46 -0800 |
|---|---|---|
| committer | Jim Porter | 2023-01-30 17:49:11 -0800 |
| commit | e7d0aa248e684a6de0d655d93bfcfee06cc8ff09 (patch) | |
| tree | 57da89cd001aa6ae1501174122eb9e55c6dec4e7 | |
| parent | cc5a2ed457eb34543bb7aaf6b39663af2599805d (diff) | |
| download | emacs-e7d0aa248e684a6de0d655d93bfcfee06cc8ff09.tar.gz emacs-e7d0aa248e684a6de0d655d93bfcfee06cc8ff09.zip | |
During completion, convert all Eshell arguments to strings
Eshell was already converting some types (numbers, nil) to strings, as
well as fixing up multiple-dot forms like ".../", so this way is more
consistent and should produce fewer problems for Pcomplete functions.
* lisp/eshell/em-cmpl.el (eshell-complete-parse-arguments): Always
convert parsed arguments to strings.
* test/lisp/eshell/em-cmpl-tests.el (eshell-arguments-equal,
eshell-arguments-equal--equal-explainer): New functions.
(em-cmpl-test/parse-arguments/pipeline)
(em-cmpl-test/parse-arguments/multiple-dots)
(em-cmpl-test/parse-arguments/variable/numeric)
(em-cmpl-test/parse-arguments/variable/nil)
(em-cmpl-test/parse-arguments/variable/list)
(em-cmpl-test/parse-arguments/variable/splice): Use
'eshell-arguments-equal'.
| -rw-r--r-- | lisp/eshell/em-cmpl.el | 24 | ||||
| -rw-r--r-- | test/lisp/eshell/em-cmpl-tests.el | 54 |
2 files changed, 55 insertions, 23 deletions
diff --git a/lisp/eshell/em-cmpl.el b/lisp/eshell/em-cmpl.el index d1c7e81090a..acbf206a3c6 100644 --- a/lisp/eshell/em-cmpl.el +++ b/lisp/eshell/em-cmpl.el | |||
| @@ -386,17 +386,19 @@ to writing a completion function." | |||
| 386 | ;; Convert arguments to forms that Pcomplete can understand. | 386 | ;; Convert arguments to forms that Pcomplete can understand. |
| 387 | (cons (mapcar | 387 | (cons (mapcar |
| 388 | (lambda (arg) | 388 | (lambda (arg) |
| 389 | (cond | 389 | (pcase arg |
| 390 | ((numberp arg) | 390 | ;; Expand ".../" etc that only Eshell understands to |
| 391 | (number-to-string arg)) | 391 | ;; the standard "../../". |
| 392 | ;; Expand ".../" etc that only Eshell understands to the | 392 | ((rx ".." (+ ".") "/") |
| 393 | ;; standard "../../". | 393 | (propertize (eshell-expand-multiple-dots arg) |
| 394 | ((and (stringp arg) (string-match "\\.\\.\\.+/" arg)) | 394 | 'pcomplete-arg-value arg)) |
| 395 | (eshell-expand-multiple-dots arg)) | 395 | ((pred stringp) |
| 396 | ((null arg) | 396 | arg) |
| 397 | "") | 397 | ('nil |
| 398 | (t | 398 | (propertize "" 'pcomplete-arg-value arg)) |
| 399 | arg))) | 399 | (_ |
| 400 | (propertize (eshell-stringify arg) | ||
| 401 | 'pcomplete-arg-value arg)))) | ||
| 400 | args) | 402 | args) |
| 401 | posns))) | 403 | posns))) |
| 402 | 404 | ||
diff --git a/test/lisp/eshell/em-cmpl-tests.el b/test/lisp/eshell/em-cmpl-tests.el index 3f8f890f6e5..12a156fbb38 100644 --- a/test/lisp/eshell/em-cmpl-tests.el +++ b/test/lisp/eshell/em-cmpl-tests.el | |||
| @@ -44,6 +44,26 @@ | |||
| 44 | (completion-at-point) | 44 | (completion-at-point) |
| 45 | (eshell-get-old-input)) | 45 | (eshell-get-old-input)) |
| 46 | 46 | ||
| 47 | (defun eshell-arguments-equal (actual expected) | ||
| 48 | "Return t if ACTUAL and EXPECTED are equal, including properties of strings. | ||
| 49 | ACTUAL and EXPECTED should both be lists of strings." | ||
| 50 | (when (length= actual (length expected)) | ||
| 51 | (catch 'not-equal | ||
| 52 | (cl-mapc (lambda (i j) | ||
| 53 | (unless (equal-including-properties i j) | ||
| 54 | (throw 'not-equal nil))) | ||
| 55 | actual expected) | ||
| 56 | t))) | ||
| 57 | |||
| 58 | (defun eshell-arguments-equal--equal-explainer (actual expected) | ||
| 59 | "Explain the result of `eshell-arguments-equal'." | ||
| 60 | `(nonequal-result | ||
| 61 | (actual ,actual) | ||
| 62 | (expected ,expected))) | ||
| 63 | |||
| 64 | (put 'eshell-arguments-equal 'ert-explainer | ||
| 65 | #'eshell-arguments-equal--equal-explainer) | ||
| 66 | |||
| 47 | ;;; Tests: | 67 | ;;; Tests: |
| 48 | 68 | ||
| 49 | (ert-deftest em-cmpl-test/parse-arguments/pipeline () | 69 | (ert-deftest em-cmpl-test/parse-arguments/pipeline () |
| @@ -51,47 +71,57 @@ | |||
| 51 | (with-temp-eshell | 71 | (with-temp-eshell |
| 52 | (let ((eshell-test-value '("foo" "bar"))) | 72 | (let ((eshell-test-value '("foo" "bar"))) |
| 53 | (insert "echo hi | cat") | 73 | (insert "echo hi | cat") |
| 54 | (should (equal (car (eshell-complete-parse-arguments)) | 74 | (should (eshell-arguments-equal |
| 55 | '("cat")))))) | 75 | (car (eshell-complete-parse-arguments)) |
| 76 | '("cat")))))) | ||
| 56 | 77 | ||
| 57 | (ert-deftest em-cmpl-test/parse-arguments/multiple-dots () | 78 | (ert-deftest em-cmpl-test/parse-arguments/multiple-dots () |
| 58 | "Test parsing arguments with multiple dots like \".../\"." | 79 | "Test parsing arguments with multiple dots like \".../\"." |
| 59 | (with-temp-eshell | 80 | (with-temp-eshell |
| 60 | (insert "echo .../file.txt") | 81 | (insert "echo .../file.txt") |
| 61 | (should (equal (car (eshell-complete-parse-arguments)) | 82 | (should (eshell-arguments-equal |
| 62 | '("echo" "../../file.txt"))))) | 83 | (car (eshell-complete-parse-arguments)) |
| 84 | `("echo" ,(propertize "../../file.txt" | ||
| 85 | 'pcomplete-arg-value | ||
| 86 | ".../file.txt")))))) | ||
| 63 | 87 | ||
| 64 | (ert-deftest em-cmpl-test/parse-arguments/variable/numeric () | 88 | (ert-deftest em-cmpl-test/parse-arguments/variable/numeric () |
| 65 | "Test parsing arguments with a numeric variable interpolation." | 89 | "Test parsing arguments with a numeric variable interpolation." |
| 66 | (with-temp-eshell | 90 | (with-temp-eshell |
| 67 | (let ((eshell-test-value 42)) | 91 | (let ((eshell-test-value 42)) |
| 68 | (insert "echo $eshell-test-value") | 92 | (insert "echo $eshell-test-value") |
| 69 | (should (equal (car (eshell-complete-parse-arguments)) | 93 | (should (eshell-arguments-equal |
| 70 | '("echo" "42")))))) | 94 | (car (eshell-complete-parse-arguments)) |
| 95 | `("echo" ,(propertize "42" 'pcomplete-arg-value 42))))))) | ||
| 71 | 96 | ||
| 72 | (ert-deftest em-cmpl-test/parse-arguments/variable/nil () | 97 | (ert-deftest em-cmpl-test/parse-arguments/variable/nil () |
| 73 | "Test parsing arguments with a nil variable interpolation." | 98 | "Test parsing arguments with a nil variable interpolation." |
| 74 | (with-temp-eshell | 99 | (with-temp-eshell |
| 75 | (let ((eshell-test-value nil)) | 100 | (let ((eshell-test-value nil)) |
| 76 | (insert "echo $eshell-test-value") | 101 | (insert "echo $eshell-test-value") |
| 77 | (should (equal (car (eshell-complete-parse-arguments)) | 102 | (should (eshell-arguments-equal |
| 78 | '("echo" "")))))) | 103 | (car (eshell-complete-parse-arguments)) |
| 104 | `("echo" ,(propertize "" 'pcomplete-arg-value nil))))))) | ||
| 79 | 105 | ||
| 80 | (ert-deftest em-cmpl-test/parse-arguments/variable/list () | 106 | (ert-deftest em-cmpl-test/parse-arguments/variable/list () |
| 81 | "Test parsing arguments with a list variable interpolation." | 107 | "Test parsing arguments with a list variable interpolation." |
| 82 | (with-temp-eshell | 108 | (with-temp-eshell |
| 83 | (let ((eshell-test-value '("foo" "bar"))) | 109 | (let ((eshell-test-value '("foo" "bar"))) |
| 84 | (insert "echo $eshell-test-value") | 110 | (insert "echo $eshell-test-value") |
| 85 | (should (equal (car (eshell-complete-parse-arguments)) | 111 | (should (eshell-arguments-equal |
| 86 | '("echo" ("foo" "bar"))))))) | 112 | (car (eshell-complete-parse-arguments)) |
| 113 | `("echo" ,(propertize "(\"foo\" \"bar\")" | ||
| 114 | 'pcomplete-arg-value | ||
| 115 | eshell-test-value))))))) | ||
| 87 | 116 | ||
| 88 | (ert-deftest em-cmpl-test/parse-arguments/variable/splice () | 117 | (ert-deftest em-cmpl-test/parse-arguments/variable/splice () |
| 89 | "Test parsing arguments with a spliced variable interpolation." | 118 | "Test parsing arguments with a spliced variable interpolation." |
| 90 | (with-temp-eshell | 119 | (with-temp-eshell |
| 91 | (let ((eshell-test-value '("foo" "bar"))) | 120 | (let ((eshell-test-value '("foo" "bar"))) |
| 92 | (insert "echo $@eshell-test-value") | 121 | (insert "echo $@eshell-test-value") |
| 93 | (should (equal (car (eshell-complete-parse-arguments)) | 122 | (should (eshell-arguments-equal |
| 94 | '("echo" "foo" "bar")))))) | 123 | (car (eshell-complete-parse-arguments)) |
| 124 | '("echo" "foo" "bar")))))) | ||
| 95 | 125 | ||
| 96 | (ert-deftest em-cmpl-test/file-completion/unique () | 126 | (ert-deftest em-cmpl-test/file-completion/unique () |
| 97 | "Test completion of file names when there's a unique result." | 127 | "Test completion of file names when there's a unique result." |