adjust
[emacs.git] / .emacs.d / elisp / local / use-package.el
index 68216c6..50fa4ed 100644 (file)
@@ -5,6 +5,7 @@
 ;; Author: John Wiegley <jwiegley@gmail.com>
 ;; Created: 17 Jun 2012
 ;; Version: 1.0
+;; Package-Requires: ((bind-key "1.0") (diminish "0.44"))
 ;; Keywords: dotemacs startup speed config package
 ;; X-URL: https://github.com/jwiegley/use-package
 
 ;; if you have that installed.  It's purpose is to remove strings from your
 ;; mode-line that would otherwise always be there and provide no useful
 ;; information.  It is invoked with the `:diminish' keyword, which is passed
-;; either the minor mode symbol, or a cons of the symbol and a replacement string:
+;; either the minor mode symbol, a cons of the symbol and a replacement string,
+;; or just a replacement string in which case the minor mode symbol is guessed
+;; to be the package name with "-mode" at the end:
 ;;
 ;;   (use-package abbrev
 ;;     :diminish abbrev-mode
 (eval-when-compile
   (require 'cl))
 
+(declare-function package-installed-p 'package)
+(declare-function el-get-read-recipe 'el-get)
+
 (defgroup use-package nil
-  "A use-package declaration for simplifying your .emacs"
+  "A use-package declaration for simplifying your `.emacs'."
   :group 'startup)
 
 (defcustom use-package-verbose t
   :group 'use-package)
 
 (defcustom use-package-debug nil
-  "Whether to report more information, mostly regarding el-get"
+  "Whether to report more information, mostly regarding el-get."
   :type 'boolean
   :group 'use-package)
 
 (defcustom use-package-minimum-reported-time 0.01
   "Minimal load time that will be reported"
   :type 'number
-  :group 'use-package
-  )
+  :group 'use-package)
 
 (defmacro with-elapsed-timer (text &rest forms)
   `(let ((now ,(if use-package-verbose
 (defvar use-package-idle-forms nil)
 
 (defun use-package-start-idle-timer ()
-  "Ensure that the idle timer is running"
+  "Ensure that the idle timer is running."
   (unless use-package-idle-timer
     (setq use-package-idle-timer
           (run-with-idle-timer
            'use-package-idle-eval))))
 
 (defun use-package-init-on-idle (form)
-  "Add a new form to the idle queue"
+  "Add a new form to the idle queue."
   (use-package-start-idle-timer)
   (if use-package-idle-forms
       (add-to-list 'use-package-idle-forms
                    form t)
-    (setq use-package-idle-forms (list form))
-    ))
+    (setq use-package-idle-forms (list form))))
 
 (defun use-package-idle-eval()
-  "Start to eval idle-commands from the idle queue"
+  "Start to eval idle-commands from the idle queue."
   (let ((next (pop use-package-idle-forms)))
     (if next
         (progn
              (message
               "Failure on use-package idle. Form: %s, Error: %s"
               next e)))
-         ;; recurse after a bit
+          ;; recurse after a bit
           (when (sit-for 3)
-           (use-package-idle-eval)))
+            (use-package-idle-eval)))
       ;; finished (so far!)
       (cancel-timer use-package-idle-timer)
       (setq use-package-idle-timer nil))))
@@ -407,8 +411,7 @@ For full documentation. please see commentary.
 :defines Define vars to silence byte-compiler.
 :load-path Add to `load-path' before loading.
 :diminish Support for diminish package (if it's installed).
-:idle adds a form to run on an idle timer
-"
+:idle adds a form to run on an idle timer"
   (let* ((commands (plist-get args :commands))
          (pre-init-body (plist-get args :pre-init))
          (init-body (plist-get args :init))
@@ -445,6 +448,7 @@ For full documentation. please see commentary.
                   ensure)))
 
         (when package-name
+          (require 'package)
           (use-package-ensure-elpa package-name)))
 
 
@@ -453,16 +457,20 @@ For full documentation. please see commentary.
                 `(progn
                    ,config-body
                    (ignore-errors
-                     ,@(if (listp diminish-var)
-                           (if (listp (cdr diminish-var))
-                               (mapcar (lambda (var)
-                                           (if (listp var)
-                                               `(diminish (quote ,(car var)) ,(cdr var))
-                                               `(diminish (quote ,var))))
-                                diminish-var)
-                               `((diminish (quote ,(car diminish-var)) ,(cdr diminish-var)))
-                           )
-                         `((diminish (quote ,diminish-var))))))))
+                     ,@(cond
+                        ((stringp diminish-var)
+                         `((diminish (quote ,(intern (concat name-string "-mode")))
+                                     ,diminish-var)))
+                        ((symbolp diminish-var)
+                         `((diminish (quote ,diminish-var))))
+                        ((and (consp diminish-var) (stringp (cdr diminish-var)))
+                         `((diminish (quote ,(car diminish-var)) ,(cdr diminish-var))))
+                        (t ; list of symbols or (symbol . "string") pairs
+                         (mapcar (lambda (var)
+                                   (if (listp var)
+                                       `(diminish (quote ,(car var)) ,(cdr var))
+                                     `(diminish (quote ,var))))
+                                 diminish-var)))))))
 
       (if (and commands (symbolp commands))
           (setq commands (list commands)))
@@ -475,35 +483,38 @@ For full documentation. please see commentary.
                    ,init-body)))
 
 
-      (flet ((init-for-commands
-              (func sym-or-list)
-              (let ((cons-list (if (and (consp sym-or-list)
-                                        (stringp (car sym-or-list)))
-                                   (list sym-or-list)
-                                 sym-or-list)))
-                (if cons-list
-                    (setq init-body
-                          `(progn
-                             ,init-body
-                             ,@(mapcar #'(lambda (elem)
-                                           (push (cdr elem) commands)
-                                           (funcall func elem))
-                                       cons-list)))))))
-
-        (init-for-commands #'(lambda (binding)
-                               `(bind-key ,(car binding)
-                                          (quote ,(cdr binding))))
-                           (plist-get args :bind))
-
-        (init-for-commands #'(lambda (mode)
-                               `(add-to-list 'auto-mode-alist
-                                             (quote ,mode)))
-                           (plist-get args :mode))
-
-        (init-for-commands #'(lambda (interpreter)
-                               `(add-to-list 'interpreter-mode-alist
-                                             (quote ,interpreter)))
-                           (plist-get args :interpreter)))
+      (let ((init-for-commands
+             (lambda (func sym-or-list)
+               (let ((cons-list (if (and (consp sym-or-list)
+                                         (stringp (car sym-or-list)))
+                                    (list sym-or-list)
+                                  sym-or-list)))
+                 (if cons-list
+                     (setq init-body
+                           `(progn
+                              ,init-body
+                              ,@(mapcar #'(lambda (elem)
+                                            (push (cdr elem) commands)
+                                            (funcall func elem))
+                                        cons-list))))))))
+
+        (funcall init-for-commands
+                 #'(lambda (binding)
+                     `(bind-key ,(car binding)
+                                (quote ,(cdr binding))))
+                 (plist-get args :bind))
+
+        (funcall init-for-commands
+                 #'(lambda (mode)
+                     `(add-to-list 'auto-mode-alist
+                                   (quote ,mode)))
+                 (plist-get args :mode))
+
+        (funcall init-for-commands
+                 #'(lambda (interpreter)
+                     `(add-to-list 'interpreter-mode-alist
+                                   (quote ,interpreter)))
+                 (plist-get args :interpreter)))
 
       `(progn
          ,@(mapcar
@@ -597,6 +608,15 @@ For full documentation. please see commentary.
 
 (put 'use-package 'lisp-indent-function 1)
 
-(provide 'use-package)
+(defconst use-package-font-lock-keywords
+  '(("(\\(use-package\\)\\> *\\(\\sw+\\)?"
+     (1 font-lock-keyword-face)
+     (2 font-lock-constant-face))))
 
+(font-lock-add-keywords 'emacs-lisp-mode use-package-font-lock-keywords)
+
+(provide 'use-package)
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
 ;;; use-package.el ends here