aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2020-11-19 17:18:36 +0100
committerMichael Albinus2020-11-19 17:18:36 +0100
commit4fa1de82a28b04128fcb02b3dd1bfcca34efda4c (patch)
treeddf9296c40e8621c86c1dcaa93e8d12793764bc6
parent90aab73f8d6b5fd0a8adb706c8ae669564f23c56 (diff)
downloademacs-4fa1de82a28b04128fcb02b3dd1bfcca34efda4c.tar.gz
emacs-4fa1de82a28b04128fcb02b3dd1bfcca34efda4c.zip
Use decoding implementation from `insert-directory' in Tramp
* lisp/net/tramp-sh.el (tramp-sh-handle-insert-directory): Use decoding implementation from `insert-directory', it is more robust.
-rw-r--r--lisp/net/tramp-sh.el65
1 files changed, 39 insertions, 26 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index c4390b3d041..f9b218a970a 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -2658,8 +2658,7 @@ The method used must be an out-of-band method."
2658 #'file-name-nondirectory (list localname))))))) 2658 #'file-name-nondirectory (list localname)))))))
2659 2659
2660 (save-restriction 2660 (save-restriction
2661 (let ((beg (point)) 2661 (let ((beg (point)))
2662 match)
2663 (narrow-to-region (point) (point)) 2662 (narrow-to-region (point) (point))
2664 ;; We cannot use `insert-buffer-substring' because the Tramp 2663 ;; We cannot use `insert-buffer-substring' because the Tramp
2665 ;; buffer changes its contents before insertion due to calling 2664 ;; buffer changes its contents before insertion due to calling
@@ -2692,30 +2691,44 @@ The method used must be an out-of-band method."
2692 ;; Some busyboxes are reluctant to discard colors. 2691 ;; Some busyboxes are reluctant to discard colors.
2693 (unless 2692 (unless
2694 (string-match-p "color" (tramp-get-connection-property v "ls" "")) 2693 (string-match-p "color" (tramp-get-connection-property v "ls" ""))
2695 (goto-char beg) 2694 (save-excursion
2696 (while 2695 (goto-char beg)
2697 (re-search-forward tramp-display-escape-sequence-regexp nil t) 2696 (while
2698 (replace-match ""))) 2697 (re-search-forward tramp-display-escape-sequence-regexp nil t)
2699 2698 (replace-match ""))))
2700 ;; Decode the output, it could be multibyte. We must 2699
2701 ;; restore the text property, because `decode-coding-region' 2700 ;; Now decode what read if necessary. Stolen from `insert-directory'.
2702 ;; has destroyed it. However, text-property-search.el 2701 (let ((coding (or coding-system-for-read
2703 ;; exists since Emacs 27 only. 2702 file-name-coding-system
2704 (if (not (require 'text-property-search nil 'noerror)) 2703 default-file-name-coding-system
2705 (decode-coding-region 2704 'undecided))
2706 beg (point-max) 2705 coding-no-eol
2707 (or file-name-coding-system default-file-name-coding-system)) 2706 val pos)
2708 (goto-char beg) 2707 (when (and enable-multibyte-characters
2709 (while (setq match 2708 (not (memq (coding-system-base coding)
2710 (tramp-compat-funcall 2709 '(raw-text no-conversion))))
2711 'text-property-search-forward 'dired-filename t t)) 2710 ;; If no coding system is specified or detection is
2712 (decode-coding-region 2711 ;; requested, detect the coding.
2713 (tramp-compat-funcall 'prop-match-beginning match) 2712 (if (eq (coding-system-base coding) 'undecided)
2714 (tramp-compat-funcall 'prop-match-end match) 2713 (setq coding (detect-coding-region beg (point) t)))
2715 (or file-name-coding-system default-file-name-coding-system)) 2714 (if (not (eq (coding-system-base coding) 'undecided))
2716 (put-text-property 2715 (save-restriction
2717 (tramp-compat-funcall 'prop-match-beginning match) 2716 (setq coding-no-eol
2718 (point) 'dired-filename t))) 2717 (coding-system-change-eol-conversion coding 'unix))
2718 (narrow-to-region beg (point))
2719 (goto-char (point-min))
2720 (while (not (eobp))
2721 (setq pos (point)
2722 val (get-text-property (point) 'dired-filename))
2723 (goto-char (next-single-property-change
2724 (point) 'dired-filename nil (point-max)))
2725 ;; Force no eol conversion on a file name, so
2726 ;; that CR is preserved.
2727 (decode-coding-region pos (point)
2728 (if val coding-no-eol coding))
2729 (if val
2730 (put-text-property pos (point)
2731 'dired-filename t)))))))
2719 2732
2720 ;; The inserted file could be from somewhere else. 2733 ;; The inserted file could be from somewhere else.
2721 (when (and (not wildcard) (not full-directory-p)) 2734 (when (and (not wildcard) (not full-directory-p))