;;; Code:
-;;;###autoload
(defgroup ls-lisp nil
"Emulate the ls program completely in Emacs Lisp."
:version "21.1"
:type 'boolean
:group 'ls-lisp)
+(defcustom ls-lisp-format-time-list
+ '("%b %e %H:%M"
+ "%b %e %Y")
+ "*List of `format-time-string' specs to display file time stamps.
+They are used whenever a locale is not specified to use instead.
+
+Syntax: (EARLY-TIME-FORMAT OLD-TIME-FORMAT)
+
+The EARLY-TIME-FORMAT is used if file has been modified within the
+current year. The OLD-TIME-FORMAT is used for older files. To use ISO
+8601 dates, you could set:
+
+\(setq ls-lisp-format-time-list
+ '(\"%Y-%m-%d %H:%M\"
+ \"%Y-%m-%d \"))"
+ :type '(list (string :tag "Early time format")
+ (string :tag "Old time format"))
+ :group 'ls-lisp)
+
+(defvar original-insert-directory nil
+ "This holds the original function definition of `insert-directory'.")
+
;; Remember the original insert-directory function
(or (featurep 'ls-lisp) ; FJW: unless this file is being reloaded!
- (fset 'original-insert-directory (symbol-function 'insert-directory)))
+ (setq original-insert-directory (symbol-function 'insert-directory)))
;; This stub is to allow ls-lisp to parse symbolic links via another
;; library such as w32-symlinks.el from
-;; http://centaur.qmw.ac.uk/Emacs/:
+;; http://centaur.maths.qmw.ac.uk/Emacs/:
(defun ls-lisp-parse-symlink (file-name)
"This stub may be redefined to parse FILE-NAME as a symlink.
It should return nil or the link target as a string."
to match file names. It does not support all `ls' switches -- those
that work are: A a c i r S s t u U X g G B C R and F partly."
(if ls-lisp-use-insert-directory-program
- (original-insert-directory file switches wildcard full-directory-p)
+ (funcall original-insert-directory
+ file switches wildcard full-directory-p)
;; We need the directory in order to find the right handler.
(let ((handler (find-file-name-handler (expand-file-name file)
'insert-directory)))
(if (memq ?B switches) (setq wildcard "[^~]\\'")))
(ls-lisp-insert-directory
file switches (ls-lisp-time-index switches)
- wildcard full-directory-p)))))
+ wildcard full-directory-p)
+ ;; Try to insert the amount of free space.
+ (save-excursion
+ (goto-char (point-min))
+ ;; First find the line to put it on.
+ (when (re-search-forward "^total" nil t)
+ (let ((available (get-free-disk-space ".")))
+ (when available
+ ;; Replace "total" with "total used", to avoid confusion.
+ (replace-match "total used in directory")
+ (end-of-line)
+ (insert " available " available)))))))))
(defun ls-lisp-insert-directory
(file switches time-index wildcard full-directory-p)
(setq locale nil))
(format-time-string
(if (and (<= past-cutoff diff) (<= diff 0))
- (if locale "%m-%d %H:%M" "%b %e %H:%M")
- (if locale "%Y-%m-%d " "%b %e %Y"))
+ (if locale "%m-%d %H:%M" (nth 0 ls-lisp-format-time-list))
+ (if locale "%Y-%m-%d " (nth 1 ls-lisp-format-time-list)))
time))
(error "Unk 0 0000"))))