* net/tramp.el (tramp-replace-environment-variables): Hide
[bpt/emacs.git] / lisp / net / tramp-compat.el
CommitLineData
94be87e8 1;;; tramp-compat.el --- Tramp compatibility functions
9e6ab520 2
acaf905b 3;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
9e6ab520
MA
4
5;; Author: Michael Albinus <michael.albinus@gmx.de>
6;; Keywords: comm, processes
bd78fa1d 7;; Package: tramp
9e6ab520
MA
8
9;; This file is part of GNU Emacs.
10
874a927a 11;; GNU Emacs is free software: you can redistribute it and/or modify
9e6ab520 12;; it under the terms of the GNU General Public License as published by
874a927a
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
9e6ab520
MA
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
874a927a 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
9e6ab520
MA
23
24;;; Commentary:
25
1cdd2a1b
MA
26;; Tramp's main Emacs version for development is Emacs 24. This
27;; package provides compatibility functions for Emacs 22, Emacs 23,
28;; XEmacs 21.4+ and SXEmacs 22.
9e6ab520
MA
29
30;;; Code:
31
9fa0d3aa 32(eval-when-compile
94be87e8
MA
33
34 ;; Pacify byte-compiler.
9fa0d3aa
MA
35 (require 'cl))
36
37(eval-and-compile
38
957b3189
MA
39 ;; Some packages must be required for XEmacs, because we compile
40 ;; with -no-autoloads.
41 (when (featurep 'xemacs)
42 (require 'cus-edit)
43 (require 'env)
44 (require 'executable)
45 (require 'outline)
46 (require 'passwd)
47 (require 'pp)
48 (require 'regexp-opt))
49
03c1ad43 50 (require 'advice)
94be87e8 51 (require 'custom)
03c1ad43 52 (require 'format-spec)
710dec63 53 (require 'shell)
03c1ad43 54
957b3189
MA
55 (require 'tramp-loaddefs)
56
03c1ad43
MA
57 ;; As long as password.el is not part of (X)Emacs, it shouldn't be
58 ;; mandatory.
59 (if (featurep 'xemacs)
60 (load "password" 'noerror)
61 (or (require 'password-cache nil 'noerror)
62 (require 'password nil 'noerror))) ; Part of contrib.
63
64 ;; auth-source is relatively new.
65 (if (featurep 'xemacs)
66 (load "auth-source" 'noerror)
67 (require 'auth-source nil 'noerror))
9e6ab520 68
94be87e8
MA
69 ;; Load the appropriate timer package.
70 (if (featurep 'xemacs)
71 (require 'timer-funcs)
72 (require 'timer))
9e6ab520 73
94be87e8
MA
74 ;; Avoid byte-compiler warnings if the byte-compiler supports this.
75 ;; Currently, XEmacs supports this.
76 (when (featurep 'xemacs)
77 (unless (boundp 'byte-compile-default-warnings)
78 (defvar byte-compile-default-warnings nil))
79 (delq 'unused-vars byte-compile-default-warnings))
80
81 ;; `last-coding-system-used' is unknown in XEmacs.
9e6ab520 82 (unless (boundp 'last-coding-system-used)
94be87e8 83 (defvar last-coding-system-used nil))
9e6ab520 84
94be87e8
MA
85 ;; `directory-sep-char' is an obsolete variable in Emacs. But it is
86 ;; used in XEmacs, so we set it here and there. The following is
87 ;; needed to pacify Emacs byte-compiler.
77f38949
GM
88 ;; Note that it was removed altogether in Emacs 24.1.
89 (when (boundp 'directory-sep-char)
bd8fadca 90 (defvar byte-compile-not-obsolete-var nil)
77f38949
GM
91 (setq byte-compile-not-obsolete-var 'directory-sep-char)
92 ;; Emacs 23.2.
bd8fadca 93 (defvar byte-compile-not-obsolete-vars nil)
77f38949 94 (setq byte-compile-not-obsolete-vars '(directory-sep-char)))
9e6ab520 95
4bc3c53d
MA
96 ;; `remote-file-name-inhibit-cache' has been introduced with Emacs 24.1.
97 ;; Besides `t', `nil', and integer, we use also timestamps (as
98 ;; returned by `current-time') internally.
99 (defvar remote-file-name-inhibit-cache nil)
100
0d5852cf
MA
101 ;; For not existing functions, or functions with a changed argument
102 ;; list, there are compiler warnings. We want to avoid them in
103 ;; cases we know what we do.
104 (defmacro tramp-compat-funcall (function &rest arguments)
105 (if (featurep 'xemacs)
106 `(funcall (symbol-function ,function) ,@arguments)
107 `(when (or (subrp ,function) (functionp ,function))
108 (with-no-warnings (funcall ,function ,@arguments)))))
109
94be87e8 110 ;; `set-buffer-multibyte' comes from Emacs Leim.
9e6ab520 111 (unless (fboundp 'set-buffer-multibyte)
94be87e8 112 (defalias 'set-buffer-multibyte 'ignore))
9e6ab520 113
e5aa47f9
MA
114 ;; The following functions cannot be aliases of the corresponding
115 ;; `tramp-handle-*' functions, because this would bypass the locking
116 ;; mechanism.
117
94be87e8 118 ;; `file-remote-p' has been introduced with Emacs 22. The version
5504e2c7 119 ;; of XEmacs is not a magic file name function (yet).
94be87e8 120 (unless (fboundp 'file-remote-p)
e5aa47f9
MA
121 (defalias 'file-remote-p
122 (lambda (file &optional identification connected)
123 (when (tramp-tramp-file-p file)
957b3189
MA
124 (tramp-compat-funcall
125 'tramp-file-name-handler
e5aa47f9 126 'file-remote-p file identification connected)))))
94be87e8 127
b533bc97 128 ;; `process-file' does not exist in XEmacs.
94be87e8 129 (unless (fboundp 'process-file)
e5aa47f9
MA
130 (defalias 'process-file
131 (lambda (program &optional infile buffer display &rest args)
132 (when (tramp-tramp-file-p default-directory)
133 (apply
134 'tramp-file-name-handler
135 'process-file program infile buffer display args)))))
94be87e8
MA
136
137 ;; `start-file-process' is new in Emacs 23.
138 (unless (fboundp 'start-file-process)
e5aa47f9
MA
139 (defalias 'start-file-process
140 (lambda (name buffer program &rest program-args)
141 (when (tramp-tramp-file-p default-directory)
142 (apply
143 'tramp-file-name-handler
144 'start-file-process name buffer program program-args)))))
94be87e8
MA
145
146 ;; `set-file-times' is also new in Emacs 23.
147 (unless (fboundp 'set-file-times)
e5aa47f9
MA
148 (defalias 'set-file-times
149 (lambda (filename &optional time)
150 (when (tramp-tramp-file-p filename)
957b3189
MA
151 (tramp-compat-funcall
152 'tramp-file-name-handler 'set-file-times filename time)))))
1f3611c6
MA
153
154 ;; We currently use "[" and "]" in the filename format for IPv6
2c68ca0e 155 ;; hosts of GNU Emacs. This means that Emacs wants to expand
1f3611c6
MA
156 ;; wildcards if `find-file-wildcards' is non-nil, and then barfs
157 ;; because no expansion could be found. We detect this situation
158 ;; and do something really awful: we have `file-expand-wildcards'
159 ;; return the original filename if it can't expand anything. Let's
160 ;; just hope that this doesn't break anything else.
161 ;; It is not needed anymore since GNU Emacs 23.2.
b533bc97
MA
162 (unless (or (featurep 'xemacs)
163 ;; `featurep' has only one argument in XEmacs.
164 (funcall 'featurep 'files 'remote-wildcards))
1f3611c6
MA
165 (defadvice file-expand-wildcards
166 (around tramp-advice-file-expand-wildcards activate)
167 (let ((name (ad-get-arg 0)))
168 ;; If it's a Tramp file, look if wildcards need to be expanded
169 ;; at all.
170 (if (and
171 (tramp-tramp-file-p name)
172 (not (string-match
b81a0b56
MA
173 "[[*?]" (tramp-compat-funcall
174 'file-remote-p name 'localname))))
1f3611c6
MA
175 (setq ad-return-value (list name))
176 ;; Otherwise, just run the original function.
177 ad-do-it)))
178 (add-hook
179 'tramp-unload-hook
180 (lambda ()
181 (ad-remove-advice
182 'file-expand-wildcards 'around 'tramp-advice-file-expand-wildcards)
183 (ad-activate 'file-expand-wildcards)))))
9e6ab520 184
6139f995
MA
185;; `with-temp-message' does not exists in XEmacs.
186(if (fboundp 'with-temp-message)
187 (defalias 'tramp-compat-with-temp-message 'with-temp-message)
1a9dc3b5 188 (defmacro tramp-compat-with-temp-message (message &rest body)
6139f995
MA
189 "Display MESSAGE temporarily if non-nil while BODY is evaluated."
190 `(progn ,@body)))
191
2fe4b125
MA
192;; `condition-case-unless-debug' is introduced with Emacs 24.
193(if (fboundp 'condition-case-unless-debug)
194 (defalias 'tramp-compat-condition-case-unless-debug
195 'condition-case-unless-debug)
196 (defmacro tramp-compat-condition-case-unless-debug
197 (var bodyform &rest handlers)
198 "Like `condition-case' except that it does not catch anything when debugging."
199 (declare (debug condition-case) (indent 2))
200 (let ((bodysym (make-symbol "body")))
201 `(let ((,bodysym (lambda () ,bodyform)))
202 (if debug-on-error
203 (funcall ,bodysym)
204 (condition-case ,var
205 (funcall ,bodysym)
206 ,@handlers))))))
207
6139f995
MA
208;; `font-lock-add-keywords' does not exist in XEmacs.
209(defun tramp-compat-font-lock-add-keywords (mode keywords &optional how)
210 "Add highlighting KEYWORDS for MODE."
211 (ignore-errors
212 (tramp-compat-funcall 'font-lock-add-keywords mode keywords how)))
213
9e6ab520
MA
214(defsubst tramp-compat-temporary-file-directory ()
215 "Return name of directory for temporary files (compat function).
216For Emacs, this is the variable `temporary-file-directory', for XEmacs
217this is the function `temp-directory'."
03310646 218 (let (file-name-handler-alist)
957b3189
MA
219 ;; We must return a local directory. If it is remote, we could
220 ;; run into an infloop.
03310646 221 (cond
957b3189
MA
222 ((and (boundp 'temporary-file-directory)
223 (eval (car (get 'temporary-file-directory 'standard-value)))))
03310646
MA
224 ((fboundp 'temp-directory) (tramp-compat-funcall 'temp-directory))
225 ((let ((d (getenv "TEMP"))) (and d (file-directory-p d)))
226 (file-name-as-directory (getenv "TEMP")))
227 ((let ((d (getenv "TMP"))) (and d (file-directory-p d)))
228 (file-name-as-directory (getenv "TMP")))
229 ((let ((d (getenv "TMPDIR"))) (and d (file-directory-p d)))
230 (file-name-as-directory (getenv "TMPDIR")))
231 ((file-exists-p "c:/temp") (file-name-as-directory "c:/temp"))
232 (t (message (concat "Neither `temporary-file-directory' nor "
233 "`temp-directory' is defined -- using /tmp."))
234 (file-name-as-directory "/tmp")))))
9e6ab520 235
b533bc97
MA
236;; `make-temp-file' exists in Emacs only. On XEmacs, we use our own
237;; implementation with `make-temp-name', creating the temporary file
238;; immediately in order to avoid a security hole.
9cf3544e 239(defsubst tramp-compat-make-temp-file (filename &optional dir-flag)
258800f8
MA
240 "Create a temporary file (compat function).
241Add the extension of FILENAME, if existing."
87bdd2c7
MA
242 (let* (file-name-handler-alist
243 (prefix (expand-file-name
244 (symbol-value 'tramp-temp-name-prefix)
245 (tramp-compat-temporary-file-directory)))
246 (extension (file-name-extension filename t))
247 result)
b81a0b56 248 (condition-case nil
258800f8 249 (setq result
0d5852cf 250 (tramp-compat-funcall 'make-temp-file prefix dir-flag extension))
b81a0b56
MA
251 (error
252 ;; We use our own implementation, taken from files.el.
253 (while
254 (condition-case ()
255 (progn
256 (setq result (concat (make-temp-name prefix) extension))
257 (if dir-flag
258 (make-directory result)
259 (write-region "" nil result nil 'silent))
260 nil)
261 (file-already-exists t))
262 ;; The file was somehow created by someone else between
263 ;; `make-temp-name' and `write-region', let's try again.
264 nil)))
258800f8
MA
265 result))
266
b533bc97 267;; `most-positive-fixnum' does not exist in XEmacs.
9e6ab520
MA
268(defsubst tramp-compat-most-positive-fixnum ()
269 "Return largest positive integer value (compat function)."
94be87e8
MA
270 (cond
271 ((boundp 'most-positive-fixnum) (symbol-value 'most-positive-fixnum))
b533bc97 272 ;; Default value in XEmacs.
94be87e8 273 (t 134217727)))
9e6ab520 274
0f34aa77
MA
275(defun tramp-compat-decimal-to-octal (i)
276 "Return a string consisting of the octal digits of I.
277Not actually used. Use `(format \"%o\" i)' instead?"
278 (cond ((< i 0) (error "Cannot convert negative number to octal"))
279 ((not (integerp i)) (error "Cannot convert non-integer to octal"))
280 ((zerop i) "0")
281 (t (concat (tramp-compat-decimal-to-octal (/ i 8))
282 (number-to-string (% i 8))))))
283
284;; Kudos to Gerd Moellmann for this suggestion.
285(defun tramp-compat-octal-to-decimal (ostr)
286 "Given a string of octal digits, return a decimal number."
287 (let ((x (or ostr "")))
288 ;; `save-match' is in `tramp-mode-string-to-int' which calls this.
289 (unless (string-match "\\`[0-7]*\\'" x)
290 (error "Non-octal junk in string `%s'" x))
291 (string-to-number ostr 8)))
292
b533bc97 293;; ID-FORMAT does not exists in XEmacs.
9e6ab520
MA
294(defun tramp-compat-file-attributes (filename &optional id-format)
295 "Like `file-attributes' for Tramp files (compat function)."
296 (cond
297 ((or (null id-format) (eq id-format 'integer))
298 (file-attributes filename))
e5aa47f9 299 ((tramp-tramp-file-p filename)
957b3189
MA
300 (tramp-compat-funcall
301 'tramp-file-name-handler 'file-attributes filename id-format))
9e6ab520 302 (t (condition-case nil
0d5852cf 303 (tramp-compat-funcall 'file-attributes filename id-format)
9566840f 304 (wrong-number-of-arguments (file-attributes filename))))))
9e6ab520 305
1cdd2a1b
MA
306;; PRESERVE-UID-GID does not exist in XEmacs.
307;; PRESERVE-SELINUX-CONTEXT has been introduced with Emacs 24.1.
9e6ab520 308(defun tramp-compat-copy-file
0d5852cf
MA
309 (filename newname &optional ok-if-already-exists keep-date
310 preserve-uid-gid preserve-selinux-context)
9e6ab520 311 "Like `copy-file' for Tramp files (compat function)."
0d5852cf
MA
312 (cond
313 (preserve-selinux-context
314 (tramp-compat-funcall
315 'copy-file filename newname ok-if-already-exists keep-date
316 preserve-uid-gid preserve-selinux-context))
317 (preserve-uid-gid
318 (tramp-compat-funcall
319 'copy-file filename newname ok-if-already-exists keep-date
320 preserve-uid-gid))
321 (t
322 (copy-file filename newname ok-if-already-exists keep-date))))
9e6ab520 323
c2770957
MA
324;; `copy-directory' is a new function in Emacs 23.2. Implementation
325;; is taken from there.
326(defun tramp-compat-copy-directory
2fe4b125 327 (directory newname &optional keep-time parents copy-contents)
c2770957 328 "Make a copy of DIRECTORY (compat function)."
2fe4b125
MA
329 (condition-case nil
330 (tramp-compat-funcall
331 'copy-directory directory newname keep-time parents copy-contents)
332
333 ;; `copy-directory' is either not implemented, or it does not
334 ;; support the the COPY-CONTENTS flag. For the time being, we
335 ;; ignore COPY-CONTENTS as well.
336
337 (error
338 ;; If `default-directory' is a remote directory, make sure we
339 ;; find its `copy-directory' handler.
340 (let ((handler (or (find-file-name-handler directory 'copy-directory)
341 (find-file-name-handler newname 'copy-directory))))
342 (if handler
343 (funcall handler 'copy-directory directory newname keep-time parents)
344
345 ;; Compute target name.
346 (setq directory (directory-file-name (expand-file-name directory))
347 newname (directory-file-name (expand-file-name newname)))
348 (if (and (file-directory-p newname)
349 (not (string-equal (file-name-nondirectory directory)
350 (file-name-nondirectory newname))))
351 (setq newname
352 (expand-file-name
353 (file-name-nondirectory directory) newname)))
354 (if (not (file-directory-p newname)) (make-directory newname parents))
355
356 ;; Copy recursively.
357 (mapc
358 (lambda (file)
359 (if (file-directory-p file)
360 (tramp-compat-copy-directory file newname keep-time parents)
361 (copy-file file newname t keep-time)))
362 ;; We do not want to delete "." and "..".
363 (directory-files
364 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
365
366 ;; Set directory attributes.
367 (set-file-modes newname (file-modes directory))
368 (if keep-time
369 (set-file-times newname (nth 5 (file-attributes directory)))))))))
c2770957 370
f1a5d776
CY
371;; TRASH has been introduced with Emacs 24.1.
372(defun tramp-compat-delete-file (filename &optional trash)
66bdc868 373 "Like `delete-file' for Tramp files (compat function)."
f1a5d776
CY
374 (condition-case nil
375 (tramp-compat-funcall 'delete-file filename trash)
376 ;; This Emacs version does not support the TRASH flag.
377 (wrong-number-of-arguments
378 (let ((delete-by-moving-to-trash
379 (and (boundp 'delete-by-moving-to-trash)
eba082a2 380 (symbol-value 'delete-by-moving-to-trash)
f1a5d776
CY
381 trash)))
382 (delete-file filename)))))
66bdc868 383
c2770957
MA
384;; RECURSIVE has been introduced with Emacs 23.2.
385(defun tramp-compat-delete-directory (directory &optional recursive)
386 "Like `delete-directory' for Tramp files (compat function)."
b533bc97
MA
387 (if (null recursive)
388 (delete-directory directory)
389 (condition-case nil
0d5852cf 390 (tramp-compat-funcall 'delete-directory directory recursive)
b533bc97
MA
391 ;; This Emacs version does not support the RECURSIVE flag. We
392 ;; use the implementation from Emacs 23.2.
9566840f 393 (wrong-number-of-arguments
b533bc97
MA
394 (setq directory (directory-file-name (expand-file-name directory)))
395 (if (not (file-symlink-p directory))
396 (mapc (lambda (file)
397 (if (eq t (car (file-attributes file)))
398 (tramp-compat-delete-directory file recursive)
399 (delete-file file)))
400 (directory-files
401 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
402 (delete-directory directory)))))
403
404;; `number-sequence' does not exist in XEmacs. Implementation is
405;; taken from Emacs 23.
e5aa47f9
MA
406(defun tramp-compat-number-sequence (from &optional to inc)
407 "Return a sequence of numbers from FROM to TO as a list (compat function)."
408 (if (or (subrp 'number-sequence) (symbol-file 'number-sequence))
0d5852cf 409 (tramp-compat-funcall 'number-sequence from to inc)
e5aa47f9
MA
410 (if (or (not to) (= from to))
411 (list from)
412 (or inc (setq inc 1))
413 (when (zerop inc) (error "The increment can not be zero"))
414 (let (seq (n 0) (next from))
415 (if (> inc 0)
416 (while (<= next to)
417 (setq seq (cons next seq)
418 n (1+ n)
419 next (+ from (* n inc))))
420 (while (>= next to)
421 (setq seq (cons next seq)
422 n (1+ n)
423 next (+ from (* n inc)))))
424 (nreverse seq)))))
425
b41b828a
MA
426(defun tramp-compat-split-string (string pattern)
427 "Like `split-string' but omit empty strings.
428In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").
429This is, the first, empty, element is omitted. In XEmacs, the first
430element is not omitted."
431 (delete "" (split-string string pattern)))
432
0f34aa77
MA
433(defun tramp-compat-call-process
434 (program &optional infile destination display &rest args)
435 "Calls `call-process' on the local host.
436This is needed because for some Emacs flavors Tramp has
4c36be58 437defadvised `call-process' to behave like `process-file'. The
0f34aa77
MA
438Lisp error raised when PROGRAM is nil is trapped also, returning 1."
439 (let ((default-directory
440 (if (file-remote-p default-directory)
441 (tramp-compat-temporary-file-directory)
442 default-directory)))
443 (if (executable-find program)
444 (apply 'call-process program infile destination display args)
445 1)))
446
b41b828a
MA
447(defun tramp-compat-process-running-p (process-name)
448 "Returns `t' if system process PROCESS-NAME is running for `user-login-name'."
449 (when (stringp process-name)
450 (cond
451 ;; GNU Emacs 22 on w32.
452 ((fboundp 'w32-window-exists-p)
0d5852cf 453 (tramp-compat-funcall 'w32-window-exists-p process-name process-name))
b41b828a
MA
454
455 ;; GNU Emacs 23.
456 ((and (fboundp 'list-system-processes) (fboundp 'process-attributes))
457 (let (result)
0d5852cf
MA
458 (dolist (pid (tramp-compat-funcall 'list-system-processes) result)
459 (let ((attributes (tramp-compat-funcall 'process-attributes pid)))
f58f7520
SS
460 (when (and (string-equal
461 (cdr (assoc 'user attributes)) (user-login-name))
462 (let ((comm (cdr (assoc 'comm attributes))))
463 ;; The returned command name could be truncated
464 ;; to 15 characters. Therefore, we cannot check
465 ;; for `string-equal'.
466 (and comm (string-match
467 (concat "^" (regexp-quote comm))
468 process-name))))
b41b828a
MA
469 (setq result t))))))
470
471 ;; Fallback, if there is no Lisp support yet.
472 (t (let ((default-directory
473 (if (file-remote-p default-directory)
474 (tramp-compat-temporary-file-directory)
475 default-directory))
476 (unix95 (getenv "UNIX95"))
477 result)
478 (setenv "UNIX95" "1")
479 (when (member
480 (user-login-name)
481 (tramp-compat-split-string
482 (shell-command-to-string
483 (format "ps -C %s -o user=" process-name))
484 "[ \f\t\n\r\v]+"))
485 (setq result t))
486 (setenv "UNIX95" unix95)
487 result)))))
488
6139f995
MA
489;; The following functions do not exist in XEmacs. We ignore this;
490;; they are used for checking a remote tty.
491(defun tramp-compat-process-get (process propname)
492 "Return the value of PROCESS' PROPNAME property.
493This is the last value stored with `(process-put PROCESS PROPNAME VALUE)'."
494 (ignore-errors (tramp-compat-funcall 'process-get process propname)))
495
496(defun tramp-compat-process-put (process propname value)
497 "Change PROCESS' PROPNAME property to VALUE.
498It can be retrieved with `(process-get PROCESS PROPNAME)'."
499 (ignore-errors (tramp-compat-funcall 'process-put process propname value)))
500
bd8fadca
MA
501(defun tramp-compat-set-process-query-on-exit-flag (process flag)
502 "Specify if query is needed for process when Emacs is exited.
503If the second argument flag is non-nil, Emacs will query the user before
504exiting if process is running."
505 (if (fboundp 'set-process-query-on-exit-flag)
506 (tramp-compat-funcall 'set-process-query-on-exit-flag process flag)
507 (tramp-compat-funcall 'process-kill-without-query process flag)))
508
1cdd2a1b 509;; There exist different implementations for this function.
bd8fadca
MA
510(defun tramp-compat-coding-system-change-eol-conversion (coding-system eol-type)
511 "Return a coding system like CODING-SYSTEM but with given EOL-TYPE.
512EOL-TYPE can be one of `dos', `unix', or `mac'."
513 (cond ((fboundp 'coding-system-change-eol-conversion)
514 (tramp-compat-funcall
515 'coding-system-change-eol-conversion coding-system eol-type))
516 ((fboundp 'subsidiary-coding-system)
517 (tramp-compat-funcall
518 'subsidiary-coding-system coding-system
519 (cond ((eq eol-type 'dos) 'crlf)
520 ((eq eol-type 'unix) 'lf)
521 ((eq eol-type 'mac) 'cr)
522 (t
523 (error "Unknown EOL-TYPE `%s', must be %s"
524 eol-type
525 "`dos', `unix', or `mac'")))))
526 (t (error "Can't change EOL conversion -- is MULE missing?"))))
527
1cdd2a1b
MA
528(add-hook 'tramp-unload-hook
529 (lambda ()
530 (unload-feature 'tramp-compat 'force)))
531
9e6ab520
MA
532(provide 'tramp-compat)
533
534;;; TODO:
535
536;;; tramp-compat.el ends here