1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-03 08:30:09 +00:00

(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.
This commit is contained in:
Stefan Monnier 2023-12-09 23:57:35 -05:00
parent 29957969e5
commit fe67c36cd9
2 changed files with 10 additions and 43 deletions

View File

@ -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.

View File

@ -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.