 (use-package clojure-mode
   :ensure t
   :config
-  (add-hook 'clojure-mode-hook 'clojure-jack-in)
+  (add-hook 'clojure-mode-hook 'maybe-cider-jack-in)
   (define-clojure-indent
     (against-background 'defun)
     (alet 'defun)

(global-set-key (kbd "M-]") 'end-of-buffer)
(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "s-j") 'delete-indentation)
(global-set-key (kbd "<f4>") 'query-replace-from-beginning-of-buffer)
(global-set-key (kbd "<f5>") 'query-replace-regexp-from-beginning-of-buffer)

;; Install use-package
(unless (package-installed-p 'use-package)

(defun cider-show-repl-buffer ()
  "Show cider repl buffer."
  (interactive)
  (call-and-go-to-previous-buffer 'cider-switch-to-repl-buffer))

(defun maybe-cider-jack-in ()
  "Start the repl if there is no current connection."
  (unless (cider-current-connection)
    (cider-jack-in '())))

(defun call-on-buffer (func)
  "Call FUNC on buffer."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (call-interactively func)))

(defun query-replace-buffer ()
  "Call 'query-replace' on buffer."
  (interactive)
  (call-on-buffer 'query-replace))

(defun query-replace-regexp-buffer ()
  "Call 'query-replace-regexp' on buffer."
  (interactive)
  (call-on-buffer 'query-replace-regexp))

;; Hooks
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
