perf(lib): memoize doom-system-* functions
This commit is contained in:
parent
3239ab8b2e
commit
c540f1b515
1 changed files with 50 additions and 44 deletions
|
@ -3,23 +3,26 @@
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-system-distro ()
|
(defun doom-system-distro ()
|
||||||
"Return a symbol representing the installed distro."
|
"Return a symbol representing the installed distro."
|
||||||
(cond (IS-WINDOWS 'windows)
|
;; REVIEW Use `with-memoization' when 27.x support is dropped
|
||||||
(IS-MAC 'macos)
|
(or (get 'doom-system-distro 'cached-value)
|
||||||
((and (file-exists-p "/etc/os-release")
|
(put 'doom-system-distro 'cached-value
|
||||||
(with-temp-buffer
|
(cond ((featurep :os 'windows) 'windows)
|
||||||
(insert-file-contents "/etc/os-release")
|
((featurep :os 'macos) 'macos)
|
||||||
(when (re-search-forward "^ID=\"?\\([^\"\n]+\\)\"?" nil t)
|
((and (file-exists-p "/etc/os-release")
|
||||||
(intern (downcase (match-string 1)))))))
|
(with-temp-buffer
|
||||||
;; A few redundancies in case os-release fails us
|
(insert-file-contents "/etc/os-release")
|
||||||
((file-exists-p "/etc/debian_version")
|
(when (re-search-forward "^ID=\"?\\([^\"\n]+\\)\"?" nil t)
|
||||||
'debian)
|
(intern (downcase (match-string 1)))))))
|
||||||
((executable-find "nixos-version")
|
;; A few redundancies in case os-release fails us
|
||||||
'nixos)
|
((file-exists-p "/etc/debian_version")
|
||||||
((and (or (file-exists-p "/etc/config.scm")
|
'debian)
|
||||||
(file-directory-p "/run/current-system"))
|
((executable-find "nixos-version")
|
||||||
(executable-find "guix"))
|
'nixos)
|
||||||
'guix)
|
((and (or (file-exists-p "/etc/config.scm")
|
||||||
('linux)))
|
(file-directory-p "/run/current-system"))
|
||||||
|
(executable-find "guix"))
|
||||||
|
'guix)
|
||||||
|
('linux)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-system-distro-version ()
|
(defun doom-system-distro-version ()
|
||||||
|
@ -49,33 +52,36 @@
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-system-distro-icon ()
|
(defun doom-system-distro-icon ()
|
||||||
"Display icon for the installed distro."
|
"Display icon for the installed distro."
|
||||||
(propertize
|
;; REVIEW Use `with-memoization' when 27.x support is dropped
|
||||||
(pcase (doom-system-distro)
|
(or (get 'doom-system-distro-icon 'cached-value)
|
||||||
(`windows (all-the-icons-faicon "windows"))
|
(put 'doom-system-distro-icon 'cached-value
|
||||||
(`macos (all-the-icons-faicon "apple"))
|
(propertize
|
||||||
(`arch "\uF303")
|
(pcase (doom-system-distro)
|
||||||
(`debian "\uF306")
|
(`windows (all-the-icons-faicon "windows"))
|
||||||
(`raspbian "\uF315")
|
(`macos (all-the-icons-faicon "apple"))
|
||||||
(`ubuntu "\uF31b")
|
(`arch "\uF303")
|
||||||
(`elementary "\uF309")
|
(`debian "\uF306")
|
||||||
(`fedora "\uF30a")
|
(`raspbian "\uF315")
|
||||||
(`coreos "\uF305")
|
(`ubuntu "\uF31b")
|
||||||
(`gentoo "\uF30d")
|
(`elementary "\uF309")
|
||||||
(`mageia "\uF310")
|
(`fedora "\uF30a")
|
||||||
(`centos "\uF304")
|
(`coreos "\uF305")
|
||||||
((or `opensuse `tumbleweed) "\uF314")
|
(`gentoo "\uF30d")
|
||||||
(`sabayon "\uF317")
|
(`mageia "\uF310")
|
||||||
(`slackware "\uF319")
|
(`centos "\uF304")
|
||||||
(`linuxmint "\uF30e")
|
((or `opensuse `tumbleweed) "\uF314")
|
||||||
(`alpine "\uF300")
|
(`sabayon "\uF317")
|
||||||
(`aosc "\uF301")
|
(`slackware "\uF319")
|
||||||
(`nixos "\uF313")
|
(`linuxmint "\uF30e")
|
||||||
(`devuan "\uF307")
|
(`alpine "\uF300")
|
||||||
(`manjaro "\uF312")
|
(`aosc "\uF301")
|
||||||
((or `void `artix) "\uF17c")
|
(`nixos "\uF313")
|
||||||
(_ (all-the-icons-faicon "linux")))
|
(`devuan "\uF307")
|
||||||
'face '(:height 1)
|
(`manjaro "\uF312")
|
||||||
'display '(raise 0)))
|
((or `void `artix) "\uF17c")
|
||||||
|
(_ (all-the-icons-faicon "linux")))
|
||||||
|
'face '(:height 1)
|
||||||
|
'display '(raise 0)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-system-cpus ()
|
(defun doom-system-cpus ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue