Emacs: Refactored my/quelpa-upgrade-all-maybe.

This commit is contained in:
tastytea 2020-02-27 05:26:05 +01:00
parent 25eeb3f159
commit 6c7b8a46b7
4 changed files with 19 additions and 25 deletions

View File

@ -1,6 +1,6 @@
;;; global-variables.el --- Set some global variables. -*- lexical-binding: t; -*- ;;; global-variables.el --- Set some global variables. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-02-26T22:56:29+0100> ;; Time-stamp: <2020-02-27T05:14:19+0100>
;;; Commentary: ;;; Commentary:
;; * Set `slow-computer'. ;; * Set `slow-computer'.
@ -65,11 +65,6 @@
"Returns the version of clangd as float." "Returns the version of clangd as float."
(string-to-number (string-to-number
(nth 2 (split-string (shell-command-to-string "clangd --version"))))) (nth 2 (split-string (shell-command-to-string "clangd --version")))))
(defun my/file-last-modification (file)
"Return the absolute time FILE was last modified in seconds."
(time-to-seconds
(file-attribute-modification-time (file-attributes file))))
) )
(provide 'basics/global-variables) (provide 'basics/global-variables)

View File

@ -1,6 +1,6 @@
;;; package-management.el --- Initialize package management. -*- lexical-binding: t; -*- ;;; package-management.el --- Initialize package management. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-02-27T03:13:02+0100> ;; Time-stamp: <2020-02-27T05:25:23+0100>
;;; Commentary: ;;; Commentary:
;; * Set up package sources and their priorities. ;; * Set up package sources and their priorities.
@ -38,9 +38,6 @@
(eval-when-compile (eval-when-compile
(require 'use-package)) (require 'use-package))
;; We need `my/file-last-modification', it needs `use-package'.
(require 'basics/global-variables)
;; Always install packages if they are not present. ;; Always install packages if they are not present.
(use-package use-package (use-package use-package
:custom (use-package-always-ensure t) :custom (use-package-always-ensure t)
@ -80,20 +77,21 @@
(quelpa-update-melpa-p nil) (quelpa-update-melpa-p nil)
(quelpa-checkout-melpa-p nil)) (quelpa-checkout-melpa-p nil))
:config :config
(defvar my/quelpa-last-upgrade-file (defun my/quelpa-upgrade-all-maybe (&optional force)
(concat user-emacs-directory "quelpa/last_upgrade") "Run `quelpa-upgrade-all' if at least 7 days passed since the last run.
"File with the timestamp of the last quelpa upgrade.") With prefix FORCE, packages will all be upgraded discarding local changes."
(interactive "P")
(let ((timestamp (expand-file-name "last_upgrade" quelpa-dir))
(days 7))
(when (or (not (file-exists-p timestamp))
(> (- (time-to-seconds) ; Current time - file modification time.
(time-to-seconds (nth 5 (file-attributes timestamp))))
(* 60 60 24 days)))
(let ((current-prefix-arg force))
(quelpa-upgrade-all))
(write-region "" nil timestamp))))
(defun my/quelpa-maybe-upgrade () :hook (after-init . my/quelpa-upgrade-all-maybe)
"Upgrade quelpa packages if the last upgrade was > 7 days ago."
(when (or (not (file-exists-p my/quelpa-last-upgrade-file))
(> (- (time-to-seconds)
(my/file-last-modification my/quelpa-last-upgrade-file))
(* 60 60 24 7)))
(quelpa-upgrade-all)
(write-region "" nil my/quelpa-last-upgrade-file)))
:hook (after-init . my/quelpa-maybe-upgrade)
) )
;; Use :quelpa in use-package configurations. ;; Use :quelpa in use-package configurations.

View File

@ -1,6 +1,6 @@
;;; init.el --- tastytea's Emacs init file. -*- lexical-binding: t; -*- ;;; init.el --- tastytea's Emacs init file. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-02-26T23:31:10+0100> ;; Time-stamp: <2020-02-27T05:16:37+0100>
;;; Commentary: ;;; Commentary:
;; Requires at least Emacs 26. Most of it will probably work with Emacs 24 and ;; Requires at least Emacs 26. Most of it will probably work with Emacs 24 and
@ -12,6 +12,7 @@
(push (concat user-emacs-directory "init.d") load-path) (push (concat user-emacs-directory "init.d") load-path)
(require 'basics/package-management) (require 'basics/package-management)
(require 'basics/global-variables) (require 'basics/global-variables)
;; Set garbage collection threshold to 100 MiB (or 20 MiB) to speed up init. ;; Set garbage collection threshold to 100 MiB (or 20 MiB) to speed up init.

View File

@ -1,2 +1,2 @@
127.0.0.1:51313 10169 127.0.0.1:51313 880
phahw2ohVoh0oopheish7IVie9desh8aequeenei3uo8wahShe%thuadaeNa4ieh phahw2ohVoh0oopheish7IVie9desh8aequeenei3uo8wahShe%thuadaeNa4ieh