emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 020ae66608 1/2: Add file-name-absolute-p from Em


From: ELPA Syncer
Subject: [elpa] externals/compat 020ae66608 1/2: Add file-name-absolute-p from Emacs 28
Date: Wed, 20 Jul 2022 04:57:25 -0400 (EDT)

branch: externals/compat
commit 020ae6660885d67e9c6063f192f8dc6cd6ab1c21
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add file-name-absolute-p from Emacs 28
---
 MANUAL          |  1 +
 compat-27.el    | 38 ++++++++++++++++++++++++++++++++++++++
 compat-tests.el | 14 ++++++++++++++
 compat.texi     |  9 +++++++++
 4 files changed, 62 insertions(+)

diff --git a/MANUAL b/MANUAL
index eba606ad5f..2c5633eaf3 100644
--- a/MANUAL
+++ b/MANUAL
@@ -450,6 +450,7 @@ provided by Compat by default:
 - Function: null-device :: Defined in ~files.el~.
 - Function: decoded-time-period :: Defined in ~time-data.el~.
 - Function: subr-primitive-p :: Defined in ~subr.el~.
+- Function: file-name-absolute-p :: See [[info:elisp#Relative File 
Names][(elisp) Relative File Names]].
 
 These functions are prefixed with ~compat~ prefix, and are only loaded
 when ~compat-28~ is required:
diff --git a/compat-27.el b/compat-27.el
index 3d909137d9..a5eb72e36a 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -342,6 +342,44 @@ A nil value for either argument stands for the current 
time."
                  (float-time (or t2 now))))
          1e-5)))))
 
+;;;; Defined in fileio.c
+
+(compat-defun file-name-absolute-p (filename)
+  "Return t if FILENAME is an absolute file name.
+On Unix, absolute file names start with `/'.  In Emacs, an absolute
+file name can also start with an initial `~' or `~USER' component,
+where USER is a valid login name."
+  ;; See definitions in filename.h
+  (let ((seperator
+         (eval-when-compile
+           (if (memq system-type '(cygwin windows-nt ms-dos))
+               "[\\/]" "/")))
+        (drive
+         (eval-when-compile
+           (cond
+            ((memq system-type '(windows-nt ms-dos))
+             "\\`[A-Za-z]:[\\/]")
+            ((eq system-type 'cygwin)
+             "\\`\\([\\/]\\|[A-Za-z]:\\)")
+            ("\\`/"))))
+        (home
+         (eval-when-compile
+           (if (memq system-type '(cygwin windows-nt ms-dos))
+               "\\`~[\\/]" "\\`~/")))
+        (user-home
+         (eval-when-compile
+           (format "\\`\\(~.*?\\)\\(%s.*\\)?$"
+                   (if (memq system-type '(cygwin windows-nt ms-dos))
+                       "[\\/]" "/")))))
+    (or (and (string-match-p drive filename) t)
+        (and (string-match-p home filename) t)
+        (save-excursion
+          (when (string-match user-home filename)
+            (let ((init (match-string 1 filename)))
+              (not (string=
+                    (file-name-base (expand-file-name init))
+                    init))))))))
+
 ;;;; Defined in subr.el
 
 (compat-defmacro setq-local (&rest pairs)
diff --git a/compat-tests.el b/compat-tests.el
index 1a9f63568d..70b7829453 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1777,5 +1777,19 @@ being compared against."
   (ought nil (symbol-function 'defun))        ;macro from subr.el
   (ought nil nil))
 
+(compat-deftests file-name-absolute-p   ;assuming unix
+  (ought t "/")
+  (ought t "/a")
+  (ought nil "a")
+  (ought nil "a/b")
+  (ought nil "a/b/")
+  (ought t "~")
+  (ought t "~/foo")
+  (ought nil "~foo")
+  (ought nil "~foo/")
+  (ought t "~root")
+  (ought t "~root/")
+  (ought t "~root/file"))
+
 (provide 'compat-tests)
 ;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index cb45222669..0a98f8dccc 100644
--- a/compat.texi
+++ b/compat.texi
@@ -1021,6 +1021,10 @@ Defined in @code{time-data.el}.
 Defined in @code{subr.el}.
 @end defun
 
+@defun file-name-absolute-p
+See @ref{Absolute and Relative File Names,(elisp) Relative File Names,,elisp,}.
+@end defun
+
 These functions are prefixed with @code{compat} prefix, and are only loaded
 when @code{compat-28} is required:
 
@@ -1152,3 +1156,8 @@ contribution (roughly 15 lines of code) can be applied.
 @printindex vr
 
 @bye
+
+@c Local Variables:
+@c mode: texinfo
+@c TeX-master: t
+@c End:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]