 (use-package pyvenv
   :ensure t
   :config
-  (defun ach-set-pyvenv-workon ()
-    (local-set-key (kbd "C-c C-d") #'pyvenv-deactivate)
-    (local-set-key (kbd "C-c C-w") #'pyvenv-workon))
-  (add-hook 'python-mode-hook #'ach-set-pyvenv-workon))
+  (define-key python-mode-map (kbd "C-c C-d") #'pyvenv-deactivate)
+  (define-key python-mode-map (kbd "C-c C-w") #'pyvenv-workon))
 
 ;; The warning message is very annoying, let's get rid of it
 ;; Solution found at:

             (python-shell-switch-to-shell)))))

;; Add tweaks to standard python.el defined in this file.
(defun ach-python-rebinds ()
  "Add the functions defined in python-programming.el to Python buffer locally."
  ;; Shell related commands
  (local-set-key (kbd "C-c C-z") #'ach-python-switch-to-shell)
  (local-set-key (kbd "C-c C-r") #'spacemacs/python-execute-file)
  (local-set-key (kbd "C-c C-c") #'python-shell-send-dwim)
  ;; I don't know why these are not defaults
  (local-set-key (kbd "C-M-f") #'python-nav-forward-sexp)
  (local-set-key (kbd "C-M-b") #'python-nav-backward-sexp)
  (local-set-key (kbd "C-M-a") #'python-nav-backward-defun)
  (local-set-key (kbd "C-M-e") #'python-nav-forward-defun))

(add-hook 'python-mode-hook #'ach-python-rebinds)

;; Debugging
(defun ach-python-debug ()
  "Insert import ipdb; ipdb.set_trace() in the buffer."
  (interactive)
  (insert "import ipdb; ipdb.set_trace()")
  (newline-and-indent))

(define-key python-mode-map (kbd "C-c C-e") 'ach-python-debug)


(with-eval-after-load 'ivy
  (add-to-list 'ivy-ignore-buffers "\\*epc con"))

(add-hook 'python-mode-hook #'rainbow-delimiters-mode)
(add-hook 'python-mode-hook (lambda () (color-identifiers-mode -1)))

