From 6a90e0ee324f6fd0efe8b0de2a82c8a8a09dd19d Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Sat, 11 Apr 2026 11:01:05 +0200 Subject: [PATCH] Handle 'dired' called with -Al switches (bug#80711) * lisp/dired.el (dired-internal-noselect): After reading in directory, check whether there was an 'ls' error instead of checking for file entries, since there may be none is the -Al switches (or just -l) were used. (dired--display-ls-error): Ensure the 'ls' error buffer is a live buffer. * lisp/files.el (insert-directory-clean): Ensure deletion of "//DIRED-OPTIONS//" line when using -Al switches (or just -l). --- lisp/dired.el | 18 +++++++----------- lisp/files.el | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lisp/dired.el b/lisp/dired.el index 353190347db..2f66753f230 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1456,16 +1456,12 @@ The return value is the target column for the file names." (let ((failed t)) (unwind-protect (progn (dired-readin) - ;; Check for file entries (they are listed below the - ;; directory name and (if present) wildcard lines). - (while (and (skip-syntax-forward "\s") - (looking-at "\\(.+:$\\|wildcard\\)")) - (forward-line)) - (unless (eobp) + (unless (and dired--ls-error-buffer + (get-buffer "*ls error*")) (setq failed nil))) - ;; No file entries indicates an `ls' error, and `dired-readin' - ;; can fail if parent directories are inaccessible. In either - ;; case don't leave the Dired buffer around. + ;; If either `dired-readin' failed (e.g. if parent directories + ;; are inaccessible) or `ls' errored, don't leave the Dired + ;; buffer around. (when failed (kill-buffer buffer) (setq buffer nil)))) @@ -4112,8 +4108,8 @@ See `%s' for other alternatives and more information.")) (search-backward "Warning (dired)"))))) (defun dired--display-ls-error () - "Pop up a buffer displaying the current `ls' error, if any." - (when dired--ls-error-buffer + "Pop up the buffer displaying the current `ls' error, if any." + (when (buffer-live-p dired--ls-error-buffer) (let* ((errwin (display-buffer dired--ls-error-buffer))) (fit-window-to-buffer errwin)) (setq dired--ls-error-buffer nil))) diff --git a/lisp/files.el b/lisp/files.el index e05a4b99497..15bcf3568a2 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -8340,7 +8340,7 @@ Valid wildcards are `*', `?', `[abc]' and `[a-z]'." ;; Take care of the case where the ls output contains a ;; "//DIRED-OPTIONS//"-line, but no "//DIRED//"-line ;; and we went one line too far back (see above). - (unless (bobp) (forward-line 1))) + (forward-line 1)) (if (let ((case-fold-search nil)) (looking-at "//DIRED-OPTIONS//")) (delete-region (point) (progn (forward-line 1) (point))))))