emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 8d4039b: file-attribute-collect: New defun


From: Tino Calancha
Subject: [Emacs-diffs] master 8d4039b: file-attribute-collect: New defun
Date: Wed, 17 Aug 2016 09:39:32 +0000 (UTC)

branch: master
commit 8d4039bcd69f0134fe3723b2bb3c921952e298c5
Author: Tino Calancha <address@hidden>
Commit: Tino Calancha <address@hidden>

    file-attribute-collect: New defun
    
    * lisp/files.el (file-attribute-collect):
    Return a sublist of the attributes returned by 'file-attributes'.
    Suggested by Ted Zlatanov in:
    
    http://lists.gnu.org/archive/html/emacs-devel/2016-07/msg01195.html
    ; * etc/NEWS: Mention this defun in NEWS.
---
 etc/NEWS      |    4 ++--
 lisp/files.el |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 8a13d52..0c561cc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -115,8 +115,8 @@ have been added.  They are: 'file-attribute-type',
 'file-attribute-group-id', 'file-attribute-access-time',
 'file-attribute-modification-time',
 'file-attribute-status-change-time', 'file-attribute-size',
-'file-attribute-modes', 'file-attribute-inode-number', and
-'file-attribute-device-number'.
+'file-attribute-modes', 'file-attribute-inode-number',
+'file-attribute-device-number' and 'file-attribute-collect'.
 
 +++
 ** The new function 'buffer-hash' computes a fast, non-consing hash of
diff --git a/lisp/files.el b/lisp/files.el
index aad9f75..b93cc79 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7225,6 +7225,26 @@ of the form (HIGH MIDDLE . LOW): first the high bits, 
then the
 middle 24 bits, and finally the low 16 bits."
   (nth 11 attributes))
 
+(defun file-attribute-collect (attributes &rest attr-names)
+  "Return a sublist of ATTRIBUTES returned by `file-attributes'.
+ATTR-NAMES are symbols with the selected attribute names.
+
+Valid attribute names are: type, link-number, user-id, group-id,
+access-time, modification-time, status-change-time, size, modes,
+inode-number and device-number."
+  (let ((all '(type link-number user-id group-id access-time
+               modification-time status-change-time
+               size modes inode-number device-number))
+        result)
+    (while attr-names
+      (let ((attr (pop attr-names)))
+        (if (memq attr all)
+            (push (funcall
+                   (intern (format "file-attribute-%s" (symbol-name attr)))
+                   attributes)
+                  result)
+          (error "Wrong attribute name '%S'" attr))))
+    (nreverse result)))
 
 (define-key ctl-x-map "\C-f" 'find-file)
 (define-key ctl-x-map "\C-r" 'find-file-read-only)



reply via email to

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