[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 8d17ffdd88 29/84: Add file-has-changed-p from Em
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 8d17ffdd88 29/84: Add file-has-changed-p from Emacs 29 |
Date: |
Tue, 3 Jan 2023 08:57:33 -0500 (EST) |
branch: externals/compat
commit 8d17ffdd88d913e70cd61ea8a85407034a6260a2
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add file-has-changed-p from Emacs 29
---
compat-29.el | 24 ++++++++++++++++++++++++
compat.texi | 17 +++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/compat-29.el b/compat-29.el
index 9538e99c72..540350d6c0 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -381,5 +381,29 @@ to `default-directory', and the result will also be
relative."
(t
parent))))
+(defvar compat--file-has-changed-p--hash-table (make-hash-table :test #'equal)
+ "Internal variable used by `file-has-changed-p'.")
+
+;;* UNTESTED
+(compat-defun file-has-changed-p (file &optional tag)
+ "Return non-nil if FILE has changed.
+The size and modification time of FILE are compared to the size
+and modification time of the same FILE during a previous
+invocation of `file-has-changed-p'. Thus, the first invocation
+of `file-has-changed-p' always returns non-nil when FILE exists.
+The optional argument TAG, which must be a symbol, can be used to
+limit the comparison to invocations with identical tags; it can be
+the symbol of the calling function, for example."
+ (let* ((file (directory-file-name (expand-file-name file)))
+ (remote-file-name-inhibit-cache t)
+ (fileattr (file-attributes file 'integer))
+ (attr (and fileattr
+ (cons (file-attribute-size fileattr)
+ (file-attribute-modification-time fileattr))))
+ (sym (concat (symbol-name tag) "@" file))
+ (cachedattr (gethash sym compat--file-has-changed-p--hash-table)))
+ (when (not (equal attr cachedattr))
+ (puthash sym attr compat--file-has-changed-p--hash-table))))
+
(provide 'compat-29)
;;; compat-29.el ends here
diff --git a/compat.texi b/compat.texi
index 35a78ca7b5..064533a3f2 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2510,6 +2510,23 @@ non-@code{nil}, it ends in a slash.
@xref{Directory Names,,,elisp}.
@end defun
+@c copied from lispref/files.texi
+@defun file-has-changed-p file &optional tag
+This function returns non-@code{nil} if the time stamp of
+@var{filename} has changed since the last call. When called for the
+first time for some @var{filename}, it records the last modification
+time and size of the file, and returns non-@code{nil} when
+@var{filename} exists. Thereafter, when called for the same
+@var{filename}, it compares the current time stamp and size with the
+recorded ones, and returns non-@code{nil} only if either the time
+stamp or the size (or both) are different. This is useful when a Lisp
+program wants to re-read a file whenever it changes. With an optional
+argument @var{tag}, which must be a symbol, the size and modification
+time comparisons are limited to calls with the same tag.
+
+@xref{File Attributes,,,elisp}.
+@end defun
+
@subsection Prefixed Definitions
- [elpa] externals/compat 2ee63f46b2 07/84: Make compat-font-lock dependency on compat-macs explicit, (continued)
- [elpa] externals/compat 2ee63f46b2 07/84: Make compat-font-lock dependency on compat-macs explicit, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 22b2634ada 06/84: Compile compat-macs before anything else, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 2e206a8304 21/84: Add prefixed plist-get from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e13ca90cd7 12/84: Rewrite legacy compat-test definitions, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e370f9b7e7 25/84: Add match-buffers from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 4710da5fa7 28/84: Add file-parent-directory from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat bb86f3aa3b 37/84: Simplify compat--generate-testable, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 282f2dc6a7 41/84: Call install-fn in compat--generate-testable, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 3f3f2e44d5 43/84: Split compat-insert-into-buffer into multiple tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 933d6fdf80 24/84: Add buffer-match-p from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 8d17ffdd88 29/84: Add file-has-changed-p from Emacs 29,
ELPA Syncer <=
- [elpa] externals/compat 252d33e897 31/84: Fix incompatible function calls in compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9e0eb5b72f 33/84: Add compat-declare-version to compat-29.el, ELPA Syncer, 2023/01/03
- [elpa] externals/compat fdae099b00 34/84: Move if-let and related function from subr-x to subr, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 6ac6ed2a99 36/84: Use make-symbol instead of gensym in function-alias-p tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ef5246cf55 38/84: Fix issues related to 'expect' tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0a84a7c219 48/84: Add add-display-text-property from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e6d279af18 14/84: Extend byte-compile-docstring-max-column to 100, ELPA Syncer, 2023/01/03
- [elpa] externals/compat c177ff5e83 17/84: Reuse ntake in take definition, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0de389aca6 19/84: Add string-equal-ignore-case from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ff331f6c29 22/84: Add prefixed plist-put from Emacs 29, ELPA Syncer, 2023/01/03