aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2016-03-04 13:39:07 +0000
committerLars Ingebrigtsen2016-03-04 15:33:38 +0000
commit2d5b20f68c194e7fec7b9602935fd95149e9b7c6 (patch)
tree4dc995ec41e242f4f0c2d431bcd129a5e2c40410
parent484967796755051c4045cdcc26b0d3d129cc72ad (diff)
downloademacs-2d5b20f68c194e7fec7b9602935fd95149e9b7c6.tar.gz
emacs-2d5b20f68c194e7fec7b9602935fd95149e9b7c6.zip
Add accessors for `file-attributes'
* doc/lispref/files.texi (File Attributes): Mention the accessors. * lisp/files.el (file-attribute-type) (file-attribute-link-number, file-attribute-user-id) (file-attribute-group-id, file-attribute-access-time) (file-attribute-modification-time) (file-attribute-change-time, file-attribute-size) (file-attribute-modes, file-attribute-inode-number) (file-attribute-device-number): New functions. * src/dired.c (Ffile_attributes): Mention the accessors (bug#22890).
-rw-r--r--doc/lispref/files.texi82
-rw-r--r--etc/NEWS10
-rw-r--r--lisp/files.el72
-rw-r--r--src/dired.c8
4 files changed, 136 insertions, 36 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 6b7ee19d5f3..8a6cb7beaad 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -1195,73 +1195,83 @@ the default, but we plan to change that, so you should specify a
1195non-@code{nil} value for @var{id-format} if you use the returned 1195non-@code{nil} value for @var{id-format} if you use the returned
1196@acronym{UID} or @acronym{GID}. 1196@acronym{UID} or @acronym{GID}.
1197 1197
1198Accessor functions are provided to access the elements in this list.
1199The accessors are mentioned along with the descriptions of the
1200elements below.
1201
1198The elements of the list, in order, are: 1202The elements of the list, in order, are:
1199 1203
1200@enumerate 0 1204@enumerate 0
1201@item 1205@item
1202@code{t} for a directory, a string for a symbolic link (the name 1206@code{t} for a directory, a string for a symbolic link (the name
1203linked to), or @code{nil} for a text file. 1207linked to), or @code{nil} for a text file
1208(@code{file-attribute-type}).
1204 1209
1205@c Wordy so as to prevent an overfull hbox. --rjc 15mar92 1210@c Wordy so as to prevent an overfull hbox. --rjc 15mar92
1206@item 1211@item
1207The number of names the file has. Alternate names, also known as hard 1212The number of names the file has (@code{file-attribute-link-number}).
1208links, can be created by using the @code{add-name-to-file} function 1213Alternate names, also known as hard links, can be created by using the
1209(@pxref{Changing Files}). 1214@code{add-name-to-file} function (@pxref{Changing Files}).
1210 1215
1211@item 1216@item
1212The file's @acronym{UID}, normally as a string. However, if it does 1217The file's @acronym{UID}, normally as a string
1213not correspond to a named user, the value is a number. 1218(@code{file-attribute-user-id}). However, if it does not correspond
1219to a named user, the value is a number.
1214 1220
1215@item 1221@item
1216The file's @acronym{GID}, likewise. 1222The file's @acronym{GID}, likewise (@code{file-attribute-group-id}).
1217 1223
1218@item 1224@item
1219The time of last access, as a list of four integers @code{(@var{sec-high} 1225The time of last access, as a list of four integers
1220@var{sec-low} @var{microsec} @var{picosec})}. (This is similar to the 1226@code{(@var{sec-high} @var{sec-low} @var{microsec} @var{picosec})}
1221value of @code{current-time}; see @ref{Time of Day}.) Note that on 1227(@code{file-attribute-access-time}). (This is similar to the value of
1222some FAT-based filesystems, only the date of last access is recorded, 1228@code{current-time}; see @ref{Time of Day}.) Note that on some
1223so this time will always hold the midnight of the day of last access. 1229FAT-based filesystems, only the date of last access is recorded, so
1230this time will always hold the midnight of the day of last access.
1224 1231
1225@cindex modification time of file 1232@cindex modification time of file
1226@item 1233@item
1227The time of last modification as a list of four integers (as above). 1234The time of last modification as a list of four integers (as above)
1228This is the last time when the file's contents were modified. 1235(@code{file-attribute-modification-time}). This is the last time when
1236the file's contents were modified.
1229 1237
1230@item 1238@item
1231The time of last status change as a list of four integers (as above). 1239The time of last status change as a list of four integers (as above)
1232This is the time of the last change to the file's access mode bits, 1240(code{file-attribute-status-change-time}). This is the time of the
1233its owner and group, and other information recorded in the filesystem 1241last change to the file's access mode bits, its owner and group, and
1234for the file, beyond the file's contents. 1242other information recorded in the filesystem for the file, beyond the
1243file's contents.
1235 1244
1236@item 1245@item
1237The size of the file in bytes. This is floating point if the size is 1246The size of the file in bytes (@code{file-attribute-size}). This is
1238too large to fit in a Lisp integer. 1247floating point if the size is too large to fit in a Lisp integer.
1239 1248
1240@item 1249@item
1241The file's modes, as a string of ten letters or dashes, 1250The file's modes, as a string of ten letters or dashes, as in
1242as in @samp{ls -l}. 1251@samp{ls -l} (@code{file-attribute-modes}).
1243 1252
1244@item 1253@item
1245An unspecified value, present for backward compatibility. 1254An unspecified value, present for backward compatibility.
1246 1255
1247@item 1256@item
1248The file's inode number. If possible, this is an integer. If the 1257The file's inode number (@code{file-attribute-inode-number}). If
1249inode number is too large to be represented as an integer in Emacs 1258possible, this is an integer. If the inode number is too large to be
1250Lisp but dividing it by @math{2^{16}} yields a representable integer, 1259represented as an integer in Emacs Lisp but dividing it by
1251then the value has the 1260@math{2^{16}} yields a representable integer, then the value has the
1252form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16 1261form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16
1253bits. If the inode number is too wide for even that, the value is of the form 1262bits. If the inode number is too wide for even that, the value is of
1254@code{(@var{high} @var{middle} . @var{low})}, where @code{high} holds 1263the form @code{(@var{high} @var{middle} . @var{low})}, where
1255the high bits, @var{middle} the middle 24 bits, and @var{low} the low 1264@code{high} holds the high bits, @var{middle} the middle 24 bits, and
125616 bits. 1265@var{low} the low 16 bits.
1257 1266
1258@item 1267@item
1259The filesystem number of the device that the file is on. Depending on 1268The filesystem number of the device that the file is on
1260the magnitude of the value, this can be either an integer or a cons 1269@code{file-attribute-device-number}). Depending on the magnitude of
1261cell, in the same manner as the inode number. This element and the 1270the value, this can be either an integer or a cons cell, in the same
1262file's inode number together give enough information to distinguish 1271manner as the inode number. This element and the file's inode number
1263any two files on the system---no two files can have the same values 1272together give enough information to distinguish any two files on the
1264for both of these numbers. 1273system---no two files can have the same values for both of these
1274numbers.
1265@end enumerate 1275@end enumerate
1266 1276
1267For example, here are the file attributes for @file{files.texi}: 1277For example, here are the file attributes for @file{files.texi}:
diff --git a/etc/NEWS b/etc/NEWS
index d7e1b839895..b29d460b19a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -40,6 +40,16 @@ erc-emacs-build-time.
40 40
41* Changes in Emacs 25.2 41* Changes in Emacs 25.2
42 42
43+++
44** A number of accessors for the value returned by `file-attributes'
45has been added. They are: `file-attribute-type',
46`file-attribute-link-number', `file-attribute-user-id',
47`file-attribute-group-id', `file-attribute-access-time',
48`file-attribute-modification-time',
49`file-attribute-status-change-time', `file-attribute-size',
50`file-attribute-modes', `file-attribute-inode-number', and
51`file-attribute-device-number'
52
43--- 53---
44** `align-regexp' has a separate history for its interactive argument 54** `align-regexp' has a separate history for its interactive argument
45`align-regexp' no longer shares its history with all other 55`align-regexp' no longer shares its history with all other
diff --git a/lisp/files.el b/lisp/files.el
index aca7b3593d9..c892ab4e219 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7083,6 +7083,78 @@ Otherwise, trash FILENAME using the freedesktop.org conventions,
7083 (let ((delete-by-moving-to-trash nil)) 7083 (let ((delete-by-moving-to-trash nil))
7084 (rename-file fn new-fn))))))))) 7084 (rename-file fn new-fn)))))))))
7085 7085
7086(defsubst file-attribute-type (attributes)
7087 "The type field in ATTRIBUTES returned by `file-attribute'.
7088The value is either t for directory, string (name linked to) for
7089symbolic link, or nil."
7090 (nth 0 attributes))
7091
7092(defsubst file-attribute-link-number (attributes)
7093 "Return the number of links in ATTRIBUTES returned by `file-attribute'."
7094 (nth 1 attributes))
7095
7096(defsubst file-attribute-user-id (attributes)
7097 "The UID field in ATTRIBUTES returned by `file-attribute'.
7098This is either a string or a number. If a string value cannot be
7099looked up, a numeric value, either an integer or a float, is
7100returned."
7101 (ntf 2 attributes))
7102
7103(defsubst file-attribute-group-id (attributes)
7104 "The GID field in ATTRIBUTES returned by `file-attribute'.
7105This is either a string or a number. If a string value cannot be
7106looked up, a numeric value, either an integer or a float, is
7107returned."
7108 (ntf 3 attributes))
7109
7110(defsubst file-attribute-access-time (attributes)
7111 "The last access time in ATTRIBUTES returned by `file-attribute'.
7112This a list of integers (HIGH LOW USEC PSEC) in the same style
7113as (current-time)."
7114 (ntf 4 attributes))
7115
7116(defsubst file-attribute-modification-time (attributes)
7117 "The modification time in ATTRIBUTES returned by `file-attribute'.
7118This is the time of the last change to the file's contents, and
7119is a list of integers (HIGH LOW USEC PSEC) in the same style
7120as (current-time)."
7121 (ntf 5 attributes))
7122
7123(defsubst file-attribute-status-change-time (attributes)
7124 "The status modification time in ATTRIBUTES returned by `file-attribute'.
7125This is the time of last change to the file's attributes: owner
7126and group, access mode bits, etc, and is a list of integers (HIGH
7127LOW USEC PSEC) in the same style as (current-time)."
7128 (ntf 6 attributes))
7129
7130(defsubst file-attribute-size (attributes)
7131 "The size (in bytes) in ATTRIBUTES returned by `file-attribute'.
7132This is a floating point number if the size is too large for an integer."
7133 (ntf 7 attributes))
7134
7135(defsubst file-attribute-modes (attributes)
7136 "The file modes in ATTRIBUTES returned by `file-attribute'.
7137This is a string of ten letters or dashes as in ls -l."
7138 (ntf 8 attributes))
7139
7140(defsubst file-attribute-inode-number (attributes)
7141 "The inode number in ATTRIBUTES returned by `file-attribute'.
7142If it is larger than what an Emacs integer can hold, this is of
7143the form (HIGH . LOW): first the high bits, then the low 16 bits.
7144If even HIGH is too large for an Emacs integer, this is instead
7145of the form (HIGH MIDDLE . LOW): first the high bits, then the
7146middle 24 bits, and finally the low 16 bits."
7147 (ntf 10 attributes))
7148
7149(defsubst file-attribute-device-number (attributes)
7150 "The file system device number in ATTRIBUTES returned by `file-attribute'.
7151If it is larger than what an Emacs integer can hold, this is of
7152the form (HIGH . LOW): first the high bits, then the low 16 bits.
7153If even HIGH is too large for an Emacs integer, this is instead
7154of the form (HIGH MIDDLE . LOW): first the high bits, then the
7155middle 24 bits, and finally the low 16 bits."
7156 (ntf 11 attributes))
7157
7086 7158
7087(define-key ctl-x-map "\C-f" 'find-file) 7159(define-key ctl-x-map "\C-f" 'find-file)
7088(define-key ctl-x-map "\C-r" 'find-file-read-only) 7160(define-key ctl-x-map "\C-r" 'find-file-read-only)
diff --git a/src/dired.c b/src/dired.c
index 97fefaefffd..fd5f142d0b5 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -861,6 +861,14 @@ below) - valid values are `string' and `integer'. The latter is the
861default, but we plan to change that, so you should specify a non-nil value 861default, but we plan to change that, so you should specify a non-nil value
862for ID-FORMAT if you use the returned uid or gid. 862for ID-FORMAT if you use the returned uid or gid.
863 863
864To access the elements returned, the following access functions are
865provided: `file-attribute-type', `file-attribute-link-number',
866`file-attribute-user-id', `file-attribute-group-id',
867`file-attribute-access-time', `file-attribute-modification-time',
868`file-attribute-status-change-time', `file-attribute-size',
869`file-attribute-modes', `file-attribute-inode-number', and
870`file-attribute-device-number'.
871
864Elements of the attribute list are: 872Elements of the attribute list are:
865 0. t for directory, string (name linked to) for symbolic link, or nil. 873 0. t for directory, string (name linked to) for symbolic link, or nil.
866 1. Number of links to file. 874 1. Number of links to file.