From 7f28faa497419aeda4fed6ec413b7d6060f2c203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= Date: Wed, 3 Jul 2019 21:17:57 +0200 Subject: [PATCH 5/5] Add '^' markers below non-isolated chars in dired prompt * lisp/dired-aux.el (dired--mark-positions): New function. (dired--no-subst-prompt): Use it. * test/lisp/dired-aux-tests.el (dired-test-highlight-metachar): Add assertion for '^' marker positions. (Bug#35564) --- lisp/dired-aux.el | 25 +++++++++++++++++-------- test/lisp/dired-aux-tests.el | 8 ++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 7ea1191c49..cc11f2674f 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -102,18 +102,27 @@ dired--need-confirm-positions (setq start (match-end 0))) confirm-positions)) +(defun dired--mark-positions (positions) + (let* ((positions (sort positions '<)) + (markers (make-string (1+ (car (last positions))) ?\s))) + (dolist (pos positions) + (setf (aref markers pos) ?^)) + markers)) + (defun dired--no-subst-prompt (char-positions command) (cl-callf substring-no-properties command) (dolist (pos char-positions) (add-face-text-property pos (1+ pos) 'warning nil command)) - (concat command "\n" - (format-message - (ngettext "Send %d occurrence of `%s' as-is to shell?" - "Send %d occurrences of `%s' as-is to shell?" - (length char-positions)) - (length char-positions) - (propertize (string (aref command (car char-positions))) - 'face 'warning)))) + (let ((markers (dired--mark-positions char-positions))) + (concat command "\n" + markers "\n" + (format-message + (ngettext "Send %d occurrence of `%s' as-is to shell?" + "Send %d occurrences of `%s' as-is to shell?" + (length char-positions)) + (length char-positions) + (propertize (string (aref command (car char-positions))) + 'face 'warning))))) ;;;###autoload (defun dired-diff (file &optional switches) diff --git a/test/lisp/dired-aux-tests.el b/test/lisp/dired-aux-tests.el index ff18edddb6..fbadfcbf12 100644 --- a/test/lisp/dired-aux-tests.el +++ b/test/lisp/dired-aux-tests.el @@ -117,6 +117,7 @@ dired-test-bug30624 (ert-deftest dired-test-highlight-metachar () "Check that non-isolated meta-characters are highlighted" (let* ((command "sed -r -e 's/oo?/a/' -e 's/oo?/a/' ? `?`") + (markers " ^ ^") (prompt (dired--no-subst-prompt (dired--need-confirm-positions command "?") command)) @@ -126,9 +127,11 @@ dired-test-highlight-metachar (should (equal 'warning (get-text-property 15 'face result))) (should-not (text-property-not-all 16 28 'face nil result)) (should (equal 'warning (get-text-property 29 'face result))) - (should-not (text-property-not-all 30 39 'face nil result))) + (should-not (text-property-not-all 30 39 'face nil result)) + (should (string-match (regexp-quote markers) prompt (1+ (length command))))) ;; Note that `?` is considered isolated, but `*` is not. (let* ((command "sed -e 's/o*/a/' -e 's/o`*` /a/'") + (markers " ^ ^") (prompt (dired--no-subst-prompt (dired--need-confirm-positions command "*") command)) @@ -138,7 +141,8 @@ dired-test-highlight-metachar (should (equal 'warning (get-text-property 11 'face result))) (should-not (text-property-not-all 12 23 'face nil result)) (should (equal 'warning (get-text-property 25 'face result))) - (should-not (text-property-not-all 26 32 'face nil result)))) + (should-not (text-property-not-all 26 32 'face nil result)) + (should (string-match (regexp-quote markers) prompt (1+ (length command)))))) (provide 'dired-aux-tests) ;; dired-aux-tests.el ends here -- 2.22.0