Created
October 25, 2011 05:03
-
-
Save kiwanami/1311358 to your computer and use it in GitHub Desktop.
e2wm:def-plugin-files-update-buffer.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun e2wm:format-byte-unit (size) | |
(cond ((null size) "NA") | |
((> size (* 1048576 4)) | |
(format "%s Mb" (e2wm:num (round (/ size 1048576))))) | |
((> size (* 1024 4)) | |
(format "%s Kb" (e2wm:num (round (/ size 1024))))) | |
(t | |
(format "%s bytes" (e2wm:num size))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun e2wm:def-plugin-files-update-buffer (dir) | |
(let* ((files | |
(e2wm:def-plugin-files-sort | |
(loop | |
for f in (directory-files-and-attributes dir) | |
for fn = (car f) | |
unless (or (member fn '(".." ".")) | |
(and e2wm:def-plugin-files-hide-hidden-files | |
(eq (aref fn 0) ?.))) | |
collect (list | |
;; 0:name, 1:dirp, 2:time, 3:size | |
;; 4:dirp-str, 5:size-str, 6:float-time | |
fn (cadr f) | |
(format-time-string "%Y/%m/%d %H:%M:%S" (nth 7 f)) | |
(nth 8 f) | |
(if (cadr f) "d" "f") | |
(if (nth 8 f) (format "%014d" (nth 8 f)) (make-string 14 ?\ )) | |
(float-time (nth 7 f)))) | |
e2wm:def-plugin-files-sort-key)) rows-file rows-time rows-size rows) | |
(loop for i in files | |
for fn = (substring (car i) 0) | |
for tm = (nth 2 i) for sz = (nth 3 i) | |
for type = (cadr i) | |
do | |
(push i rows) | |
(push | |
(e2wm:tp | |
(cond | |
((stringp type) (e2wm:rt fn 'e2wm:face-files-symlink)) | |
(type (e2wm:rt fn 'e2wm:face-files-directory)) | |
(t fn)) | |
'e2wm:file | |
(expand-file-name fn dir)) rows-file) | |
(push (nth 2 i) rows-time) | |
(push (e2wm:format-byte-unit (nth 3 i)) rows-size)) | |
(cond | |
((eq e2wm:def-plugin-files-sort-key 'name) | |
(e2wm:def-plugin-files-insert-by-name rows-file rows-time rows-size)) | |
((eq e2wm:def-plugin-files-sort-key 'time) | |
(e2wm:def-plugin-files-insert-by-time rows-file rows-time rows-size rows)) | |
((eq e2wm:def-plugin-files-sort-key 'size) | |
(e2wm:def-plugin-files-insert-by-size rows-file rows-time rows-size))) | |
(setq mode-line-format | |
'("-" mode-line-mule-info | |
" " mode-line-position "-%-")) | |
(let* ((win (get-buffer-window (current-buffer))) | |
(width (- (or (and win (window-width win)) 90) 7)) ; 9 <= num and ellipse "..." | |
(dirname (expand-file-name dir)) | |
(namelen (string-width dirname)) | |
(startcol (max 0 (- namelen width)))) | |
(setq header-line-format | |
(format "[%2i] %s%s" | |
(length files) (if (< 0 startcol) "..." "") | |
(truncate-string-to-width dirname namelen startcol)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment