diff options
| author | Lars Ingebrigtsen | 2016-03-04 13:39:07 +0000 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2016-03-04 15:33:38 +0000 |
| commit | 2d5b20f68c194e7fec7b9602935fd95149e9b7c6 (patch) | |
| tree | 4dc995ec41e242f4f0c2d431bcd129a5e2c40410 | |
| parent | 484967796755051c4045cdcc26b0d3d129cc72ad (diff) | |
| download | emacs-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.texi | 82 | ||||
| -rw-r--r-- | etc/NEWS | 10 | ||||
| -rw-r--r-- | lisp/files.el | 72 | ||||
| -rw-r--r-- | src/dired.c | 8 |
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 | |||
| 1195 | non-@code{nil} value for @var{id-format} if you use the returned | 1195 | non-@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 | ||
| 1198 | Accessor functions are provided to access the elements in this list. | ||
| 1199 | The accessors are mentioned along with the descriptions of the | ||
| 1200 | elements below. | ||
| 1201 | |||
| 1198 | The elements of the list, in order, are: | 1202 | The 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 |
| 1203 | linked to), or @code{nil} for a text file. | 1207 | linked 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 |
| 1207 | The number of names the file has. Alternate names, also known as hard | 1212 | The number of names the file has (@code{file-attribute-link-number}). |
| 1208 | links, can be created by using the @code{add-name-to-file} function | 1213 | Alternate 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 |
| 1212 | The file's @acronym{UID}, normally as a string. However, if it does | 1217 | The file's @acronym{UID}, normally as a string |
| 1213 | not correspond to a named user, the value is a number. | 1218 | (@code{file-attribute-user-id}). However, if it does not correspond |
| 1219 | to a named user, the value is a number. | ||
| 1214 | 1220 | ||
| 1215 | @item | 1221 | @item |
| 1216 | The file's @acronym{GID}, likewise. | 1222 | The file's @acronym{GID}, likewise (@code{file-attribute-group-id}). |
| 1217 | 1223 | ||
| 1218 | @item | 1224 | @item |
| 1219 | The time of last access, as a list of four integers @code{(@var{sec-high} | 1225 | The 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})} |
| 1221 | value 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 |
| 1222 | some FAT-based filesystems, only the date of last access is recorded, | 1228 | @code{current-time}; see @ref{Time of Day}.) Note that on some |
| 1223 | so this time will always hold the midnight of the day of last access. | 1229 | FAT-based filesystems, only the date of last access is recorded, so |
| 1230 | this 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 |
| 1227 | The time of last modification as a list of four integers (as above). | 1234 | The time of last modification as a list of four integers (as above) |
| 1228 | This is the last time when the file's contents were modified. | 1235 | (@code{file-attribute-modification-time}). This is the last time when |
| 1236 | the file's contents were modified. | ||
| 1229 | 1237 | ||
| 1230 | @item | 1238 | @item |
| 1231 | The time of last status change as a list of four integers (as above). | 1239 | The time of last status change as a list of four integers (as above) |
| 1232 | This 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 |
| 1233 | its owner and group, and other information recorded in the filesystem | 1241 | last change to the file's access mode bits, its owner and group, and |
| 1234 | for the file, beyond the file's contents. | 1242 | other information recorded in the filesystem for the file, beyond the |
| 1243 | file's contents. | ||
| 1235 | 1244 | ||
| 1236 | @item | 1245 | @item |
| 1237 | The size of the file in bytes. This is floating point if the size is | 1246 | The size of the file in bytes (@code{file-attribute-size}). This is |
| 1238 | too large to fit in a Lisp integer. | 1247 | floating point if the size is too large to fit in a Lisp integer. |
| 1239 | 1248 | ||
| 1240 | @item | 1249 | @item |
| 1241 | The file's modes, as a string of ten letters or dashes, | 1250 | The file's modes, as a string of ten letters or dashes, as in |
| 1242 | as in @samp{ls -l}. | 1251 | @samp{ls -l} (@code{file-attribute-modes}). |
| 1243 | 1252 | ||
| 1244 | @item | 1253 | @item |
| 1245 | An unspecified value, present for backward compatibility. | 1254 | An unspecified value, present for backward compatibility. |
| 1246 | 1255 | ||
| 1247 | @item | 1256 | @item |
| 1248 | The file's inode number. If possible, this is an integer. If the | 1257 | The file's inode number (@code{file-attribute-inode-number}). If |
| 1249 | inode number is too large to be represented as an integer in Emacs | 1258 | possible, this is an integer. If the inode number is too large to be |
| 1250 | Lisp but dividing it by @math{2^{16}} yields a representable integer, | 1259 | represented as an integer in Emacs Lisp but dividing it by |
| 1251 | then the value has the | 1260 | @math{2^{16}} yields a representable integer, then the value has the |
| 1252 | form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16 | 1261 | form @code{(@var{high} . @var{low})}, where @var{low} holds the low 16 |
| 1253 | bits. If the inode number is too wide for even that, the value is of the form | 1262 | bits. 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 | 1263 | the form @code{(@var{high} @var{middle} . @var{low})}, where |
| 1255 | the 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 |
| 1256 | 16 bits. | 1265 | @var{low} the low 16 bits. |
| 1257 | 1266 | ||
| 1258 | @item | 1267 | @item |
| 1259 | The filesystem number of the device that the file is on. Depending on | 1268 | The filesystem number of the device that the file is on |
| 1260 | the magnitude of the value, this can be either an integer or a cons | 1269 | @code{file-attribute-device-number}). Depending on the magnitude of |
| 1261 | cell, in the same manner as the inode number. This element and the | 1270 | the value, this can be either an integer or a cons cell, in the same |
| 1262 | file's inode number together give enough information to distinguish | 1271 | manner as the inode number. This element and the file's inode number |
| 1263 | any two files on the system---no two files can have the same values | 1272 | together give enough information to distinguish any two files on the |
| 1264 | for both of these numbers. | 1273 | system---no two files can have the same values for both of these |
| 1274 | numbers. | ||
| 1265 | @end enumerate | 1275 | @end enumerate |
| 1266 | 1276 | ||
| 1267 | For example, here are the file attributes for @file{files.texi}: | 1277 | For example, here are the file attributes for @file{files.texi}: |
| @@ -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' | ||
| 45 | has 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'. | ||
| 7088 | The value is either t for directory, string (name linked to) for | ||
| 7089 | symbolic 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'. | ||
| 7098 | This is either a string or a number. If a string value cannot be | ||
| 7099 | looked up, a numeric value, either an integer or a float, is | ||
| 7100 | returned." | ||
| 7101 | (ntf 2 attributes)) | ||
| 7102 | |||
| 7103 | (defsubst file-attribute-group-id (attributes) | ||
| 7104 | "The GID field in ATTRIBUTES returned by `file-attribute'. | ||
| 7105 | This is either a string or a number. If a string value cannot be | ||
| 7106 | looked up, a numeric value, either an integer or a float, is | ||
| 7107 | returned." | ||
| 7108 | (ntf 3 attributes)) | ||
| 7109 | |||
| 7110 | (defsubst file-attribute-access-time (attributes) | ||
| 7111 | "The last access time in ATTRIBUTES returned by `file-attribute'. | ||
| 7112 | This a list of integers (HIGH LOW USEC PSEC) in the same style | ||
| 7113 | as (current-time)." | ||
| 7114 | (ntf 4 attributes)) | ||
| 7115 | |||
| 7116 | (defsubst file-attribute-modification-time (attributes) | ||
| 7117 | "The modification time in ATTRIBUTES returned by `file-attribute'. | ||
| 7118 | This is the time of the last change to the file's contents, and | ||
| 7119 | is a list of integers (HIGH LOW USEC PSEC) in the same style | ||
| 7120 | as (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'. | ||
| 7125 | This is the time of last change to the file's attributes: owner | ||
| 7126 | and group, access mode bits, etc, and is a list of integers (HIGH | ||
| 7127 | LOW 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'. | ||
| 7132 | This 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'. | ||
| 7137 | This 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'. | ||
| 7142 | If it is larger than what an Emacs integer can hold, this is of | ||
| 7143 | the form (HIGH . LOW): first the high bits, then the low 16 bits. | ||
| 7144 | If even HIGH is too large for an Emacs integer, this is instead | ||
| 7145 | of the form (HIGH MIDDLE . LOW): first the high bits, then the | ||
| 7146 | middle 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'. | ||
| 7151 | If it is larger than what an Emacs integer can hold, this is of | ||
| 7152 | the form (HIGH . LOW): first the high bits, then the low 16 bits. | ||
| 7153 | If even HIGH is too large for an Emacs integer, this is instead | ||
| 7154 | of the form (HIGH MIDDLE . LOW): first the high bits, then the | ||
| 7155 | middle 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 | |||
| 861 | default, but we plan to change that, so you should specify a non-nil value | 861 | default, but we plan to change that, so you should specify a non-nil value |
| 862 | for ID-FORMAT if you use the returned uid or gid. | 862 | for ID-FORMAT if you use the returned uid or gid. |
| 863 | 863 | ||
| 864 | To access the elements returned, the following access functions are | ||
| 865 | provided: `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 | |||
| 864 | Elements of the attribute list are: | 872 | Elements 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. |