]> git.eshelyaron.com Git - emacs.git/commitdiff
Support more long time options in 'ls-lisp'
authorLin Sun <sunlin7@hotmail.com>
Mon, 8 Apr 2024 06:59:21 +0000 (06:59 +0000)
committerEshel Yaron <me@eshelyaron.com>
Wed, 10 Apr 2024 20:29:42 +0000 (22:29 +0200)
* lisp/ls-lisp.el (ls-lisp--sanitize-switches): Support '--time'
and '--sort=time'.  (Bug#70271)

* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug70271): New
test case.

(cherry picked from commit a4c766e057b9b05685433db010b6536148f29f1d)

lisp/ls-lisp.el
test/lisp/ls-lisp-tests.el

index d09b53b1cc3e0ed26238e8cb3cd46f158c6a9a07..ae4a43797f00daa5f0a1f51d75ef35c23b7c0a0f 100644 (file)
@@ -873,6 +873,7 @@ The l switch is assumed to be always present and cannot be turned off."
   (let ((lsflags '(("-a" . "--all")
                    ("-A" . "--almost-all")
                    ("-B" . "--ignore-backups")
+                   ("-c" . "--time=ctime")
                    ("-C" . "--color")
                    ("-F" . "--classify")
                    ("-G" . "--no-group")
@@ -883,7 +884,9 @@ The l switch is assumed to be always present and cannot be turned off."
                    ("-r" . "--reverse")
                    ("-R" . "--recursive")
                    ("-s" . "--size")
+                   ("-t" . "--sort=time")
                    ("-S" . "--sort.*[ \\\t]")
+                   ("-u" . "--time=atime")
                    (""   . "--group-directories-first")
                    (""   . "--author")
                    (""   . "--escape")
index 77046871ea7c567132bacb0e9de0de39986e7b20..81e3e163c9c719e807bac7de0ffcd07f616ef186 100644 (file)
 (require 'ls-lisp)
 (require 'dired)
 
+(ert-deftest ls-lisp-test-bug70271 ()
+  "Test for https://debbugs.gnu.org/70271 ."
+  (ert-with-temp-file
+   fpath
+   :suffix "bug70271"
+   (let* ((dir (file-name-directory fpath))
+          (attributes (file-attributes fpath))
+          (dired-find-subdir t)
+          ls-lisp-use-insert-directory-program buf ts)
+     (unwind-protect
+         (progn
+           (setq ts (file-attribute-access-time attributes))
+           (with-current-buffer
+               (dired-internal-noselect dir "-la --time=ctime")
+             (setq buf (current-buffer)
+                   str (format-time-string "%H:%M" ts))
+             (should (search-forward-regexp str nil t))
+             (kill-buffer))
+           (setq ts (- (float-time) 60))
+           (set-file-times fpath ts)
+           (with-current-buffer
+               (dired-internal-noselect dir "-la --sort=time")
+             (setq buf (current-buffer)
+                   str (format-time-string "%H:%M" ts))
+             (should (search-forward-regexp str nil t))
+             (kill-buffer))
+           (setq ts (- (float-time) 120))
+           (set-file-times fpath ts)
+           (with-current-buffer
+               (dired-internal-noselect dir "-la --time=atime")
+             (setq buf (current-buffer)
+                   str (format-time-string "%H:%M" ts))
+             (should (search-forward-regexp str nil t))
+             (kill-buffer)))
+       (when (buffer-live-p buf) (kill-buffer buf))))))
+
 (ert-deftest ls-lisp-test-bug27762 ()
   "Test for https://debbugs.gnu.org/27762 ."
   (let* ((dir source-directory)