mirror of
				https://github.com/larstvei/dot-emacs.git
				synced 2025-11-04 09:20:11 +00:00 
			
		
		
		
	Update packages every nth day! (Very hacky)
This commit is contained in:
		
							parent
							
								
									6f947ae1de
								
							
						
					
					
						commit
						4bf07b9509
					
				
							
								
								
									
										32
									
								
								init.el
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								init.el
									
									
									
									
									
								
							@ -35,7 +35,34 @@ PACKAGE is installed and the current version is deleted."
 | 
				
			|||||||
                         (package-desc-vers (cdr pkg-desc)))))
 | 
					                         (package-desc-vers (cdr pkg-desc)))))
 | 
				
			||||||
      (package-install package))))
 | 
					      (package-install package))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(package-refresh-contents)
 | 
					(defvar days-between-updates 1)
 | 
				
			||||||
 | 
					(defvar do-package-update-on-init t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(require 'time-stamp)
 | 
				
			||||||
 | 
					;; Open the 'user-init-file' and write any changes.
 | 
				
			||||||
 | 
					(with-temp-file user-init-file
 | 
				
			||||||
 | 
					  ;; Insert it's original content's.
 | 
				
			||||||
 | 
					  (insert-file-contents user-init-file)
 | 
				
			||||||
 | 
					  (forward-line time-stamp-line-limit)
 | 
				
			||||||
 | 
					  (let ((bound (point)))
 | 
				
			||||||
 | 
					    (goto-char (point-min))
 | 
				
			||||||
 | 
					    ;; We search for the time-stamp.
 | 
				
			||||||
 | 
					    (let ((start (re-search-forward time-stamp-start bound t))
 | 
				
			||||||
 | 
					          (end (re-search-forward time-stamp-end bound t)))
 | 
				
			||||||
 | 
					      (when (and start end)
 | 
				
			||||||
 | 
					        ;; Assuming we have found a time-stamp, we check determine if it's
 | 
				
			||||||
 | 
					        ;; time to update.
 | 
				
			||||||
 | 
					        (setq do-package-update-on-init
 | 
				
			||||||
 | 
					              (<= days-between-updates
 | 
				
			||||||
 | 
					                  (days-between
 | 
				
			||||||
 | 
					                   (current-time-string)
 | 
				
			||||||
 | 
					                   (buffer-substring-no-properties start end)))))))
 | 
				
			||||||
 | 
					  ;; Remember to update the time-stamp.
 | 
				
			||||||
 | 
					  (time-stamp))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(when do-package-update-on-init
 | 
				
			||||||
 | 
					  (package-refresh-contents))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(dolist (package
 | 
					(dolist (package
 | 
				
			||||||
         '(ac-geiser         ; Auto-complete backend for geiser
 | 
					         '(ac-geiser         ; Auto-complete backend for geiser
 | 
				
			||||||
           ac-slime          ; An auto-complete source using slime completions
 | 
					           ac-slime          ; An auto-complete source using slime completions
 | 
				
			||||||
@ -59,7 +86,8 @@ PACKAGE is installed and the current version is deleted."
 | 
				
			|||||||
           pretty-lambdada   ; the word `lambda' as the Greek letter.
 | 
					           pretty-lambdada   ; the word `lambda' as the Greek letter.
 | 
				
			||||||
           smex              ; M-x interface with Ido-style fuzzy matching.
 | 
					           smex              ; M-x interface with Ido-style fuzzy matching.
 | 
				
			||||||
           ))
 | 
					           ))
 | 
				
			||||||
  (upgrade-or-install-package package))
 | 
					  (when do-package-update-on-init
 | 
				
			||||||
 | 
					    (upgrade-or-install-package package)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(dolist (feature
 | 
					(dolist (feature
 | 
				
			||||||
         '(auto-compile             ; auto-compile .el files
 | 
					         '(auto-compile             ; auto-compile .el files
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										48
									
								
								init.org
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								init.org
									
									
									
									
									
								
							@ -83,12 +83,55 @@
 | 
				
			|||||||
           (package-install package))))
 | 
					           (package-install package))))
 | 
				
			||||||
   #+END_SRC
 | 
					   #+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The =package-refresh-contents= function downloads archive descriptions,
 | 
				
			||||||
 | 
					   this is a major bottleneck in this configuration. To avoid this we can
 | 
				
			||||||
 | 
					   try to only check for updates once every day or so. Here are to
 | 
				
			||||||
 | 
					   variables. The first specifies how often we should check for updates. The
 | 
				
			||||||
 | 
					   second specifies wither one should update during the initialization.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   #+BEGIN_SRC emacs-lisp :tangle yes
 | 
				
			||||||
 | 
					     (defvar days-between-updates 1)
 | 
				
			||||||
 | 
					     (defvar do-package-update-on-init t)
 | 
				
			||||||
 | 
					   #+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   The tricky part is figuring out when the last time the Emacs was opened!
 | 
				
			||||||
 | 
					   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
 | 
				
			||||||
 | 
					   not to do an update. After that we must run the =time-stamp=-function to
 | 
				
			||||||
 | 
					   update the time-stamp.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   #+BEGIN_SRC emacs-lisp :tangle yes
 | 
				
			||||||
 | 
					     (require 'time-stamp)
 | 
				
			||||||
 | 
					     ;; Open the 'user-init-file' and write any changes.
 | 
				
			||||||
 | 
					     (with-temp-file user-init-file
 | 
				
			||||||
 | 
					       ;; Insert it's original content's.
 | 
				
			||||||
 | 
					       (insert-file-contents user-init-file)
 | 
				
			||||||
 | 
					       (forward-line time-stamp-line-limit)
 | 
				
			||||||
 | 
					       (let ((bound (point)))
 | 
				
			||||||
 | 
					         (goto-char (point-min))
 | 
				
			||||||
 | 
					         ;; We search for the time-stamp.
 | 
				
			||||||
 | 
					         (let ((start (re-search-forward time-stamp-start bound t))
 | 
				
			||||||
 | 
					               (end (re-search-forward time-stamp-end bound t)))
 | 
				
			||||||
 | 
					           (when (and start end)
 | 
				
			||||||
 | 
					             ;; Assuming we have found a time-stamp, we check determine if it's
 | 
				
			||||||
 | 
					             ;; time to update.
 | 
				
			||||||
 | 
					             (setq do-package-update-on-init
 | 
				
			||||||
 | 
					                   (<= days-between-updates
 | 
				
			||||||
 | 
					                       (days-between
 | 
				
			||||||
 | 
					                        (current-time-string)
 | 
				
			||||||
 | 
					                        (buffer-substring-no-properties start end)))))))
 | 
				
			||||||
 | 
					       ;; Remember to update the time-stamp.
 | 
				
			||||||
 | 
					       (time-stamp))
 | 
				
			||||||
 | 
					   #+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
 | 
				
			||||||
   up to date. Here are some packages I find useful (some of these
 | 
					   up to date. Here are some packages I find useful (some of these
 | 
				
			||||||
   configurations are also dependent on them).
 | 
					   configurations are also dependent on them).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   #+BEGIN_SRC emacs-lisp :tangle yes
 | 
					   #+BEGIN_SRC emacs-lisp :tangle yes
 | 
				
			||||||
     (package-refresh-contents)
 | 
					     (when do-package-update-on-init
 | 
				
			||||||
 | 
					       (package-refresh-contents))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
     (dolist (package
 | 
					     (dolist (package
 | 
				
			||||||
              '(ac-geiser         ; Auto-complete backend for geiser
 | 
					              '(ac-geiser         ; Auto-complete backend for geiser
 | 
				
			||||||
                ac-slime          ; An auto-complete source using slime completions
 | 
					                ac-slime          ; An auto-complete source using slime completions
 | 
				
			||||||
@ -112,7 +155,8 @@
 | 
				
			|||||||
                pretty-lambdada   ; the word `lambda' as the Greek letter.
 | 
					                pretty-lambdada   ; the word `lambda' as the Greek letter.
 | 
				
			||||||
                smex              ; M-x interface with Ido-style fuzzy matching.
 | 
					                smex              ; M-x interface with Ido-style fuzzy matching.
 | 
				
			||||||
                ))
 | 
					                ))
 | 
				
			||||||
       (upgrade-or-install-package package))
 | 
					       (when do-package-update-on-init
 | 
				
			||||||
 | 
					         (upgrade-or-install-package package)))
 | 
				
			||||||
   #+END_SRC
 | 
					   #+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
** Require
 | 
					** Require
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user