Emacs init.el and Elisp and equivalent of common lisp every-p function -
i working on init.el , setup checks if defined packages installed , if not refresh package contents , install them.
i can automate install fine, want refresh package list if there packages not installed.
i came works common lisp seems if elisp not have every-p simplest method.
(defparameter *my-packages* '(evil evil-leader helm)) (defparmeter *installed-pkgs* '()) ;fake package-installed-p (defun package-installed-p(pkg) (member pkg *installed-pkgs*)) ;fake package-install (defun package-install(pkg) (format t "installing package: ~a~%" pkg)) (defun check-installed-p() (every #'package-installed-p *my-packages*)) (defun mytest() (unless (check-installed-p) (package-refresh-contents) (dolist (pkg *my-packages*) (unless (package-installed-p pkg) (package-install pkg)))))
the other method came following using return-from seems not part of elisp. searching looks emulate catch , throw.
(defun check-installed-p() (dolist (pkg *my-packages*) (unless (package-installed-p(pkg) (return-from check-installed-p nil))) (return-from check-installed-p t))
what best way this?
edit #1 using cl-lib , cl-extra
(require 'package) (require 'cl-lib) (require 'cl-extra) (push '("melpa" . "http://melpa.org/packages/") package-archives ) (package-initialize) (defconst *my-packages* '(evil evil-leader helm)) (defun my-package-check() (unless (cl-every #'package-installed-p *my-packages) (package-refresh-contents) (dolist (pkg *my-packages*) (unless (package-installed-p pkg) (package-install pkg))))) (my-package-check) (require 'evil) (require 'evil-leader) (require 'helm-config)
edit #2
to without require common lisp libraries, replace cl-every my-every below followint drew's suggested answer.
thanks help!
(defun my-every (pred list) (while (and list (funcall pred (car list))) (setq list (cdr list))) (null list))
i use in bookmark+:
(defun bmkp-every (predicate list) "return t if predicate true elements of list; else nil." (while (and list (funcall predicate (car list))) (setq list (cdr list))) (null list))
Comments
Post a Comment