A time-stamp file is created by default.

Instead of the user having the option to add a time-stamp to the
init-file, a file is created for this purpose only.
This commit is contained in:
larstvei 2014-01-04 18:59:29 +01:00
parent 67d780f9af
commit dd1e475d99
2 changed files with 47 additions and 46 deletions

43
init.el
View File

@ -39,27 +39,28 @@ PACKAGE is installed and the current version is deleted."
(defvar do-package-update-on-init t) (defvar do-package-update-on-init t)
(require 'time-stamp) (require 'time-stamp)
;; Open the 'user-init-file' and write any changes. ;; Open the package-last-update-file
(with-temp-file user-init-file (with-temp-file package-last-update-file
;; Insert it's original content's. (if (file-exists-p package-last-update-file)
(insert-file-contents user-init-file) (progn
(forward-line time-stamp-line-limit) ;; Insert it's original content's.
(let ((bound (point))) (insert-file-contents package-last-update-file)
(goto-char (point-min)) (let ((start (re-search-forward time-stamp-start nil t))
;; We search for the time-stamp. (end (re-search-forward time-stamp-end nil t)))
(let ((start (re-search-forward time-stamp-start bound t)) (when (and start end)
(end (re-search-forward time-stamp-end bound t))) ;; Assuming we have found a time-stamp, we check determine if it's
(when (and start end) ;; time to update.
;; Assuming we have found a time-stamp, we check determine if it's (setq do-package-update-on-init
;; time to update. (<= days-between-updates
(setq do-package-update-on-init (days-between
(<= days-between-updates (current-time-string)
(days-between (buffer-substring-no-properties start end))))
(current-time-string) ;; Remember to update the time-stamp.
(buffer-substring-no-properties start end)))) (when do-package-update-on-init
;; Remember to update the time-stamp. (time-stamp)))))
(when do-package-update-on-init ;; If no such file exists it is created with a time-stamp.
(time-stamp)))))) (insert "Time-stamp: <>")
(time-stamp)))
(when do-package-update-on-init (when do-package-update-on-init
(package-refresh-contents)) (package-refresh-contents))

View File

@ -96,34 +96,34 @@
The tricky part is figuring out when the last time the Emacs was updated! The tricky part is figuring out when the last time the Emacs was updated!
Here is a hacky way of doing it, using [[http://www.gnu.org/software/emacs/manual/html_node/emacs/Time-Stamps.html][time-stamps]]. By adding a Here is a hacky way of doing it, using [[http://www.gnu.org/software/emacs/manual/html_node/emacs/Time-Stamps.html][time-stamps]]. By adding a
time-stamp to the init file, we can search for it and determine wither or time-stamp to the a file, we can determine wither or not to do an
not to do an update. After that we must run the =time-stamp=-function to update. After that we must run the =time-stamp=-function to update the
update the time-stamp. Note that if there is no time-stamp in the time-stamp.
init-file then packages will be updated every time you start Emacs.
#+BEGIN_SRC emacs-lisp :tangle yes #+BEGIN_SRC emacs-lisp :tangle yes
(require 'time-stamp) (require 'time-stamp)
;; Open the 'user-init-file' and write any changes. ;; Open the package-last-update-file
(with-temp-file user-init-file (with-temp-file package-last-update-file
;; Insert it's original content's. (if (file-exists-p package-last-update-file)
(insert-file-contents user-init-file) (progn
(forward-line time-stamp-line-limit) ;; Insert it's original content's.
(let ((bound (point))) (insert-file-contents package-last-update-file)
(goto-char (point-min)) (let ((start (re-search-forward time-stamp-start nil t))
;; We search for the time-stamp. (end (re-search-forward time-stamp-end nil t)))
(let ((start (re-search-forward time-stamp-start bound t)) (when (and start end)
(end (re-search-forward time-stamp-end bound t))) ;; Assuming we have found a time-stamp, we check determine if it's
(when (and start end) ;; time to update.
;; Assuming we have found a time-stamp, we check determine if it's (setq do-package-update-on-init
;; time to update. (<= days-between-updates
(setq do-package-update-on-init (days-between
(<= days-between-updates (current-time-string)
(days-between (buffer-substring-no-properties start end))))
(current-time-string) ;; Remember to update the time-stamp.
(buffer-substring-no-properties start end)))) (when do-package-update-on-init
;; Remember to update the time-stamp. (time-stamp)))))
(when do-package-update-on-init ;; If no such file exists it is created with a time-stamp.
(time-stamp)))))) (insert "Time-stamp: <>")
(time-stamp)))
#+END_SRC #+END_SRC
Now we can use the function above to make sure packages are installed and Now we can use the function above to make sure packages are installed and