Mercurial > emacs
comparison lisp/ls-lisp.el @ 50767:5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
(ls-lisp-format): Use it.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 01 May 2003 11:16:21 +0000 |
parents | 850f7b918635 |
children | 01a94a546935 |
comparison
equal
deleted
inserted
replaced
50766:fc9cb527333d | 50767:5e248d2a95e7 |
---|---|
62 ;; Modified by Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>, mainly | 62 ;; Modified by Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>, mainly |
63 ;; to support many more ls options, "platform emulation", hooks for | 63 ;; to support many more ls options, "platform emulation", hooks for |
64 ;; external symbolic link support and more robust sorting. | 64 ;; external symbolic link support and more robust sorting. |
65 | 65 |
66 ;;; Code: | 66 ;;; Code: |
67 | |
68 (eval-when-compile (require 'cl)) | |
67 | 69 |
68 (defgroup ls-lisp nil | 70 (defgroup ls-lisp nil |
69 "Emulate the ls program completely in Emacs Lisp." | 71 "Emulate the ls program completely in Emacs Lisp." |
70 :version "21.1" | 72 :version "21.1" |
71 :group 'dired) | 73 :group 'dired) |
531 (let* ((gid (nth 3 file-attr)) | 533 (let* ((gid (nth 3 file-attr)) |
532 (group (user-login-name gid))) | 534 (group (user-login-name gid))) |
533 (if group | 535 (if group |
534 (format " %-8s" group) | 536 (format " %-8s" group) |
535 (format " %-8d" gid)))))) | 537 (format " %-8d" gid)))))) |
536 (format (if (floatp file-size) " %8.0f" " %8d") file-size) | 538 (ls-lisp-format-file-size file-size (memq ?h switches)) |
537 " " | 539 " " |
538 (ls-lisp-format-time file-attr time-index now) | 540 (ls-lisp-format-time file-attr time-index now) |
539 " " | 541 " " |
540 file-name | 542 file-name |
541 (if (stringp file-type) ; is a symbolic link | 543 (if (stringp file-type) ; is a symbolic link |
585 (if locale "%m-%d %H:%M" (nth 0 ls-lisp-format-time-list)) | 587 (if locale "%m-%d %H:%M" (nth 0 ls-lisp-format-time-list)) |
586 (if locale "%Y-%m-%d " (nth 1 ls-lisp-format-time-list))) | 588 (if locale "%Y-%m-%d " (nth 1 ls-lisp-format-time-list))) |
587 time)) | 589 time)) |
588 (error "Unk 0 0000")))) | 590 (error "Unk 0 0000")))) |
589 | 591 |
592 (defun ls-lisp-format-file-size (file-size human-readable) | |
593 (if (or (not human-readable) | |
594 (< file-size 1024)) | |
595 (format (if (floatp file-size) " %8.0f" " %8d") file-size) | |
596 (do ((file-size (/ file-size 1024.0) (/ file-size 1024.0)) | |
597 ;; kilo, mega, giga, tera, peta, exa | |
598 (post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes))) | |
599 ((< file-size 1024) (format " %7.0f%s" file-size (car post-fixes)))))) | |
600 | |
590 (provide 'ls-lisp) | 601 (provide 'ls-lisp) |
591 | 602 |
592 ;;; ls-lisp.el ends here | 603 ;;; ls-lisp.el ends here |