]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-compat.el
Tramp diagnostics as per ‘text-quoting-style’
[gnu-emacs] / lisp / net / tramp-compat.el
index c5f1882931e35c6626d0ed03169ee2acc5418575..48eda2fd174c87f9452bf44381b676d5951e73e6 100644 (file)
@@ -1,6 +1,6 @@
 ;;; 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)
@@ -44,7 +49,8 @@
     (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))
@@ -230,8 +236,8 @@ this is the function `temp-directory'."
      ((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
@@ -288,7 +294,7 @@ Not actually used.  Use `(format \"%o\" i)' instead?"
   (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.
@@ -416,6 +422,13 @@ Not actually used.  Use `(format \"%o\" i)' instead?"
                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)
@@ -446,7 +459,7 @@ element is not omitted."
   (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.
@@ -521,10 +534,10 @@ EOL-TYPE can be one of `dos', `unix', or `mac'."
                ((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 "Cant change EOL conversion -- is MULE missing?"))))
 
 ;; `replace-regexp-in-string' does not exist in XEmacs.
 ;; Implementation is taken from Emacs 24.
@@ -578,8 +591,29 @@ and replace a sub-expression, e.g.
        (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)