From 42d9a7763fb4f061e8c963b8d699fc9c744f1396 Mon Sep 17 00:00:00 2001 From: larstvei Date: Tue, 24 Dec 2013 02:09:02 +0100 Subject: [PATCH 1/2] Fixed package and implemented automatic updates. --- init.el | 24 ++++++++++++++++++++++-- init.elc | Bin 8676 -> 9459 bytes init.org | 45 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/init.el b/init.el index d3defe9..6d0656a 100644 --- a/init.el +++ b/init.el @@ -3,17 +3,36 @@ "If the current buffer is 'init.org' the code-blocks are tangled, and the tangled file is compiled." (when (equal (buffer-file-name) - (concat user-emacs-directory "init.org")) + (expand-file-name (concat user-emacs-directory "init.org"))) (org-babel-tangle) (byte-compile-file (concat user-emacs-directory "init.el")))) (add-hook 'after-save-hook 'init-hook) +(require 'package) (package-initialize) (add-to-list 'package-archives '("MELPA" . "http://melpa.milkbox.net/packages/") t) +(defun newest-package-installed-p (package) + "Return true if the newest available PACKAGE is installed." + (when (package-installed-p package) + (let* ((local-pkg-desc (or (assq package package-alist) + (assq package package--builtins))) + (newest-pkg-desc (assq package package-archive-contents))) + (version-list-= (package-desc-vers (cdr local-pkg-desc)) + (package-desc-vers (cdr newest-pkg-desc)))))) + +(defun upgrade-or-install-package (package) + "Unless the newest available version of PACKAGE is installed +PACKAGE is installed and the current version is deleted." + (unless (newest-package-installed-p package) + (let ((pkg-desc (assq package package-alist))) + (when pkg-desc + (package-delete package (package-desc-vers (cdr pkg-desc)))) + (package-install package)))) + (let ((packages '(ac-geiser ; Auto-complete backend for geiser ac-slime ; An auto-complete source using slime completions @@ -40,8 +59,9 @@ tangled, and the tangled file is compiled." ))) ;; 'remove-if' is a part of the cl-library, so we require this feature. (require 'cl) + (package-refresh-contents) ;; Filter out installed packages and install the remaining. - (mapc 'package-install (remove-if 'package-installed-p packages))) + (mapc 'upgrade-or-install-package packages)) (dolist (feature '(auto-compile ; auto-compile .el files diff --git a/init.elc b/init.elc index 942c1f0bc920503dec65bec93377dd900c4f641a..82a5de90ac8fcf2b1ec1066ac9dcfd0ae0a69db0 100644 GIT binary patch delta 1314 zcmaJ=OHb5L6dtfZXT%WR%F8n|3R99oZyz%QL>&YbR(sfORX*ZWl{L@*_D`HtmS6GmcJoYW+U^_hK@&g`y)v!DYb;CR`_GtKxGn+f03YmOGTY~2_ zXm}0;9^$cT5bRTM=xgc+U>q5iZR{e5&DFI>s}Jsh<%8w;fnnRUx^O*HsM4BYTZRvF zQHdBIA)aK3b;xfQ;;;ZYhK?di0Im}F9J2zo9yVu{ZR|5v2VJo1TDHO&*2BU5%bCebc}g5)NFSb;MtSh{+knLikOo9zrGc7Al_u zS<2-}kw|6~_6zZ)##!H5X}Sj%$)Zn37$#saJB%~-J%@3W0U;1F_ubW}kYRw+%uwMB z30gT?Ij+tQ2NjS>gnmAaJ~o4A0t8H_n(*_nVc1#odr9nxg}}1!9`|=mU}dEIDxEU{ zXgZHCuEEa&z|Wyy3f{)`e+n*zzsdvvo-2O;CvcEZUc^-w;hcI3H&iD2K7Um2Hc7YM zY}XI1727%P*E=23vyR*oq%Bn)NvZAFp1O_Q1$9-6ziMn%mtJ{vB%*RmVO7gVcwm diff --git a/init.org b/init.org index 7e971f5..b02d32f 100644 --- a/init.org +++ b/init.org @@ -26,7 +26,7 @@ "If the current buffer is 'init.org' the code-blocks are tangled, and the tangled file is compiled." (when (equal (buffer-file-name) - (concat user-emacs-directory "init.org")) + (expand-file-name (concat user-emacs-directory "init.org"))) (org-babel-tangle) (byte-compile-file (concat user-emacs-directory "init.el")))) @@ -35,11 +35,12 @@ ** Package - Managing extensions for Emacs is simplified using =package= which is - built in to Emacs 24 and newer. To load downloaded packages we need to - initialize =package=. + Managing extensions for Emacs is simplified using =package= which + is built in to Emacs 24 and newer. To load downloaded packages we + need to initialize =package=. #+BEGIN_SRC emacs-lisp :tangle yes + (require 'package) (package-initialize) #+END_SRC @@ -51,7 +52,38 @@ '("MELPA" . "http://melpa.milkbox.net/packages/") t) #+END_SRC - Some packages I find useful are installed if missing. + We can define a predicate that tells us wither or not the newest version + of a package is installed. + + #+BEGIN_SRC emacs-lisp :tangle yes + (defun newest-package-installed-p (package) + "Return true if the newest available PACKAGE is installed." + (when (package-installed-p package) + (let* ((local-pkg-desc (or (assq package package-alist) + (assq package package--builtins))) + (newest-pkg-desc (assq package package-archive-contents))) + (version-list-= (package-desc-vers (cdr local-pkg-desc)) + (package-desc-vers (cdr newest-pkg-desc)))))) + #+END_SRC + + Let's write a function to install the package if it is not installed or + upgrades it if a new version has been released. Here our predicate comes + in handy. + + #+BEGIN_SRC emacs-lisp :tangle yes + (defun upgrade-or-install-package (package) + "Unless the newest available version of PACKAGE is installed + PACKAGE is installed and the current version is deleted." + (unless (newest-package-installed-p package) + (let ((pkg-desc (assq package package-alist))) + (when pkg-desc + (package-delete package (package-desc-vers (cdr pkg-desc)))) + (package-install package)))) + #+END_SRC + + 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 + configurations are also dependent on them). #+BEGIN_SRC emacs-lisp :tangle yes (let ((packages @@ -80,8 +112,9 @@ ))) ;; 'remove-if' is a part of the cl-library, so we require this feature. (require 'cl) + (package-refresh-contents) ;; Filter out installed packages and install the remaining. - (mapc 'package-install (remove-if 'package-installed-p packages))) + (mapc 'upgrade-or-install-package packages)) #+END_SRC ** Require From aa803a9bc6d9bac0b611019e4fd059432bb6a9b0 Mon Sep 17 00:00:00 2001 From: larstvei Date: Tue, 24 Dec 2013 02:18:45 +0100 Subject: [PATCH 2/2] Fix merge conflict --- init.elc | Bin 9459 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 init.elc diff --git a/init.elc b/init.elc deleted file mode 100644 index 82a5de90ac8fcf2b1ec1066ac9dcfd0ae0a69db0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9459 zcmbta`)?b^5fzlBGrRYoBnJf|KooCocW-uf=9_Qk^u?3!9>2f0w|Dr(7hj0SYLh3ajKzE_ z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