           (c-put-font-lock-face start (point) 'font-lock-comment-face)))))
   nil)
 
-(use-package clang-format
-  :defer t
-  :init
-  (setq clang-format-executable
-        (if (executable-find "clang-format") "clang-format"
-          (if (executable-find "clang-format-3.8") "clang-format-3.8"
-            (if (executable-find "clang-format-3.7") "clang-format-3.7"
-              (if (executable-find "clang-format-3.6") "clang-format-3.6"
-                (if (executable-find "clang-format-3.5") "clang-format-3.5"))))))
-  (setq clang-format-style (concat "{BasedOnStyle: Google,"
-                                   " BreakBeforeBraces: Linux,"
-                                   " BinPackParameters: true,"
-                                   " BreakBeforeBinaryOperators: NonAssignment,"
-                                   " IndentWidth: 2,"
-                                   " ColumnLimit: 90,"
-                                   " AlwaysBreakBeforeMultilineStrings: false,"
-                                   " SpacesBeforeTrailingComments: 4,"
-                                   " AllowShortFunctionsOnASingleLine: false,"
-                                   " NamespaceIndentation: All,"
-                                   " UseTab: Never,"
-                                   " ConstructorInitializerIndentWidth: 2,"
-                                   " ContinuationIndentWidth: 2,"
-                                   " Standard: Cpp11}"))
-  (add-hook 'c-mode-common-hook
-            (lambda ()
-              (define-key c-mode-base-map (kbd "C-M-\\") 'clang-format-region)
-              (define-key c-mode-base-map (kbd "C-i") 'clang-format))))
-
-(use-package rtags
-  :commands (rtags-is-indexed)
-  ;; https://github.com/Andersbakken/rtags + https://github.com/rizsotto/Bear
-  ;; to create compile_commands.json: bear scons
-  :defer t
-  :init
-  (add-hook 'c-mode-common-hook
-            (lambda ()
-              (define-key c-mode-base-map (kbd "M-.") 'rtags-find-symbol-at-point)
-              (define-key c-mode-base-map (kbd "M-,") 'rtags-location-stack-back))))
+(setq clang-format-executable
+      (if (executable-find "clang-format") "clang-format"
+        (if (executable-find "clang-format-3.8") "clang-format-3.8"
+          (if (executable-find "clang-format-3.7") "clang-format-3.7"
+            (if (executable-find "clang-format-3.6") "clang-format-3.6"
+              (if (executable-find "clang-format-3.5") "clang-format-3.5"))))))
+(setq clang-format-style (concat "{BasedOnStyle: Google,"
+                                 " BreakBeforeBraces: Linux,"
+                                 " BinPackParameters: true,"
+                                 " BreakBeforeBinaryOperators: NonAssignment,"
+                                 " IndentWidth: 2,"
+                                 " ColumnLimit: 90,"
+                                 " AlwaysBreakBeforeMultilineStrings: false,"
+                                 " SpacesBeforeTrailingComments: 4,"
+                                 " AllowShortFunctionsOnASingleLine: false,"
+                                 " NamespaceIndentation: All,"
+                                 " UseTab: Never,"
+                                 " ConstructorInitializerIndentWidth: 2,"
+                                 " ContinuationIndentWidth: 2,"
+                                 " Standard: Cpp11}"))
+
+(setq highlight-symbol-idle-delay 0.5)
+
+(setq company-idle-delay 0.1)
+
+(require 'rtags)
+(require 'popup)
+(require 'company)
+(require 'company-rtags)
+
+(defun my-imenu ()
+  (interactive)
+  (if (rtags-is-indexed)
+      (rtags-imenu)
+    (helm-semantic-or-imenu nil)))
+
+;; https://github.com/Andersbakken/rtags + https://github.com/rizsotto/Bear
+;; to create compile_commands.json: bear scons
+
+(defun my-prog-mode-hook ()
+  (highlight-symbol-mode)
+  (smartscan-mode)           ;; M-n, M-p
+  (company-mode)
+  (whitespace-mode)
+  (define-key prog-mode-map (kbd "<C-tab>") 'company-complete)
+  (define-key prog-mode-map (kbd "C-.") 'my-imenu))
+
+(add-hook 'prog-mode-hook 'my-prog-mode-hook)
 
 (defun my-c-mode-common-hook ()
+  ;; (font-lock-add-keywords
+  ;;  nil
+  ;;  '((my-c-mode-font-lock-if0 (0 font-lock-comment-face prepend))) 'add-to-end)
+  (setq fill-column 90)
+  (setq company-backends '(company-rtags company-files))
+  (setq rtags-completions-enabled t
+        rtags-display-current-error-as-tooltip t
+        rtags-autostart-diagnostics t
+        rtags-show-containing-function t
+        rtags-track-container t)
+  (rtags-diagnostics)
+  (define-key c-mode-base-map (kbd "<C-tab>") 'company-complete)
+  (define-key c-mode-base-map (kbd "M-.") 'rtags-find-symbol-at-point)
+  (define-key c-mode-base-map (kbd "M-,") 'rtags-location-stack-back)
+  (define-key c-mode-base-map (kbd "C-M-\\") 'clang-format-region)
+  (define-key c-mode-base-map (kbd "M-?") 'rtags-display-summary)
+  (define-key c-mode-base-map (kbd "C-i") 'clang-format)
+  (define-key c-mode-base-map (kbd "C-.") 'my-imenu))
+
+(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
+
+(with-eval-after-load 'python
   (progn
-    (font-lock-add-keywords
-     nil
-     '((my-c-mode-font-lock-if0 (0 font-lock-comment-face prepend))) 'add-to-end)
-    (setq fill-column 90)))
-
-(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
-
-(use-package elpy
-  :commands (eply-enable)
-  :init (with-eval-after-load 'python (elpy-enable))
-  :config
-  (remove-hook 'elpy-modules 'elpy-module-yasnippet)
-  (when (or (equal system-type 'darwin) (kelly?))
-    (remove-hook 'elpy-modules 'elpy-module-flymake)))
-
-(use-package racket-mode
-  :if (not (kelly?))
-  :defer t
-  :config
-  (add-hook 'racket-mode-hook          ;; same as C-c C-k
-            (lambda ()
-              (define-key racket-mode-map (kbd "C-c r") 'racket-run))))
+    (elpy-enable)
+    (remove-hook 'elpy-modules 'elpy-module-yasnippet)
+    (when (or (equal system-type 'darwin) (kelly?))
+      (remove-hook 'elpy-modules 'elpy-module-flymake))))
+
+(with-eval-after-load 'racket-mode
+  (define-key racket-mode-map (kbd "C-c r") 'racket-run))
 
 (when (not (kelly?))
   (setq compile-command "scons"))

  (autoload 'vc-darcs-find-file-hook "vc-darcs")
  (add-hook 'find-file-hooks 'vc-darcs-find-file-hook))

(use-package ninja-mode :defer t)

(use-package clojure-mode
  :defer t
  :if (not (kelly?))
  :pin melpa-stable)

(use-package cider
  :defer t
  :if (not (kelly?))
  :pin melpa-stable
  :config
  (add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
  ;; (setq cider-auto-mode nil)
  ;; (setq nrepl-log-messages nil)
  ;; (setq nrepl-hide-special-buffers t)
  (setq cider-repl-use-pretty-printing t)
  (setq cider-prompt-save-file-on-load nil)
  (add-hook 'cider-mode-hook 'eldoc-mode)
  :init (add-hook 'clojure-mode-hook 'cider-mode))

(use-package pixie-mode
  :defer t
  :config (add-hook 'pixie-mode-hook #'inf-clojure-minor-mode))

(use-package browse-kill-ring
  :config
  (define-key (current-global-map) [remap yank-pop] 'browse-kill-ring)   ;; remap yank-pop
  (setq browse-kill-ring-replace-yank t))

(use-package easy-kill
  :bind (([remap kill-ring-save] . easy-kill)
         ([remap mark-sexp] . easy-mark)))

(use-package whitespace
  :diminish whitespace-mode
  :config
  (setq whitespace-line-column 90)             ;; limit line length
  (setq whitespace-style '(face trailing newline))
  (add-hook 'prog-mode-hook 'whitespace-mode))

(use-package shrink-whitespace
  :bind ("M-\\" . shrink-whitespace))

(use-package expand-region
  :defer t
  :bind ("C-=" . er/expand-region))

(use-package visual-regexp
  :bind ("C-c r" . vr/replace))

(use-package eldoc
  :diminish eldoc-mode
  :init
  (add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
  (add-hook 'lisp-interaction-mode-hook 'eldoc-mode)
  (add-hook 'ielm-mode-hook 'eldoc-mode))

(use-package rainbow-mode
  :defer t
  :diminish rainbow-mode
  :init (add-hook 'emacs-lisp-mode-hook 'rainbow-mode))

;; ;; (load-theme 'tango t)
(set-background-color "gray90")

      user-mail-address "capak@inputwish.com"
      user-full-name  "Libor Čapák")

(defun kelly? ()
  (or (string= system-name "typhoon.autokelly.local")
      (string= system-name "idev02.autokelly.local")
      (string= system-name "idev03")
      (string= system-name "idev03.autokelly.local")))

;; (setq compilation-skip-threshold 2)

(setq-default major-mode 'indented-text-mode)    ;; instead fundamental-mode
