all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: john muhl <jm@pub.pink>
Cc: 41493@debbugs.gnu.org, Matthieu Lemerre <racin@free.fr>,
	Stefan Kangas <stefan@marxist.se>
Subject: bug#41493: 26.3; Error in MPC directory browser
Date: Wed, 01 Jan 2025 13:22:01 -0500	[thread overview]
Message-ID: <jwvcyh62zje.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87ed1npsbm.fsf@pub.pink> (john muhl's message of "Tue, 31 Dec 2024 13:26:21 -0600")

[-- Attachment #1: Type: text/plain, Size: 2236 bytes --]

Hi John,

> The attached patch fixes it for me. The cause seems to be that the
> returned alist for a directory browser has entries for (directory
> ...) and (Last-Modified ...) and the code was only getting rid of
> the former only. That leftover (Last-Modified ...) would then trip
> up the assert in mpc--proc-alist-to-alists when it checks with
> mpc--proc-alist-to-alists-starters.
[...]
> diff --git a/lisp/mpc.el b/lisp/mpc.el
> index 4317fece6fc..05ef546f884 100644
> --- a/lisp/mpc.el
> +++ b/lisp/mpc.el
> @@ -644,9 +644,10 @@ mpc-cmd-find
>                          (mpc-proc-buf-to-alist
>                           (mpc-proc-cmd (list "listallinfo" value)))))
>                     (mpc--proc-alist-to-alists
> -                    ;; Strip away the `directory' entries.
> +                    ;; Strip away the `directory' & `Last-Modified' entries.
>                      (delq nil (mapcar (lambda (pair)
> -                                        (if (eq (car pair) 'directory)
> +                                        (if (or (eq (car pair) 'directory)
> +                                                (eq (car pair) 'Last-Modified))
>                                              nil pair))
>                                        pairs)))))
>                  ((string-match "|" (symbol-name tag))

Hmm... IIUC the output we receive is a list of pairs made of sublists of
the form either:

    (directory . <...>)
    (Last-Modified . <...>)

or

    (file . <...>)
    (Last-Modified . <...>)
    (Format . <...>)
    (Title . <...>)
    ...

IIUC when I wrote the code there were no such `Last-Modified` entries.

We're interested in extracting a list of the files (where each file is
represented by its alist), so I just stripped away all the `directory`
entries and that was it.  But now that `directory` can be followed by
info about that directory (currently only `Last-Modified`), we should
arguably be more careful to also remove everything between
`directory` and the next `file` or `directory`.

So I think the patch below is "more robust".
WDYT?
I also think it's a good opportunity to add some comments/docstrings
because it took me a while to understand what this was trying to do.


        Stefan

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mpc.patch --]
[-- Type: text/x-diff, Size: 1871 bytes --]

diff --git a/lisp/mpc.el b/lisp/mpc.el
index ad11007f064..ca450fd959a 100644
--- a/lisp/mpc.el
+++ b/lisp/mpc.el
@@ -312,11 +312,11 @@ mpc--proc-alist-to-alists-starters
 (defun mpc--proc-alist-to-alists (alist)
   (cl-assert (or (null alist)
               (memq (caar alist) mpc--proc-alist-to-alists-starters)))
-  (let ((starter (caar alist))
+  (let (;; (starter (caar alist))
         (alists ())
         tmp)
     (dolist (pair alist)
-      (when (eq (car pair) starter)
+      (when (memq (car pair) mpc--proc-alist-to-alists-starters)
         (if tmp (push (nreverse tmp) alists))
         (setq tmp ()))
       (push pair tmp))
@@ -638,15 +638,14 @@ mpc-cmd-find
                  (mpc-proc-buf-to-alists
                   (mpc-proc-cmd (list "search" "any" value))))
                 ((eq tag 'Directory)
-                 (let ((pairs
-                        (mpc-proc-buf-to-alist
+                 (let ((entries
+                        (mpc-proc-buf-to-alists
                          (mpc-proc-cmd (list "listallinfo" value)))))
-                   (mpc--proc-alist-to-alists
-                    ;; Strip away the `directory' entries.
-                    (delq nil (mapcar (lambda (pair)
-                                        (if (eq (car pair) 'directory)
-                                            nil pair))
-                                      pairs)))))
+                   ;; Strip away the `directory' entries.
+                   (delq nil (mapcar (lambda (entry)
+                                       (if (eq (caar entry) 'directory)
+                                           nil entry))
+                                     entries))))
                 ((string-match "|" (symbol-name tag))
                  (add-to-list 'mpc--find-memoize-union-tags tag)
                  (let ((tag1 (intern (substring (symbol-name tag)

  reply	other threads:[~2025-01-01 18:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-23 21:02 bug#41493: 26.3; Error in MPC directory browser Matthieu Lemerre
2020-08-13  1:22 ` Stefan Kangas
2024-12-31 19:26   ` john muhl
2025-01-01 18:22     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2025-01-02  3:27       ` john muhl
2025-01-03 18:28       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvcyh62zje.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=41493@debbugs.gnu.org \
    --cc=jm@pub.pink \
    --cc=monnier@iro.umontreal.ca \
    --cc=racin@free.fr \
    --cc=stefan@marxist.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.