   (set-default-font "Inconsolata 13"))
 ;; (setq x-alt-keysym 'meta)
 
-(require 'package)
-(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t)
-(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
-
-(setq package-pinned-packages
-      '((cider          . "melpa-stable")
-        (clojure-mode   . "melpa-stable")))
-
-(package-initialize)
-
-(defvar df/packages '(clojure-mode
-                      pixie-mode
-                      lua-mode
-                      expand-region
-                      vc-darcs
-                      ninja-mode
-                      ag
-                      avy
-                      google-translate
-                      wgrep
-                      wgrep-ag
-                      mwim
-                      exec-path-from-shell
-                      rust-mode
-                      swift-mode
-                      elpy
-                      define-word
-                      imenu-anywhere
-                      rainbow-mode
-                      flatui-theme
-                      json-mode
-                      undo-tree
-                      racket-mode
-                      processing-mode
-                      csharp-mode
-                      diminish
-                      irony
-                      ;; company
-                      ;; company-irony
-                      cider
-                      shrink-whitespace
-                      browse-kill-ring
-                      nyan-mode
-                      highlight-parentheses
-                      projectile
-                      glsl-mode))
-
-(if (not (file-directory-p package-user-dir))     ;; jinak chci manualne
-    (package-refresh-contents))
-
-(dolist (p df/packages)
-  (when (not (package-installed-p p))
-    (package-install p)))
-
-(require 'projectile)
-(projectile-global-mode)
-
-;; (add-hook 'c++-mode-hook 'irony-mode)
-;; (add-hook 'c-mode-hook 'irony-mode)
-;; (add-hook 'objc-mode-hook 'irony-mode)
-
-;; (defun my-irony-mode-hook ()
-;;   (define-key irony-mode-map [remap completion-at-point]
-;;     'irony-completion-at-point-async)
-;;   (define-key irony-mode-map [remap complete-symbol]
-;;     'irony-completion-at-point-async))
-;; (add-hook 'irony-mode-hook 'my-irony-mode-hook)
-;; (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
-
-;; (require 'company)
-;; (require 'company-irony)
-;; (setq company-backends (delete 'company-semantic company-backends)
-;;       company-global-modes '(not term-mode)
-;;       company-transformers '(company-sort-by-occurrence)
-;;       company-minimum-prefix-length 2
-;;       company-selection-wrap-around t
-;;       company-show-numbers t
-;;       company-require-match nil
-;;       company-dabbrev-downcase nil)
-;; (add-to-list 'company-backends 'company-irony)
-;; ;; (setq company-idle-delay 0.1)
-;; (add-hook 'prog-mode-hook (lambda () (company-mode 1)))
-
-(require 'browse-kill-ring)
-
-(require 'uniquify)
-(setq uniquify-buffer-name-style 'forward)
-
-(require 'saveplace)
-(setq-default save-place t)
-
-(require 'diminish)
-(after 'undo-tree (diminish 'undo-tree-mode))
-(after 'rainbow-mode (diminish 'rainbow-mode))
-(after 'abbrev (diminish 'abbrev-mode))
-(after 'whitespace (diminish 'whitespace-mode))
-(after 'highlight-parentheses (diminish 'highlight-parentheses-mode))
-
-(require 'whitespace)
-(setq whitespace-line-column 100)             ;; limit line length
-(setq whitespace-style '(face trailing newline))
-(add-hook 'prog-mode-hook 'whitespace-mode)
-
-(elpy-enable)
-(when (or (equal system-type 'darwin) (kelly?))
-  (setq elpy-modules (delete 'elpy-module-flymake elpy-modules)))
-;; ...nepodarilo se mi zatim zprovoznit
-
-(add-hook 'pixie-mode-hook #'inf-clojure-minor-mode)
-(require 'expand-region)
-
-(require 'highlight-parentheses)
-(require 'rainbow-mode)
-(add-hook 'emacs-lisp-mode-hook 'rainbow-mode)
-(add-hook 'emacs-lisp-mode-hook 'highlight-parentheses-mode)
-(require 'json-mode)
-(require 'define-word)
+(use-package em-alias
+  :config
+  (setq eshell-command-aliases-list (append '(("l" "ls -lcrt")
+                                              ("d" "dired $1")
+                                              ("ff" "find-file $1"))
+                                            eshell-command-aliases-list)))
+
+
+(use-package eshell
+  :init 
+  (defun visit-term-buffer ()
+    "Create or visit a terminal buffer."
+    (interactive)
+    (if (not (get-buffer "*eshell*"))
+        (progn
+          (split-window-sensibly (selected-window))
+          (other-window 1)
+          (eshell))
+      (switch-to-buffer-other-window "*eshell*")))
+  (bind-key "C-c t" 'visit-term-buffer))
+
+(use-package json-mode)
+(use-package lua-mode)
+(use-package rust-mode)
+(use-package swift-mode)
+(use-package processing-mode)
+(use-package csharp-mode)
+
+(use-package projectile
+  :bind ("C-c C-f" . projectile-find-file)
+  :init
+  (projectile-global-mode)
+  (defalias 'pg 'projectile-grep))
+
+(use-package uniquify
+  :init (setq uniquify-buffer-name-style 'forward))
+
+(use-package avy
+  :defer t
+  :bind (("C-;" . avy-goto-word-or-subword-1)
+         ("M-g l" . avy-goto-line))
+  :init (after 'isearch (define-key isearch-mode-map (kbd "C-;") 'avy-isearch)))
+
+(use-package saveplace
+  :init (setq-default save-place t))
+
+(use-package vc-darcs
+  :init
+  (setq vc-disable-async-diff nil)                ;; hotfix
+  (add-to-list 'vc-handled-backends 'DARCS t)
+  (autoload 'vc-darcs-find-file-hook "vc-darcs")
+  (add-hook 'find-file-hooks 'vc-darcs-find-file-hook))
+
+(use-package ninja-mode)
+
+(use-package clojure-mode
+  :pin melpa-stable)
+
+(use-package pixie-mode
+  :init (add-hook 'pixie-mode-hook #'inf-clojure-minor-mode))
+
+(use-package browse-kill-ring
+  :init
+  (define-key (current-global-map) [remap yank-pop] 'browse-kill-ring)   ;; remap yank-pop
+  (setq browse-kill-ring-replace-yank t))
+
+(use-package whitespace
+  :diminish whitespace-mode
+  :config
+  (setq whitespace-line-column 100)             ;; limit line length
+  (setq whitespace-style '(face trailing newline))
+  :init
+  (add-hook 'prog-mode-hook 'whitespace-mode))
+
+(use-package shrink-whitespace
+  :bind ("M-\\" . shrink-whitespace))
+
+(use-package elpy
+  :defer t
+  :init
+  (elpy-enable)
+  (when (or (equal system-type 'darwin) (kelly?))
+    (setq elpy-modules (delete 'elpy-module-flymake elpy-modules))))
+
+(use-package expand-region
+  :defer t
+  :bind ("C-=" . er/expand-region))
+
+(use-package rainbow-mode
+  :defer t
+  :diminish rainbow-mode
+  :init (add-hook 'emacs-lisp-mode-hook 'rainbow-mode))
+
 (add-hook 'prog-mode-hook
           (lambda ()
             (font-lock-add-keywords nil
                                     '(("\\<\\(FIXME\\|TODO\\):" 1 font-lock-preprocessor-face prepend)))))
 
-(require 'imenu-anywhere)
-
-(require 'undo-tree)
-(global-undo-tree-mode 1)           ;; C-x u
-(defalias 'redo 'undo-tree-redo)
+(use-package ibuffer-mode
+  :defer t
+  :bind ("C-x C-b" . ibuffer))
+
+(use-package imenu-anywhere
+  :defer t
+  :bind ("C-." . imenu-anywhere))
+
+(use-package undo-tree
+  :diminish undo-tree-mode
+  :init
+  (global-undo-tree-mode 1)           ;; C-x u
+  (defalias 'redo 'undo-tree-redo))
 
 (if (kelly?)
     (set-background-color "gray90")
-  (load-theme 'flatui t))
-
-(exec-path-from-shell-initialize)
-
-(setq vc-disable-async-diff nil)        ;; hotfix: vc-darcs je modul o ktery se zjevne nikdo moc nestara
-(add-to-list 'vc-handled-backends 'DARCS t)
-(autoload 'vc-darcs-find-file-hook "vc-darcs")
-(add-hook 'find-file-hooks 'vc-darcs-find-file-hook)
-
-(require 'avy)
-(require 'google-translate)
-(require 'google-translate-default-ui)
-;; (require 'google-translate-smooth-ui)
-
-(require 'wgrep)
-(require 'wgrep-ag)
-
-(require 'mwim)
-
-(autoload 'glsl-mode "glsl-mode" nil t)
-
-(setq auto-mode-alist (append '(("\\.mm?$" . objc-mode)
-                                ("\\.as?$" . js-mode)
-                                ("\\.glsl\\'" . glsl-mode)
-                                ("\\.vert\\'" . glsl-mode)
-                                ("\\.frag\\'" . glsl-mode)
-                                ("\\.vsh\\'" . glsl-mode)
-                                ("\\.fsh\\'" . glsl-mode)
-                                ("\\.usf\\'" . glsl-mode))     ;; unreal engine
-                              auto-mode-alist))
-
-(defun setup-mu4e ()
-  (setq epa-file-cache-passphrase-for-symmetric-encryption t)
-  (setq smtpmail-auth-credentials "~/.authinfo")
+  (use-package flatui-theme
+    :init (load-theme 'flatui t)))
+
+(use-package exec-path-from-shell
+  :init (exec-path-from-shell-initialize))
+
+(use-package google-translate
+  :defer t
+  :init (require 'google-translate-default-ui))
+
+(use-package ag)
+(use-package wgrep)
+(use-package wgrep-ag)
+
+(use-package mwim
+  :bind ("C-a" . mwim-beginning-of-code-or-line))
+;; ("C-e" . mwim-end-of-code-or-line)
+
+(use-package objc-mode
+  :defer t
+  :mode "\\.mm?$")
+
+(use-package js-mode
+  :defer t
+  :mode "\\.as?$")
+
+(use-package glsl-mode
+  :defer t
+  :mode ("\\.\\(glsl\\|vert\\|frag\\|vsh\\|fsh\\|usf\\)\\'" . glsl-mode))     ;; usf = unreal engine
+
+(use-package smtpmail
+  :if (not (kelly?))
+  :defer t
+  :config
+  (setq message-send-mail-function 'smtpmail-send-it
+        smtpmail-auth-credentials "~/.authinfo"
+        ;;smtpmail-stream-type 'ssl
+        starttls-use-gnutls t
+        smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
+        smtpmail-auth-credentials '(("smtp.gmail.com" 587 "capak44@gmail.com" nil))
+        smtpmail-default-smtp-server "smtp.gmail.com"
+        smtpmail-smtp-server "smtp.gmail.com"
+        smtpmail-smtp-service 587))
+
+(use-package mu4e
+  :if (not (kelly?))
+  :defer t
+  :config
   (when (equal system-type 'gnu/linux)
     (add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e"))
   (when (equal system-type 'darwin)
     (setq mu4e-mu-binary "/usr/local/bin/mu")
     (add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e"))
-
-  (require 'mu4e)
-
   (when (equal system-type 'gnu/linux)
     (setq mu4e-mu-binary "/usr/bin/mu"))
-
   (when (fboundp 'imagemagick-register-types)
     (imagemagick-register-types))
-
-  (setq mu4e-maildir "~/Maildir"
+  (setq epa-file-cache-passphrase-for-symmetric-encryption t
+        mu4e-maildir "~/Maildir"
         mu4e-drafts-folder "/[Gmail].Drafts"
         mu4e-sent-folder   "/[Gmail].Sent Mail"
         mu4e-trash-folder  "/[Gmail].Trash"

        mu4e-view-show-addresses t
        mu4e-date-format-long "%d.%m.%Y"
        mu4e-headers-date-format "%d.%m.%y"
        mu4e-confirm-quit nil)
  ;; (setq mu4e-use-fancy-chars t)

  (set-face-attribute 'mu4e-unread-face nil
                      :inherit font-lock-preprocessor-face
                      :bold t)

  (require 'smtpmail)

  ;; (defadvice smtpmail-send-it (around fix-using-openssl activate)
  ;;   (let ((tls-program
  ;;          '("openssl s_client -connect %h:%p -no_ssl2 -ign_eof -starttls smtp"))
  ;;         tls-program)
  ;;     ad-do-it))

  (setq message-send-mail-function 'smtpmail-send-it
        ;;smtpmail-stream-type 'ssl
        starttls-use-gnutls t
        smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
        smtpmail-auth-credentials '(("smtp.gmail.com" 587 "capak44@gmail.com" nil))
        smtpmail-default-smtp-server "smtp.gmail.com"
        smtpmail-smtp-server "smtp.gmail.com"
        smtpmail-smtp-service 587)

  (setq message-kill-buffer-on-exit t)

  (defun mu4e-msgv-action-view-in-browser (msg)
    "View the body of the message in a web browser."
    (interactive)

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq-default py-indent-offset 4)
;; (setq-default abbrev-mode t)
(winner-mode t)   ;; C-c <left|right>
(set-language-environment "czech")
(setq default-input-method "czech-qwerty")
