summaryrefslogtreecommitdiffstats
path: root/init.d/main.org
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2016-09-12 19:59:26 +0200
committerAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2016-09-12 19:59:26 +0200
commitd835d8bf8c1fa2158aa34fd4d99e9fdd3449c593 (patch)
tree876e004fb45aa450febcea90083560d8d2e7c3d8 /init.d/main.org
parenta3ed94f862575825c1453a38295dc3a7f6ff12c5 (diff)
downloademacs-d835d8bf8c1fa2158aa34fd4d99e9fdd3449c593.tar.gz
emacs-d835d8bf8c1fa2158aa34fd4d99e9fdd3449c593.tar.xz
emacs-d835d8bf8c1fa2158aa34fd4d99e9fdd3449c593.zip
use-package: Add :if-installed keyword
With the :if-installed keyword it is possible to check, if a package is installed before binding keys or creating autoloads. This helps of optional packages that overwrites built-in keys (like helm with M-x).
Diffstat (limited to 'init.d/main.org')
-rw-r--r--init.d/main.org61
1 files changed, 47 insertions, 14 deletions
diff --git a/init.d/main.org b/init.d/main.org
index 1ec2e9f..a3efc99 100644
--- a/init.d/main.org
+++ b/init.d/main.org
@@ -54,7 +54,39 @@ requirement for this configuration, so I install it here.
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(setq use-package-verbose t)
- (require 'use-package))
+ (require 'use-package)
+ <<use-package>>)
+#+end_src
+
+*** :if-installed
+
+I extend the basic set of use-package keywords with a new
+one: =:if-installed t= only enables the bind and auto-load hooks if
+the package is installed (checked with =package-installed-p=). It is
+a shorter way to write =:if (package-installed-p "<pkgname>")=. You
+can give another package name to check as argument instead of =t=.
+
+#+begin_src emacs-lisp :noweb-ref use-package :tangle no
+ (setq use-package-keywords (cons :if-installed use-package-keywords))
+
+ (defun use-package-normalize/:if-installed (name keyword args)
+ (if (null args)
+ t
+ (use-package-only-one (symbol-name keyword) args
+ (lambda (label arg)
+ (if (symbolp arg)
+ arg
+ (use-package-error
+ (concat ":if-installed wants an optional package name "
+ "(an unquoted symbol name)")))))))
+
+ (defun use-package-handler/:if-installed (name keyword ensure rest state)
+ (let ((body (use-package-process-keywords name rest state))
+ (package-name (or (and (eq ensure t) (use-package-as-symbol name)) ensure)))
+ `((if (package-installed-p ',package-name)
+ (progn ,@body)
+ ,(when (bound-and-true-p use-package-verbose)
+ `(message ,(format "Configuring package %s...SKIPPED" package-name)))))))
#+end_src
** auto-compile
@@ -1185,8 +1217,8 @@ the window. It is not optimal, because it does not display the
possibility. Maybe I will replace it with a custom hydra.
#+begin_src emacs-lisp
-(when (locate-library "ace-window")
(use-package ace-window
+ :if-installed t
:bind (("C-x o" . ace-window)
("C-x C-o" . aw-flip-window))
:config
@@ -1198,7 +1230,7 @@ possibility. Maybe I will replace it with a custom hydra.
(?v aw-split-window-vert " Ace - Split Vert Window")
(?h aw-split-window-horz " Ace - Split Horz Window")
(?i delete-other-windows " Ace - Maximize Window")
- (?o delete-other-windows)))))
+ (?o delete-other-windows))))
#+end_src
** auto-complete
@@ -1209,18 +1241,19 @@ when pressing the shortcut (but the auto-complete-mode has to be
enabled before).
#+begin_src emacs-lisp
- (use-package auto-complete
- :bind ("M-<tab>" . auto-complete)
- :demand t
- :diminish auto-complete-mode
- :config
- (require 'auto-complete-config)
- (ac-config-default)
+ (use-package auto-complete
+ :if-installed t
+ :bind ("M-<tab>" . auto-complete)
+ :demand t
+ :diminish auto-complete-mode
+ :config
+ (require 'auto-complete-config)
+ (ac-config-default)
- (setq ac-comphist-file (alex/cache-file "ac-comphist.dat")
- ac-quick-help-delay 1.0)
+ (setq ac-comphist-file (alex/cache-file "ac-comphist.dat")
+ ac-quick-help-delay 1.0)
- (global-auto-complete-mode t))
+ (global-auto-complete-mode t))
#+end_src
** TODO company-mode
@@ -1410,6 +1443,7 @@ every time I start emacs.
#+begin_src emacs-lisp
(use-package helm
+ :if-installed t
:bind (("M-x" . helm-M-x)
("M-X" . execute-extended-command)
("C-x f" . helm-mini)
@@ -1417,7 +1451,6 @@ every time I start emacs.
("C-x C-b" . helm-buffers-list)
("M-y" . helm-show-kill-ring))
:demand t
- :ensure t
:diminish helm-mode
:config
<<helm-config>>