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))
(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)))
(when (null (assoc type xdg-mime-table))
(push (cons type (make-hash-table :test #'equal)) xdg-mime-table))
(if (let ((def (make-symbol "def"))
(table (cdr (assoc type xdg-mime-table))))
(not (eq (setq files (gethash subtype table def)) def)))
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)))))))