diff options
| author | Stefan Monnier | 2025-10-15 09:31:05 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2025-10-15 09:31:05 -0400 |
| commit | 11b7cd7ebe19aafcc5566fad224bee114925d24e (patch) | |
| tree | ac3ee39b51b9de752526759daf211e9c3d5531e8 | |
| parent | eeaa9421479de0ceefbbb90a7b7bd750c3e00f4b (diff) | |
| download | emacs-11b7cd7ebe19aafcc5566fad224bee114925d24e.tar.gz emacs-11b7cd7ebe19aafcc5566fad224bee114925d24e.zip | |
(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`.
| -rw-r--r-- | lisp/xdg.el | 33 |
1 files 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. | |||
| 372 | Results are cached in `xdg-mime-table'." | 372 | Results are cached in `xdg-mime-table'." |
| 373 | (pcase-let ((`(,type ,subtype) (split-string mime "/")) | 373 | (pcase-let ((`(,type ,subtype) (split-string mime "/")) |
| 374 | (xdg-data-dirs (xdg-data-dirs)) | 374 | (xdg-data-dirs (xdg-data-dirs)) |
| 375 | (caches (xdg-mime-apps-files)) | 375 | (caches (xdg-mime-apps-files))) |
| 376 | (files ())) | ||
| 377 | (let ((mtim1 (get 'xdg-mime-table 'mtime)) | 376 | (let ((mtim1 (get 'xdg-mime-table 'mtime)) |
| 378 | (mtim2 (cl-loop for f in caches when (file-readable-p f) | 377 | (mtim2 (cl-loop for f in caches when (file-readable-p f) |
| 379 | maximize (float-time | 378 | maximize (float-time |
| @@ -382,21 +381,21 @@ Results are cached in `xdg-mime-table'." | |||
| 382 | ;; If one of the MIME/Desktop cache files has been modified: | 381 | ;; If one of the MIME/Desktop cache files has been modified: |
| 383 | (when (or (null mtim1) (time-less-p mtim1 mtim2)) | 382 | (when (or (null mtim1) (time-less-p mtim1 mtim2)) |
| 384 | (setq xdg-mime-table nil))) | 383 | (setq xdg-mime-table nil))) |
| 385 | (when (null (assoc type xdg-mime-table)) | 384 | (let ((table (cdr (or (assoc type xdg-mime-table) |
| 386 | (push (cons type (make-hash-table :test #'equal)) xdg-mime-table)) | 385 | (let ((p (cons type (make-hash-table :test #'equal)))) |
| 387 | (if (let ((table (cdr (assoc type xdg-mime-table)))) | 386 | (push p xdg-mime-table) |
| 388 | (and (hash-table-contains-p subtype table) | 387 | p))))) |
| 389 | (setq files (gethash subtype table)))) | 388 | (if (hash-table-contains-p subtype table) |
| 390 | files | 389 | (gethash subtype table) |
| 391 | (and files (setq files nil)) | 390 | (let ((files ()) |
| 392 | (let ((dirs (mapcar (lambda (dir) (expand-file-name "applications" dir)) | 391 | (dirs (mapcar (lambda (dir) (expand-file-name "applications" dir)) |
| 393 | (cons (xdg-data-home) xdg-data-dirs)))) | 392 | (cons (xdg-data-home) xdg-data-dirs)))) |
| 394 | ;; Not being particular about desktop IDs | 393 | ;; Not being particular about desktop IDs |
| 395 | (dolist (f (nreverse (xdg-mime-collect-associations mime caches))) | 394 | (dolist (f (nreverse (xdg-mime-collect-associations mime caches))) |
| 396 | (push (locate-file f dirs) files)) | 395 | (push (locate-file f dirs) files)) |
| 397 | (when files | 396 | (when files |
| 398 | (put 'xdg-mime-table 'mtime (current-time))) | 397 | (put 'xdg-mime-table 'mtime (current-time))) |
| 399 | (puthash subtype (delq nil files) (cdr (assoc type xdg-mime-table))))))) | 398 | (puthash subtype (delq nil files) table)))))) |
| 400 | 399 | ||
| 401 | 400 | ||
| 402 | ;; Unofficial extension from systemd. | 401 | ;; Unofficial extension from systemd. |