From 11b7cd7ebe19aafcc5566fad224bee114925d24e Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 15 Oct 2025 09:31:05 -0400 Subject: [PATCH] (xdg-mime-apps): Restore corner case and simplify * lisp/xdg.el (xdg-mime-apps): Return nil if that's what the table holds, like we did before commit f60fc1287d49. Consolidate the three (assoc type xdg-mime-table) and shrink the scope of `files`. --- lisp/xdg.el | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lisp/xdg.el b/lisp/xdg.el index 1e1495f8c7f..56a5efa7720 100644 --- a/lisp/xdg.el +++ b/lisp/xdg.el @@ -372,8 +372,7 @@ an absolute file name of a readable file. Results are cached in `xdg-mime-table'." (pcase-let ((`(,type ,subtype) (split-string mime "/")) (xdg-data-dirs (xdg-data-dirs)) - (caches (xdg-mime-apps-files)) - (files ())) + (caches (xdg-mime-apps-files))) (let ((mtim1 (get 'xdg-mime-table 'mtime)) (mtim2 (cl-loop for f in caches when (file-readable-p f) maximize (float-time @@ -382,21 +381,21 @@ Results are cached in `xdg-mime-table'." ;; If one of the MIME/Desktop cache files has been modified: (when (or (null mtim1) (time-less-p mtim1 mtim2)) (setq xdg-mime-table nil))) - (when (null (assoc type xdg-mime-table)) - (push (cons type (make-hash-table :test #'equal)) xdg-mime-table)) - (if (let ((table (cdr (assoc type xdg-mime-table)))) - (and (hash-table-contains-p subtype table) - (setq files (gethash subtype table)))) - files - (and files (setq files nil)) - (let ((dirs (mapcar (lambda (dir) (expand-file-name "applications" dir)) - (cons (xdg-data-home) xdg-data-dirs)))) - ;; Not being particular about desktop IDs - (dolist (f (nreverse (xdg-mime-collect-associations mime caches))) - (push (locate-file f dirs) files)) - (when files - (put 'xdg-mime-table 'mtime (current-time))) - (puthash subtype (delq nil files) (cdr (assoc type xdg-mime-table))))))) + (let ((table (cdr (or (assoc type xdg-mime-table) + (let ((p (cons type (make-hash-table :test #'equal)))) + (push p xdg-mime-table) + p))))) + (if (hash-table-contains-p subtype table) + (gethash subtype table) + (let ((files ()) + (dirs (mapcar (lambda (dir) (expand-file-name "applications" dir)) + (cons (xdg-data-home) xdg-data-dirs)))) + ;; Not being particular about desktop IDs + (dolist (f (nreverse (xdg-mime-collect-associations mime caches))) + (push (locate-file f dirs) files)) + (when files + (put 'xdg-mime-table 'mtime (current-time))) + (puthash subtype (delq nil files) table)))))) ;; Unofficial extension from systemd.