;;; tramp-compat.el --- Tramp compatibility functions
-;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2015 Free Software Foundation, Inc.
;; Author: Michael Albinus <michael.albinus@gmx.de>
;; Keywords: comm, processes
(eval-and-compile
+ ;; GNU Emacs 22.
+ (unless (fboundp 'ignore-errors)
+ (load "cl" 'noerror)
+ (load "cl-macs" 'noerror))
+
;; Some packages must be required for XEmacs, because we compile
;; with -no-autoloads.
(when (featurep 'xemacs)
(require 'outline)
(require 'passwd)
(require 'pp)
- (require 'regexp-opt))
+ (require 'regexp-opt)
+ (require 'time-date))
(require 'advice)
(require 'custom)
(setq byte-compile-not-obsolete-vars '(directory-sep-char)))
;; `remote-file-name-inhibit-cache' has been introduced with Emacs 24.1.
- ;; Besides `t', `nil', and integer, we use also timestamps (as
+ ;; Besides t, nil, and integer, we use also timestamps (as
;; returned by `current-time') internally.
(unless (boundp 'remote-file-name-inhibit-cache)
(defvar remote-file-name-inhibit-cache nil))
((let ((d (getenv "TMPDIR"))) (and d (file-directory-p d)))
(file-name-as-directory (getenv "TMPDIR")))
((file-exists-p "c:/temp") (file-name-as-directory "c:/temp"))
- (t (message (concat "Neither `temporary-file-directory' nor "
- "`temp-directory' is defined -- using /tmp."))
+ (t (message (concat "Neither ‘temporary-file-directory’ nor "
+ "‘temp-directory’ is defined -- using /tmp."))
(file-name-as-directory "/tmp")))))
;; `make-temp-file' exists in Emacs only. On XEmacs, we use our own
(let ((x (or ostr "")))
;; `save-match' is in `tramp-mode-string-to-int' which calls this.
(unless (string-match "\\`[0-7]*\\'" x)
- (error "Non-octal junk in string `%s'" x))
+ (error "Non-octal junk in string ‘%s’" x))
(string-to-number ostr 8)))
;; ID-FORMAT does not exist in XEmacs.
directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
(delete-directory directory))))
+;; MUST-SUFFIX doesn't exist on XEmacs.
+(defun tramp-compat-load (file &optional noerror nomessage nosuffix must-suffix)
+ "Like `load' for Tramp files (compat function)."
+ (if must-suffix
+ (tramp-compat-funcall 'load file noerror nomessage nosuffix must-suffix)
+ (load file noerror nomessage nosuffix)))
+
;; `number-sequence' does not exist in XEmacs. Implementation is
;; taken from Emacs 23.
(defun tramp-compat-number-sequence (from &optional to inc)
(delete "" (split-string string pattern)))
(defun tramp-compat-process-running-p (process-name)
- "Returns `t' if system process PROCESS-NAME is running for `user-login-name'."
+ "Returns t if system process PROCESS-NAME is running for `user-login-name'."
(when (stringp process-name)
(cond
;; GNU Emacs 22 on w32.
((eq eol-type 'unix) 'lf)
((eq eol-type 'mac) 'cr)
(t
- (error "Unknown EOL-TYPE `%s', must be %s"
- eol-type
- "`dos', `unix', or `mac'")))))
- (t (error "Can't change EOL conversion -- is MULE missing?"))))
+ (error
+ "Unknown EOL-TYPE ‘%s’, must be ‘dos’, ‘unix’, or ‘mac’"
+ eol-type)))))
+ (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.
(setq matches (cons (substring string start l) matches)) ; leftover
(apply #'concat (nreverse matches))))))
+;; `default-toplevel-value' has been declared in Emacs 24.
+(unless (fboundp 'default-toplevel-value)
+ (defalias 'default-toplevel-value 'symbol-value))
+
+;; ‘format-message’ is new in Emacs 25, and does not exist in XEmacs.
+;; The substitute implementation always uses grave quoting style, for
+;; compatibility with older Emacs.
+(unless (fboundp 'format-message)
+ (defalias 'format-message
+ (lambda (format-string &rest args)
+ (let ((restyled-format-string
+ (let ((start (string-match "[‘’]" format-string)))
+ (if start
+ (tramp-compat-replace-regexp-in-string
+ "[‘’]"
+ (lambda (match) (if (string-equal match "‘") "`" "'"))
+ format-string t t nil start)
+ format-string))))
+ (apply #'format restyled-format-string args)))))
+
(add-hook 'tramp-unload-hook
(lambda ()
+ (unload-feature 'tramp-loaddefs 'force)
(unload-feature 'tramp-compat 'force)))
(provide 'tramp-compat)