diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2013-09-08 17:04:10 +0200 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2013-09-08 17:04:10 +0200 |
commit | af9ff9e8058a9034b522d5b77cb7828cc6c137b4 (patch) | |
tree | 796559e33e753f931da7bdeedbbe3fdb0ce7e886 /lisp/net/tramp-compat.el | |
parent | 3aff2f57cc348b90c0f8b5926027cd0f0f378070 (diff) | |
download | emacs-af9ff9e8058a9034b522d5b77cb7828cc6c137b4.tar.gz emacs-af9ff9e8058a9034b522d5b77cb7828cc6c137b4.tar.bz2 emacs-af9ff9e8058a9034b522d5b77cb7828cc6c137b4.zip |
Improve compatibility with older Emacsen, and XEmacs.
* net/tramp.el (tramp-find-method, tramp-find-user): Call `propertize'
only if it is bound. It isn't for XEmacs.
(with-tramp-progress-reporter): Do not let-bind `result'. This
yields to scoping errors in XEmacs.
(tramp-handle-make-auto-save-file-name): New function, moved from
tramp-sh.el.
* net/tramp-adb.el (tramp-adb-file-name-handler-alist): Add handler
for `make-auto-save-file-name'.
(tramp-adb--gnu-switches-to-ash): Use
`tramp-compat-replace-regexp-in-string'.
* net/tramp-cache.el (tramp-cache-print): Call
`substring-no-properties' only if it is bound. It isn't for XEmacs.
* net/tramp-cmds.el (tramp-bug): Call `propertize' only if it is
bound. It isn't for XEmacs.
* net/tramp-compat.el (tramp-compat-copy-file): Catch
`wrong-number-of-arguments' error.
(tramp-compat-replace-regexp-in-string): New defun.
* net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): Add handler
for `make-auto-save-file-name'.
(tramp-gvfs-handle-copy-file): Use `tramp-compat-funcall' for
`copy-file'.
(tramp-gvfs-file-gvfs-monitor-file-process-filter)
(tramp-gvfs-file-name): Use `tramp-compat-replace-regexp-in-string'.
(tramp-synce-list-devices): Use `push' instead of `pushnew'.
* net/tramp-gw.el (tramp-gw-open-network-stream): Use
`tramp-compat-replace-regexp-in-string'.
* net/tramp-sh.el (tramp-sh-file-name-handler-alist): Call
`tramp-handle-make-auto-save-file-name'.
(tramp-sh-handle-make-auto-save-file-name): Move to tramp.el.
(tramp-sh-file-gvfs-monitor-dir-process-filter)
(tramp-sh-file-inotifywait-process-filter): Use
`tramp-compat-replace-regexp-in-string'.
(tramp-compute-multi-hops): Use `push' instead of `pushnew'.
* net/tramp-smb.el (tramp-smb-file-name-handler-alist): Add handler
for `make-auto-save-file-name'.
(tramp-smb-handle-copy-directory): Call
`tramp-compat-replace-regexp-in-string'.
(tramp-smb-get-file-entries): Use `push' instead of `pushnew'.
(tramp-smb-handle-copy-file): Improve error message.
(tramp-smb-handle-rename-file): Rename directly only in case
`newname' does not exist yet. This is a restriction of smbclient.
(tramp-smb-maybe-open-connection): Rerun the function only when
`auth-sources' is non-nil.
Diffstat (limited to 'lisp/net/tramp-compat.el')
-rw-r--r-- | lisp/net/tramp-compat.el | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 8f9d9d8fee5..ca70c1384cb 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -313,13 +313,21 @@ Not actually used. Use `(format \"%o\" i)' instead?" "Like `copy-file' for Tramp files (compat function)." (cond (preserve-extended-attributes - (tramp-compat-funcall - 'copy-file filename newname ok-if-already-exists keep-date - preserve-uid-gid preserve-extended-attributes)) + (condition-case nil + (tramp-compat-funcall + 'copy-file filename newname ok-if-already-exists keep-date + preserve-uid-gid preserve-extended-attributes) + (wrong-number-of-arguments + (tramp-compat-copy-file + filename newname ok-if-already-exists keep-date preserve-uid-gid)))) (preserve-uid-gid - (tramp-compat-funcall - 'copy-file filename newname ok-if-already-exists keep-date - preserve-uid-gid)) + (condition-case nil + (tramp-compat-funcall + 'copy-file filename newname ok-if-already-exists keep-date + preserve-uid-gid) + (wrong-number-of-arguments + (tramp-compat-copy-file + filename newname ok-if-already-exists keep-date)))) (t (copy-file filename newname ok-if-already-exists keep-date)))) @@ -518,6 +526,58 @@ EOL-TYPE can be one of `dos', `unix', or `mac'." "`dos', `unix', or `mac'"))))) (t (error "Can't change EOL conversion -- is MULE missing?")))) +;; `replace-regexp-in-string' does not exist in XEmacs. +;; Implementation is taken from Emacs 24. +(if (fboundp 'replace-regexp-in-string) + (defalias 'tramp-compat-replace-regexp-in-string 'replace-regexp-in-string) + (defun tramp-compat-replace-regexp-in-string + (regexp rep string &optional fixedcase literal subexp start) + "Replace all matches for REGEXP with REP in STRING. + +Return a new string containing the replacements. + +Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the +arguments with the same names of function `replace-match'. If START +is non-nil, start replacements at that index in STRING. + +REP is either a string used as the NEWTEXT arg of `replace-match' or a +function. If it is a function, it is called with the actual text of each +match, and its value is used as the replacement text. When REP is called, +the match data are the result of matching REGEXP against a substring +of STRING. + +To replace only the first match (if any), make REGEXP match up to \\' +and replace a sub-expression, e.g. + (replace-regexp-in-string \"\\\\(foo\\\\).*\\\\'\" \"bar\" \" foo foo\" nil nil 1) + => \" bar foo\"" + + (let ((l (length string)) + (start (or start 0)) + matches str mb me) + (save-match-data + (while (and (< start l) (string-match regexp string start)) + (setq mb (match-beginning 0) + me (match-end 0)) + ;; If we matched the empty string, make sure we advance by one char + (when (= me mb) (setq me (min l (1+ mb)))) + ;; Generate a replacement for the matched substring. + ;; Operate only on the substring to minimize string consing. + ;; Set up match data for the substring for replacement; + ;; presumably this is likely to be faster than munging the + ;; match data directly in Lisp. + (string-match regexp (setq str (substring string mb me))) + (setq matches + (cons (replace-match (if (stringp rep) + rep + (funcall rep (match-string 0 str))) + fixedcase literal str subexp) + (cons (substring string start mb) ; unmatched prefix + matches))) + (setq start me)) + ;; Reconstruct a string from the pieces. + (setq matches (cons (substring string start l) matches)) ; leftover + (apply #'concat (nreverse matches)))))) + (add-hook 'tramp-unload-hook (lambda () (unload-feature 'tramp-compat 'force))) |