From: Michael Albinus Date: Mon, 7 Oct 2013 12:45:20 +0000 (+0200) Subject: * net/tramp.el (tramp-handle-insert-file-contents): Improve handling X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1356 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f8f91d5d560aa64b7a4e5086eea4903a462afa68;p=emacs.git * net/tramp.el (tramp-handle-insert-file-contents): Improve handling of BEG and END. * net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): Use `tramp-handle-insert-file-contents'. (tramp-gvfs-handle-insert-file-contents): Remove function. * net/tramp-sh.el (tramp-sh-handle-insert-directory): Use `save-restriction' in order to keep markers. * net/trampver.el: Update release number. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0d9b4b10d6c..1cad30c0214 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,17 @@ +2013-10-07 Michael Albinus + + * net/tramp.el (tramp-handle-insert-file-contents): Improve handling + of BEG and END. + + * net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): Use + `tramp-handle-insert-file-contents'. + (tramp-gvfs-handle-insert-file-contents): Remove function. + + * net/tramp-sh.el (tramp-sh-handle-insert-directory): Use + `save-restriction' in order to keep markers. + + * net/trampver.el: Update release number. + 2013-10-07 Stefan Monnier * progmodes/compile.el (compilation-parse-errors): diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 8f79e495420..d4b7a89ce35 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -451,7 +451,7 @@ Every entry is a list (NAME ADDRESS).") ;; `find-file-noselect' performed by default handler. ;; `get-file-buffer' performed by default handler. (insert-directory . tramp-gvfs-handle-insert-directory) - (insert-file-contents . tramp-gvfs-handle-insert-file-contents) + (insert-file-contents . tramp-handle-insert-file-contents) (load . tramp-handle-load) (make-auto-save-file-name . tramp-handle-make-auto-save-file-name) (make-directory . tramp-gvfs-handle-make-directory) @@ -1014,32 +1014,6 @@ is no information where to trace the message.") 'insert-directory (list filename switches wildcard full-directory-p)))))) -(defun tramp-gvfs-handle-insert-file-contents - (filename &optional visit beg end replace) - "Like `insert-file-contents' for Tramp files." - (barf-if-buffer-read-only) - (setq filename (expand-file-name filename)) - (let (tmpfile result) - (unwind-protect - (if (not (file-exists-p filename)) - ;; We don't raise a Tramp error, because it might be - ;; suppressed, like in `find-file-noselect-1'. - (signal 'file-error (list "File not found on remote host" filename)) - - (setq tmpfile (file-local-copy filename) - result (insert-file-contents tmpfile visit beg end replace))) - ;; Save exit. - (when visit - (setq buffer-file-name filename) - (setq buffer-read-only (not (file-writable-p filename))) - (set-visited-file-modtime) - (set-buffer-modified-p nil)) - (when (stringp tmpfile) - (delete-file tmpfile))) - - ;; Result. - (list filename (cadr result)))) - (defun tramp-gvfs-handle-make-directory (dir &optional parents) "Like `make-directory' for Tramp files." (with-parsed-tramp-file-name dir nil diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 4bc836b88d5..8ed1c592617 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2544,61 +2544,64 @@ 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. diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 48420aad5a3..c5d728ba5c7 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3030,8 +3030,11 @@ User is always nil." (list localname visit beg end replace))) ;; When we shall insert only a part of the file, we - ;; copy this part. - (when (or beg end) + ;; copy this part. This works only for the shell file + ;; name handlers. + (when (and (or beg end) + (tramp-get-method-parameter + (tramp-file-name-method v) 'tramp-login-program)) (setq remote-copy (tramp-make-tramp-temp-file v)) ;; This is defined in tramp-sh.el. Let's assume ;; this is loaded already. @@ -3050,7 +3053,8 @@ User is always nil." (end (format "dd bs=1 count=%d if=%s of=%s" end (tramp-shell-quote-argument localname) - remote-copy))))) + remote-copy)))) + (setq tramp-temp-buffer-file-name nil beg nil end nil)) ;; `insert-file-contents-literally' takes care to ;; avoid calling jka-compr. By let-binding @@ -3093,7 +3097,7 @@ User is always nil." filename local-copy))) (setq result (insert-file-contents - local-copy visit nil nil replace))))) + local-copy visit beg end replace))))) ;; Save exit. (progn @@ -3846,7 +3850,7 @@ be granted." (stringp host) (string-match tramp-local-host-regexp host) ;; The method shall be applied to one of the shell file name - ;; handler. `tramp-local-host-p' is also called for "smb" and + ;; handlers. `tramp-local-host-p' is also called for "smb" and ;; alike, where it must fail. (tramp-get-method-parameter (tramp-file-name-method vec) 'tramp-login-program) diff --git a/lisp/net/trampver.el b/lisp/net/trampver.el index 8fc05872ca1..1986da8a94b 100644 --- a/lisp/net/trampver.el +++ b/lisp/net/trampver.el @@ -31,7 +31,7 @@ ;; should be changed only there. ;;;###tramp-autoload -(defconst tramp-version "2.2.8" +(defconst tramp-version "2.2.9-pre" "This version of Tramp.") ;;;###tramp-autoload @@ -44,7 +44,7 @@ (= emacs-major-version 21) (>= emacs-minor-version 4))) "ok" - (format "Tramp 2.2.8 is not fit for %s" + (format "Tramp 2.2.9-pre is not fit for %s" (when (string-match "^.*$" (emacs-version)) (match-string 0 (emacs-version))))))) (unless (string-match "\\`ok\\'" x) (error "%s" x)))