Function: xdg-mime-apps
xdg-mime-apps is a byte-compiled function defined in xdg.el.gz.
Signature
(xdg-mime-apps MIME)
Documentation
Return list of desktop files associated with MIME, otherwise nil.
The list is in order of descending priority, and each element is
an absolute file name of a readable file.
Results are cached in xdg-mime-table.
Source Code
;; Defined in /usr/src/emacs/lisp/xdg.el.gz
(defun xdg-mime-apps (mime)
"Return list of desktop files associated with MIME, otherwise nil.
The list is in order of descending priority, and each element is
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)))
(let ((mtim1 (get 'xdg-mime-table 'mtime))
(mtim2 (cl-loop for f in caches when (file-readable-p f)
maximize (float-time
(file-attribute-modification-time
(file-attributes f))))))
;; 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)))
(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))))))