Skip to content

Commit 1001c10

Browse files
committed
better installation of missing packages
Consolidated some repeated logic into `starter-kit-install-if-needed'.
1 parent c63fb85 commit 1001c10

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed

starter-kit-misc.org

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ Things that don't fit anywhere else.
1111
Determine whether required packages are installed. If not, use ELPA to
1212
install them. Other dependencies are provided by Emacs 24.
1313
#+begin_src emacs-lisp
14-
(dolist (package '(magit))
15-
(unless (or (starter-kit-loadable-p package) (package-installed-p package))
16-
(package-install package)))
14+
(starter-kit-install-if-needed 'magit)
1715
#+end_src
1816

1917
** Color Themes

starter-kit-publish.org

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ the documentation for the Starter Kit to html.
1919
(package-archives '(("original" . "http://tromey.com/elpa/"))))
2020
;; load up htmlize
2121
(package-initialize)
22-
(let ((package 'htmlize))
23-
(unless (or (member package package-activated-list)
24-
(functionp package))
25-
(package-install package)))
22+
(unless (functionp 'htmlize)
23+
(starter-kit-install-if-needed 'htmlize))
2624
(require 'htmlize)
2725
(org-export-htmlize-generate-css)
2826
;; define the org-publish-project for the starter kit

starter-kit-python.org

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ Support for the Python programming language.
1212
Determine whether required packages are installed. If not, use ELPA to
1313
install them.
1414
#+begin_src emacs-lisp
15-
(dolist (package '(python-mode ipython))
16-
(unless (or (starter-kit-loadable-p package) (package-installed-p package))
17-
(package-install package)))
15+
(starter-kit-install-if-needed 'python-mode 'ipython)
1816
#+end_src
1917

2018
** Use Python's python-mode.el instead of Emacs' python.el

starter-kit-ruby.org

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ Support for the [[http://www.ruby-lang.org/en/][Ruby]] dynamic, open-source prog
2424

2525
** Yaml mode
2626
#+begin_src emacs-lisp
27-
(dolist (package '(yaml-mode))
28-
(unless (or (starter-kit-loadable-p package) (package-installed-p package))
29-
(package-install package)))
27+
(starter-kit-install-if-needed 'yaml-mode)
3028
(require 'yaml-mode)
3129
(add-to-list 'auto-mode-alist '("\\.ya?ml$" . yaml-mode))
3230
#+end_src

starter-kit-yasnippet.org

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ inspired by TextMate's templating syntax.
1111

1212
Install yasnippet.
1313
#+begin_src emacs-lisp
14-
(unless (or (null starter-kit-packages) package-archive-contents)
15-
(package-refresh-contents))
16-
17-
(let ((package 'yasnippet))
18-
(unless (or (starter-kit-loadable-p package) (package-installed-p package))
19-
(package-install package)))
14+
(starter-kit-install-if-needed 'yasnippet)
2015

2116
;; If `yasnippet-bundle' has previously been installed through ELPA,
2217
;; delete it before installing the new `yasnippet'

starter-kit.org

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,15 @@ interested in the actual code implementing the starter kit.
291291
(defvar starter-kit-packages nil
292292
"Libraries that should be installed by default (currently none).")
293293

294-
(unless (or (null starter-kit-packages) package-archive-contents)
295-
(package-refresh-contents))
296-
(dolist (package starter-kit-packages)
297-
(unless (or (starter-kit-loadable-p package) (package-installed-p package))
298-
(package-install package)))
294+
(defun starter-kit-install-if-needed (&rest packages)
295+
"Install PACKAGES using ELPA if they are not loadable or installed locally."
296+
(when packages
297+
(unless package-archive-contents
298+
(package-refresh-contents))
299+
(dolist (package packages)
300+
(unless (or (starter-kit-loadable-p package)
301+
(package-installed-p package))
302+
(package-install package)))))
299303
#+end_src
300304

301305
- Function for loading other parts of the starter kit

0 commit comments

Comments
 (0)