tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tramp (2.2.8-pre); tramp breaks dired-insert-subdir


From: Michael Albinus
Subject: Re: tramp (2.2.8-pre); tramp breaks dired-insert-subdir
Date: Mon, 07 Oct 2013 11:25:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

nb <address@hidden> writes:

Hi,

> tramp-sh-handle-insert-directory assumes it only ever appends to the
> buffer. As a result it violates the postcondition of insert-directory,
> upon which (at least) dired-insert-subdir depends.
>
> Test case:
>
> 1. Open a dired buffer over e.g. ssh. 
> 2. dired-insert-subdir a directory.
> 3. (Examine the markers in dired-subdir-alist.)
> 4. dired-insert-subdir a directory that's sorted before step 2's.
> 5. (Examine dired-subdir-alist again, note the markers are wrong.)

Ah, yes. Thanks for the report.

> Fix this by recording the position of the end of the inserted directory
> text, and using that instead of (point-max).

Wouldn't it be sufficient to apply narrow-to-region? Like this:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el
index 4bc836b..0216d5f 100644
--- a/lisp/tramp-sh.el
+++ b/lisp/tramp-sh.el
@@ -2544,61 +2544,63 @@ This is like `dired-recursive-delete-directory'
for Tramp files."
                   (tramp-shell-quote-argument
                    (tramp-run-real-handler
                     'file-name-nondirectory (list localname)))))))
-      (let ((beg (point)))
-       ;; We cannot use `insert-buffer-substring' because the Tramp
-       ;; buffer changes its contents before insertion due to calling
-       ;; `expand-file' and alike.
-       (insert
-        (with-current-buffer (tramp-get-buffer v)
-          (buffer-string)))
-
-       ;; Check for "--dired" output.
-       (forward-line -2)
-       (when (looking-at "//SUBDIRED//")
-         (forward-line -1))
-       (when (looking-at "//DIRED//\\s-+")
-         (let ((databeg (match-end 0))
-               (end (point-at-eol)))
-           ;; Now read the numeric positions of file names.
-           (goto-char databeg)
-           (while (< (point) end)
-             (let ((start (+ beg (read (current-buffer))))
-                   (end (+ beg (read (current-buffer)))))
-               (if (memq (char-after end) '(?\n ?\ ))
-                   ;; End is followed by \n or by " -> ".
-                   (put-text-property start end 'dired-filename t))))))
-       ;; Remove trailing lines.
-       (goto-char (point-at-bol))
-       (while (looking-at "//")
-         (forward-line 1)
-         (delete-region (match-beginning 0) (point)))
-
-       ;; Some busyboxes are reluctant to discard colors.
-       (unless (string-match "color" (tramp-get-connection-property v "ls" ""))
-         (goto-char beg)
-         (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
-           (replace-match "")))
-
-       ;; Decode the output, it could be multibyte.
-       (decode-coding-region
-        beg (point-max)
-        (or file-name-coding-system
-            (and (boundp 'default-file-name-coding-system)
-                 (symbol-value 'default-file-name-coding-system))))
-
-       ;; The inserted file could be from somewhere else.
-       (when (and (not wildcard) (not full-directory-p))
-         (goto-char (point-max))
-         (when (file-symlink-p filename)
-           (goto-char (search-backward "->" beg 'noerror)))
-         (search-backward
-          (if (zerop (length (file-name-nondirectory filename)))
-              "."
-            (file-name-nondirectory filename))
-          beg 'noerror)
-         (replace-match (file-relative-name filename) t))
-
-       (goto-char (point-max))))))
+      (save-restriction
+       (let ((beg (point)))
+         (narrow-to-region (point) (point))
+         ;; We cannot use `insert-buffer-substring' because the Tramp
+         ;; buffer changes its contents before insertion due to calling
+         ;; `expand-file' and alike.
+         (insert
+          (with-current-buffer (tramp-get-buffer v)
+            (buffer-string)))
+
+         ;; Check for "--dired" output.
+         (forward-line -2)
+         (when (looking-at "//SUBDIRED//")
+           (forward-line -1))
+         (when (looking-at "//DIRED//\\s-+")
+           (let ((databeg (match-end 0))
+                 (end (point-at-eol)))
+             ;; Now read the numeric positions of file names.
+             (goto-char databeg)
+             (while (< (point) end)
+               (let ((start (+ beg (read (current-buffer))))
+                     (end (+ beg (read (current-buffer)))))
+                 (if (memq (char-after end) '(?\n ?\ ))
+                     ;; End is followed by \n or by " -> ".
+                     (put-text-property start end 'dired-filename t))))))
+         ;; Remove trailing lines.
+         (goto-char (point-at-bol))
+         (while (looking-at "//")
+           (forward-line 1)
+           (delete-region (match-beginning 0) (point)))
+
+         ;; Some busyboxes are reluctant to discard colors.
+         (unless (string-match "color" (tramp-get-connection-property v "ls" 
""))
+           (goto-char beg)
+           (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
+             (replace-match "")))
+
+         ;; Decode the output, it could be multibyte.
+         (decode-coding-region
+          beg (point-max)
+          (or file-name-coding-system
+              (and (boundp 'default-file-name-coding-system)
+                   (symbol-value 'default-file-name-coding-system))))
+
+         ;; The inserted file could be from somewhere else.
+         (when (and (not wildcard) (not full-directory-p))
+           (goto-char (point-max))
+           (when (file-symlink-p filename)
+             (goto-char (search-backward "->" beg 'noerror)))
+           (search-backward
+            (if (zerop (length (file-name-nondirectory filename)))
+                "."
+              (file-name-nondirectory filename))
+            beg 'noerror)
+           (replace-match (file-relative-name filename) t))
+
+         (goto-char (point-max)))))))
 
 ;; Canonicalization of file names.

--8<---------------cut here---------------end--------------->8---

Best regards, Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]