From 51e51ce2df46fc0c6e17a97e74b00366bb9c09d8 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Fri, 18 Feb 2022 08:37:33 -0800 Subject: [PATCH] Handle multiple directory separators in gnus-search results Try to treat the file names more like file names, less like strings to massage. * lisp/gnus/gnus-search.el (gnus-search-indexed-parse-output): Use `expand-file-name' to collapse separators and generally canonicalize the name. Use `file-name-split' and joining instead of regexp munging. --- lisp/gnus/gnus-search.el | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el index 27b07e36556..4ca873eeec9 100644 --- a/lisp/gnus/gnus-search.el +++ b/lisp/gnus/gnus-search.el @@ -1393,18 +1393,27 @@ Returns a list of [group article score] vectors." (when (and f-name (file-readable-p f-name) (null (file-directory-p f-name))) - (setq group - (replace-regexp-in-string - "[/\\]" "." - (replace-regexp-in-string - "/?\\(cur\\|new\\|tmp\\)?/\\'" "" + ;; `expand-file-name' canoncalizes the file name, + ;; specifically collapsing multiple consecutive directory + ;; separators. + (setq f-name (expand-file-name f-name) + group + (delete + "" ; forward slash at root leaves an empty string + (file-name-split (replace-regexp-in-string - "\\`\\." "" - (string-remove-prefix + "\\`\\." "" ; why do we do this? + (string-remove-prefix prefix (file-name-directory f-name)) - nil t) - nil t) - nil t)) + nil t))) + ;; Turn file name segments into a Gnus group name. + group (mapconcat + #'identity + (if (member (car (last group)) + '("new" "tmp" "cur")) + (nbutlast group) + group) + ".")) (setq article (file-name-nondirectory f-name) article ;; TODO: Provide a cleaner way of producing final -- 2.39.5