Subject: Re: bug#66697: 30.0.50; [PATCH] desktop-save-mode with expiring remote buffers

From: Manuel Giraud <[email-masked]>
Date: Tue, 24 Oct 2023 15:18:47 +0200

Eli Zaretskii <[email-masked]> writes:

[...]

> Sounds right, but don't you get byte-compiler warnings about
> desktop-files-not-to-save not being known?

I did not get a warning about desktop-files-not-to-save but I get one
about shadowing dired-directory.  So I fixed the patch with this new
one.
>From 6c32d99a9f1e8c813550c5a2540ef41ea2d59844 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Tue, 24 Oct 2023 14:51:04 +0200
Subject: [PATCH] Fix desktop-save on remote dired (bug#66697)

Do not gather "misc data" for dired buffer not meant to be
desktop saved.

lisp/dired.el (dired-desktop-save-p): New function to test if
`dired-directory' should be desktop saved.
(dired-desktop-buffer-misc-data): Use it.
---
 lisp/dired.el | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index cc8c74839b9..4337480e2b5 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -4875,22 +4875,30 @@ dired-dnd-handle-file
 (eval-when-compile (require 'desktop))
 (declare-function desktop-file-name "desktop" (filename dirname))
 
+(defun dired-desktop-save-p ()
+  "Should `dired-directory' be desktop saved?"
+  (if (consp dired-directory)
+      (not (string-match-p desktop-files-not-to-save (car dired-directory)))
+    (not (string-match-p desktop-files-not-to-save dired-directory))))
+
 (defun dired-desktop-buffer-misc-data (dirname)
   "Auxiliary information to be saved in desktop file."
-  (cons
-   ;; Value of `dired-directory'.
-   (if (consp dired-directory)
-       ;; Directory name followed by list of files.
-       (cons (desktop-file-name (car dired-directory) dirname)
-             (cdr dired-directory))
-     ;; Directory name, optionally with shell wildcard.
-     (desktop-file-name dired-directory dirname))
-   ;; Subdirectories in `dired-subdir-alist'.
-   (cdr
-    (nreverse
-     (mapcar
-      (lambda (f) (desktop-file-name (car f) dirname))
-      dired-subdir-alist)))))
+  (when (and (stringp desktop-files-not-to-save)
+             (dired-desktop-save-p))
+    (cons
+     ;; Value of `dired-directory'.
+     (if (consp dired-directory)
+         ;; Directory name followed by list of files.
+         (cons (desktop-file-name (car dired-directory) dirname)
+               (cdr dired-directory))
+       ;; Directory name, optionally with shell wildcard.
+       (desktop-file-name dired-directory dirname))
+     ;; Subdirectories in `dired-subdir-alist'.
+     (cdr
+      (nreverse
+       (mapcar
+        (lambda (f) (desktop-file-name (car f) dirname))
+        dired-subdir-alist))))))
 
 (defun dired-restore-desktop-buffer (_file-name
                                      _buffer-name
-- 
2.42.0

-- 
Manuel Giraud