diff options
| author | Eli Zaretskii | 2008-04-25 10:36:27 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2008-04-25 10:36:27 +0000 |
| commit | df3d23ee9bbc8c12dde798f54a46911f4956fece (patch) | |
| tree | 13550c85d777060b38227ed4f72a5a236852fd85 | |
| parent | 296fa7b4f64d85b76bcf467e7528e74ebe653000 (diff) | |
| download | emacs-df3d23ee9bbc8c12dde798f54a46911f4956fece.tar.gz emacs-df3d23ee9bbc8c12dde798f54a46911f4956fece.zip | |
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
(ls-lisp-gid-s-fmt, ls-lisp-filesize-d-fmt, ls-lisp-filesize-f-fmt): New
defvars.
(ls-lisp-insert-directory): Dynamically compute format specifiers for
displaying UID, GID, and file size, and store them in the above variables.
(ls-lisp-format): Use ls-lisp-filesize-f-fmt, ls-lisp-uid-s-fmt,
ls-lisp-uid-d-fmt, ls-lisp-gid-s-fmt, and ls-lisp-gid-d-fmt instead of
constant format strings.
(ls-lisp-format-file-size): Use ls-lisp-filesize-f-fmt and
ls-lisp-filesize-d-fmt instead of constant format strings.
| -rw-r--r-- | lisp/ChangeLog | 11 | ||||
| -rw-r--r-- | lisp/ls-lisp.el | 85 |
2 files changed, 84 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index da619ce06a3..253d0f37c5a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,6 +1,17 @@ | |||
| 1 | 2008-04-25 Eli Zaretskii <eliz@gnu.org> | 1 | 2008-04-25 Eli Zaretskii <eliz@gnu.org> |
| 2 | 2 | ||
| 3 | * ls-lisp.el (ls-lisp-format): Fix last change. | 3 | * ls-lisp.el (ls-lisp-format): Fix last change. |
| 4 | (ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt) | ||
| 5 | (ls-lisp-gid-s-fmt, ls-lisp-filesize-d-fmt) | ||
| 6 | (ls-lisp-filesize-f-fmt): New defvars. | ||
| 7 | (ls-lisp-insert-directory): Dynamically compute format specifiers | ||
| 8 | for displaying UID, GID, and file size, and store them in the | ||
| 9 | above variables. | ||
| 10 | (ls-lisp-format): Use ls-lisp-filesize-f-fmt, ls-lisp-uid-s-fmt, | ||
| 11 | ls-lisp-uid-d-fmt, ls-lisp-gid-s-fmt, and ls-lisp-gid-d-fmt | ||
| 12 | instead of constant format strings. | ||
| 13 | (ls-lisp-format-file-size): Use ls-lisp-filesize-f-fmt and | ||
| 14 | ls-lisp-filesize-d-fmt instead of constant format strings. | ||
| 4 | 15 | ||
| 5 | 2008-04-24 Nick Roberts <nickrob@snap.net.nz> | 16 | 2008-04-24 Nick Roberts <nickrob@snap.net.nz> |
| 6 | 17 | ||
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index e1e10531880..f1a05a6f8c8 100644 --- a/lisp/ls-lisp.el +++ b/lisp/ls-lisp.el | |||
| @@ -181,6 +181,19 @@ to fail to lign up, e.g. if month names are not all of the same length." | |||
| 181 | (defvar original-insert-directory nil | 181 | (defvar original-insert-directory nil |
| 182 | "This holds the original function definition of `insert-directory'.") | 182 | "This holds the original function definition of `insert-directory'.") |
| 183 | 183 | ||
| 184 | (defvar ls-lisp-uid-d-fmt "-%d" | ||
| 185 | "Format to display integer UIDs.") | ||
| 186 | (defvar ls-lisp-uid-s-fmt "-%s" | ||
| 187 | "Format to display user names.") | ||
| 188 | (defvar ls-lisp-gid-d-fmt "-%d" | ||
| 189 | "Format to display integer GIDs.") | ||
| 190 | (defvar ls-lisp-gid-s-fmt "-%s" | ||
| 191 | "Format to display user group names.") | ||
| 192 | (defvar ls-lisp-filesize-d-fmt "%d" | ||
| 193 | "Format to display integer file sizes.") | ||
| 194 | (defvar ls-lisp-filesize-f-fmt "%.0f" | ||
| 195 | "Format to display float file sizes.") | ||
| 196 | |||
| 184 | ;; Remember the original insert-directory function | 197 | ;; Remember the original insert-directory function |
| 185 | (or (featurep 'ls-lisp) ; FJW: unless this file is being reloaded! | 198 | (or (featurep 'ls-lisp) ; FJW: unless this file is being reloaded! |
| 186 | (setq original-insert-directory (symbol-function 'insert-directory))) | 199 | (setq original-insert-directory (symbol-function 'insert-directory))) |
| @@ -292,8 +305,12 @@ not contain `d', so that a full listing is expected." | |||
| 292 | 'string))) | 305 | 'string))) |
| 293 | (now (current-time)) | 306 | (now (current-time)) |
| 294 | (sum 0) | 307 | (sum 0) |
| 308 | (max-uid-len 0) | ||
| 309 | (max-gid-len 0) | ||
| 310 | (max-file-size 0) | ||
| 295 | ;; do all bindings here for speed | 311 | ;; do all bindings here for speed |
| 296 | total-line files elt short file-size fil attr) | 312 | total-line files elt short file-size fil attr |
| 313 | fuid fgid uid-len gid-len) | ||
| 297 | (cond ((memq ?A switches) | 314 | (cond ((memq ?A switches) |
| 298 | (setq file-alist | 315 | (setq file-alist |
| 299 | (ls-lisp-delete-matching "^\\.\\.?$" file-alist))) | 316 | (ls-lisp-delete-matching "^\\.\\.?$" file-alist))) |
| @@ -306,6 +323,38 @@ not contain `d', so that a full listing is expected." | |||
| 306 | (if (memq ?C switches) ; column (-C) format | 323 | (if (memq ?C switches) ; column (-C) format |
| 307 | (ls-lisp-column-format file-alist) | 324 | (ls-lisp-column-format file-alist) |
| 308 | (setq total-line (cons (point) (car-safe file-alist))) | 325 | (setq total-line (cons (point) (car-safe file-alist))) |
| 326 | ;; Find the appropriate format for displaying uid, gid, and | ||
| 327 | ;; file size, by finding the longest strings among all the | ||
| 328 | ;; files we are about to display. | ||
| 329 | (dolist (elt file-alist) | ||
| 330 | (setq attr (cdr elt) | ||
| 331 | fuid (nth 2 attr) | ||
| 332 | uid-len (length (if (stringp fuid) fuid (format "%d" fuid))) | ||
| 333 | fgid (nth 3 attr) | ||
| 334 | gid-len (length (if (stringp fgid) fgid (format "%d" fgid))) | ||
| 335 | file-size (nth 7 attr)) | ||
| 336 | (if (> uid-len max-uid-len) | ||
| 337 | (setq max-uid-len uid-len)) | ||
| 338 | (if (> gid-len max-gid-len) | ||
| 339 | (setq max-gid-len gid-len)) | ||
| 340 | (if (> file-size max-file-size) | ||
| 341 | (setq max-file-size file-size))) | ||
| 342 | (setq ls-lisp-uid-d-fmt (format " %%-%dd" max-uid-len)) | ||
| 343 | (setq ls-lisp-uid-s-fmt (format " %%-%ds" max-uid-len)) | ||
| 344 | (setq ls-lisp-gid-d-fmt (format " %%-%dd" max-gid-len)) | ||
| 345 | (setq ls-lisp-gid-s-fmt (format " %%-%ds" max-gid-len)) | ||
| 346 | (setq ls-lisp-filesize-d-fmt | ||
| 347 | (format " %%%dd" | ||
| 348 | (if (memq ?s switches) | ||
| 349 | (length (format "%.0f" | ||
| 350 | (fceiling (/ max-file-size 1024.0)))) | ||
| 351 | (length (format "%.0f" max-file-size))))) | ||
| 352 | (setq ls-lisp-filesize-f-fmt | ||
| 353 | (format " %%%d.0f" | ||
| 354 | (if (memq ?s switches) | ||
| 355 | (length (format "%.0f" | ||
| 356 | (fceiling (/ max-file-size 1024.0)))) | ||
| 357 | (length (format "%.0f" max-file-size))))) | ||
| 309 | (setq files file-alist) | 358 | (setq files file-alist) |
| 310 | (while files ; long (-l) format | 359 | (while files ; long (-l) format |
| 311 | (setq elt (car files) | 360 | (setq elt (car files) |
| @@ -555,10 +604,11 @@ SWITCHES, TIME-INDEX and NOW give the full switch list and time data." | |||
| 555 | (format " %18d " inode)))) | 604 | (format " %18d " inode)))) |
| 556 | ;; nil is treated like "" in concat | 605 | ;; nil is treated like "" in concat |
| 557 | (if (memq ?s switches) ; size in K | 606 | (if (memq ?s switches) ; size in K |
| 558 | (format " %4.0f" (fceiling (/ file-size 1024.0)))) | 607 | (format ls-lisp-filesize-f-fmt |
| 608 | (fceiling (/ file-size 1024.0)))) | ||
| 559 | drwxrwxrwx ; attribute string | 609 | drwxrwxrwx ; attribute string |
| 560 | (if (memq 'links ls-lisp-verbosity) | 610 | (if (memq 'links ls-lisp-verbosity) |
| 561 | (format " %3d" (nth 1 file-attr))) ; link count | 611 | (format "%3d" (nth 1 file-attr))) ; link count |
| 562 | ;; Numeric uid/gid are more confusing than helpful; | 612 | ;; Numeric uid/gid are more confusing than helpful; |
| 563 | ;; Emacs should be able to make strings of them. | 613 | ;; Emacs should be able to make strings of them. |
| 564 | ;; They tend to be bogus on non-UNIX platforms anyway so | 614 | ;; They tend to be bogus on non-UNIX platforms anyway so |
| @@ -566,12 +616,18 @@ SWITCHES, TIME-INDEX and NOW give the full switch list and time data." | |||
| 566 | (if (memq 'uid ls-lisp-verbosity) | 616 | (if (memq 'uid ls-lisp-verbosity) |
| 567 | ;; uid can be a sting or an integer | 617 | ;; uid can be a sting or an integer |
| 568 | (let ((uid (nth 2 file-attr))) | 618 | (let ((uid (nth 2 file-attr))) |
| 569 | (format (if (stringp uid) " %-8s" " %-8d") uid))) | 619 | (format (if (stringp uid) |
| 620 | ls-lisp-uid-s-fmt | ||
| 621 | ls-lisp-uid-d-fmt) | ||
| 622 | uid))) | ||
| 570 | (if (not (memq ?G switches)) ; GNU ls -- shows group by default | 623 | (if (not (memq ?G switches)) ; GNU ls -- shows group by default |
| 571 | (if (or (memq ?g switches) ; UNIX ls -- no group by default | 624 | (if (or (memq ?g switches) ; UNIX ls -- no group by default |
| 572 | (memq 'gid ls-lisp-verbosity)) | 625 | (memq 'gid ls-lisp-verbosity)) |
| 573 | (let ((gid (nth 3 file-attr))) | 626 | (let ((gid (nth 3 file-attr))) |
| 574 | (format (if (stringp gid) " %-8s" " %-8d") gid)))) | 627 | (format (if (stringp gid) |
| 628 | ls-lisp-gid-s-fmt | ||
| 629 | ls-lisp-gid-d-fmt) | ||
| 630 | gid)))) | ||
| 575 | (ls-lisp-format-file-size file-size (memq ?h switches)) | 631 | (ls-lisp-format-file-size file-size (memq ?h switches)) |
| 576 | " " | 632 | " " |
| 577 | (ls-lisp-format-time file-attr time-index now) | 633 | (ls-lisp-format-time file-attr time-index now) |
| @@ -631,13 +687,18 @@ All ls time options, namely c, t and u, are handled." | |||
| 631 | (error "Unk 0 0000")))) | 687 | (error "Unk 0 0000")))) |
| 632 | 688 | ||
| 633 | (defun ls-lisp-format-file-size (file-size human-readable) | 689 | (defun ls-lisp-format-file-size (file-size human-readable) |
| 634 | (if (or (not human-readable) | 690 | (if (not human-readable) |
| 635 | (< file-size 1024)) | 691 | (format (if (floatp file-size) |
| 636 | (format (if (floatp file-size) " %9.0f" " %9d") file-size) | 692 | ls-lisp-filesize-f-fmt |
| 637 | (do ((file-size (/ file-size 1024.0) (/ file-size 1024.0)) | 693 | ls-lisp-filesize-d-fmt) |
| 638 | ;; kilo, mega, giga, tera, peta, exa | 694 | file-size) |
| 639 | (post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes))) | 695 | (if (< file-size 1024) |
| 640 | ((< file-size 1024) (format " %8.0f%s" file-size (car post-fixes)))))) | 696 | (format " %4d" file-size) |
| 697 | (do ((file-size (/ file-size 1024.0) (/ file-size 1024.0)) | ||
| 698 | ;; kilo, mega, giga, tera, peta, exa | ||
| 699 | (post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes))) | ||
| 700 | ((< file-size 1024) | ||
| 701 | (format " %3.0f%s" file-size (car post-fixes))))))) | ||
| 641 | 702 | ||
| 642 | (provide 'ls-lisp) | 703 | (provide 'ls-lisp) |
| 643 | 704 | ||