emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/no-ls-lisp-advice fe67c36cd9b 5/5: (dired): Remove `ls-lisp` adv


From: Stefan Monnier
Subject: scratch/no-ls-lisp-advice fe67c36cd9b 5/5: (dired): Remove `ls-lisp` advice
Date: Sat, 9 Dec 2023 23:59:03 -0500 (EST)

branch: scratch/no-ls-lisp-advice
commit fe67c36cd9bb2967e0c2eca3d4a31c0950130eb7
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    (dired): Remove `ls-lisp` advice
    
    `ls-lisp` used to advise `dired` because `dired-insert-directory`
    blindly used `insert-directory-program` (together with a shell)
    in order to implement the "directory wildcard" expansion.
    
    * lisp/dired.el (dired-insert-directory): Make the "directory wildcard"
    code obey `files--use-insert-directory-program-p`, using
    `file-expand-wildcards`.
    
    * lisp/ls-lisp.el (ls-lisp--dired, ls-lisp-unload-function): Delete funs.
    (dired): Don't advise any more.
---
 lisp/dired.el   | 17 ++++++++++-------
 lisp/ls-lisp.el | 36 ------------------------------------
 2 files changed, 10 insertions(+), 43 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index c11b107213b..ace4bbf5776 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1696,7 +1696,7 @@ see `dired-use-ls-dired' for more details.")
     ;; Expand directory wildcards and fill file-list.
     (let ((dir-wildcard (and (null file-list) wildcard
                              (insert-directory-wildcard-in-dir-p dir))))
-      (cond (dir-wildcard
+      (cond ((and dir-wildcard (files--use-insert-directory-program-p))
              (setq switches (concat "-d " switches))
              (let* ((default-directory (car dir-wildcard))
                     (script (format "%s %s %s"
@@ -1723,12 +1723,15 @@ see `dired-use-ls-dired' for more details.")
             ;; month names; but this should not be necessary any
             ;; more, with the new value of
             ;; `directory-listing-before-filename-regexp'.
-            (file-list
-            (dolist (f file-list)
-              (let ((beg (point)))
-                (insert-directory f switches nil nil)
-                ;; Re-align fields, if necessary.
-                (dired-align-file beg (point)))))
+            ((or file-list dir-wildcard)
+            (let ((default-directory
+                   (or (car dir-wildcard) default-directory)))
+              (dolist (f (or file-list
+                             (file-expand-wildcards (cdr dir-wildcard))))
+                (let ((beg (point)))
+                  (insert-directory f switches nil nil)
+                  ;; Re-align fields, if necessary.
+                  (dired-align-file beg (point))))))
            (t
              (insert-directory dir switches wildcard (not wildcard))))
       ;; Quote certain characters, unless ls quoted them for us.
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 141d1f32c09..c0a52d76a25 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -449,36 +449,6 @@ not contain `d', so that a full listing is expected."
                       "Directory doesn't exist or is inaccessible"
                       file))))))
 
-(declare-function dired-read-dir-and-switches "dired" (str))
-(declare-function dired-goto-next-file "dired" ())
-
-(defun ls-lisp--dired (orig-fun dir-or-list &optional switches)
-  (interactive (dired-read-dir-and-switches ""))
-  (unless dir-or-list
-    (setq dir-or-list default-directory))
-  (if (consp dir-or-list)
-      (funcall orig-fun dir-or-list switches)
-    (let ((dir-wildcard (insert-directory-wildcard-in-dir-p
-                         (expand-file-name dir-or-list))))
-      (if (not dir-wildcard)
-          (funcall orig-fun dir-or-list switches)
-        (let* ((default-directory (car dir-wildcard))
-               (files (file-expand-wildcards (cdr dir-wildcard)))
-               (dir (car dir-wildcard)))
-          (if files
-              (let ((inhibit-read-only t)
-                    (buf
-                     (apply orig-fun (nconc (list dir) files) (and switches 
(list switches)))))
-                (with-current-buffer buf
-                  (save-excursion
-                    (goto-char (point-min))
-                    (dired-goto-next-file)
-                    (forward-line 0)
-                    (insert "  wildcard " (cdr dir-wildcard) "\n"))))
-            (user-error "No files matching wildcard")))))))
-
-(advice-add 'dired :around #'ls-lisp--dired)
-
 (defun ls-lisp-sanitize (file-alist)
   "Sanitize the elements in FILE-ALIST.
 Fixes any elements in the alist for directory entries whose file
@@ -866,12 +836,6 @@ All ls time options, namely c, t and u, are handled."
              file-size)
     (format " %7s" (file-size-human-readable file-size))))
 
-(defun ls-lisp-unload-function ()
-  "Unload ls-lisp library."
-  (advice-remove 'dired #'ls-lisp--dired)
-  ;; Continue standard unloading.
-  nil)
-
 (defun ls-lisp--sanitize-switches (switches)
   "Convert long options of GNU \"ls\" to their short form.
 Conversion is done only for flags supported by ls-lisp.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]