bug#81612: 32.0.50; setting marks in dired-hidden directories creates garbled output

Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
On Thu, 13 Aug 2026 08:30:36 +0000 Daniel Clemente <[email protected]> wrote:

> Reproduce in "emacs -Q":
> 1. C-x C-f /etc RET to open a folder in dired
> 2. Press $ to hide the folder. It contracts everything into a line
> 3. Press m to mark the files at point
>
> Result: screen text is garbled. You see a long line like
>   /etc:*  drwxr-xr-x 222 root  root      20480 Aug 12 17:39 .*
> drwxr-xr-x  24 root  root       4096 Aug  5 01:49 ..*  -rw-r--r--   1
> root  root      12823 Dec 23  2024 a2ps.cfg*  -rw-r--r--   1 root
> root       2502 Dec 23  2024 a2ps-site.cfg*  drwxr-xr-x   3 root  root
>       4096 Aug  5 17:52 acpi*  -rw-r--r--   1 root  root       3981
> May  7  2025 adduser.conf*  -rw-r--r--   1 root  root       2981 Feb
> 28  2023 adduser.conf.update-old*  -rw-r--r--   1 root  root
> 46 […]
>
>
> I think it's because dired-get-filename does this unhide+hide:
>     (when hidden
>       (dired-unhide-subdir))
>     (save-excursion
>       (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
>  (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
>     (when hidden
>       (dired-hide-subdir 1))
>
>
> But dired-hide-subdir says it may move the point:
> (defun dired-hide-subdir (arg)
>   "Hide or unhide the current subdirectory and move to next directory. […]"
> […]
> (goto-char (cdr elt))
> […]
> )
>
>
> With this it works:
>     (when hidden
>       (save-excursion (dired-hide-subdir 1)))
>
> Patch:
>
> diff --git a/lisp/dired.el b/lisp/dired.el
> index ac12bf42565..019cf9d8fc4 100644
> --- a/lisp/dired.el
> +++ b/lisp/dired.el
> @@ -3297,7 +3297,7 @@ dired-get-filename
>        (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
>           (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
>      (when hidden
> -      (dired-hide-subdir 1))
> +      (save-excursion (dired-hide-subdir 1)))
>      ;; nil if no file on this line, but no-error-if-not-filep is t:
>      (if (setq file (and p1 p2 (buffer-substring p1 p2)))
>         (progn

A similar patch was posted in bug#80964 (see
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=80964#20).  However, from
the discussion in that thread it seems this kind of fix leaves a number
of unresolved issues concerning marked entries in hidden subdirs.  So
for the problem reported in that bug it was decided to apply the more
targeted fix of preventing certain marking commands from applying to
entries in hidden subdirs.  That fix was limited to complex marking
commands involving `dired-mark-if', but your report suggests the same
kind of fix should apply to the simple marking command `m' (and the same
goes for `d', flagging for deletion).  According to my initial testing,
the attached patch does this, and avoids the garbled output.

Steve Berman
(unnamed) (text/x-patch, 732 B)
diff --git a/lisp/dired.el b/lisp/dired.el
index ac12bf42565..fbdbec803c6 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -4637,6 +4637,7 @@ dired-mark-files-in-region
       (while (and (< (point) end) (dired-between-files))
 	(forward-line 1))
       (if (and (not (looking-at-p dired-re-dot))
+               (not (dired--hidden-p))
 	       (dired-get-filename nil t))
 	  (progn
 	    (delete-char 1)
@@ -4681,6 +4682,7 @@ dired-mark
        (prefix-numeric-value arg)
        (lambda ()
          (when (or (not (looking-at-p dired-re-dot))
+                   (not (dired--hidden-p))
                    ;; Don't skip symlinks to ".", "..", etc.
                    (save-excursion
                      (re-search-forward
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.