 (defun intero-targets ()
   "Set the targets to use for stack ghci."
   (interactive)
-  (let ((targets (split-string (read-from-minibuffer "Targets: ")
-                               " "
-                               t)))
+  (let* ((old-targets
+          (with-current-buffer (intero-buffer 'backend)
+            intero-targets))
+         (available-targets (intero-get-targets))
+         (targets (if available-targets
+                      (intero-multiswitch
+                       "Targets:"
+                       (mapcar (lambda (target)
+                                 (list :key target
+                                       :title target
+                                       :default (member target old-targets)))
+                               available-targets))
+                    (split-string (read-from-minibuffer "Targets: " nil nil nil nil old-targets)
+                                  " "
+                                  t))))
     (intero-destroy)
     (intero-get-worker-create 'backend targets (current-buffer))))
 


(defun intero-multiswitch (title options)
  "Read multiple flags from a list of OPTIONS each of which is a
  plist of (:key :default :title). :key should be a number or
  symbol, :title should be a string, :default (boolean) specifies
  the default checkedness."
  (let ((available-width (window-total-width)))
    (save-window-excursion
      (with-temp-buffer

                       :notify (lambda (widget &rest ignore)
                                 (setq choices
                                       (mapcar (lambda (choice)
                                                 (if (equal (plist-get choice :key)
                                                            (plist-get (cdr widget) :key))
                                                     (plist-put choice :value (plist-get (cdr widget) :value))
                                                   choice))
                                               choices)))
                       :on (concat "[x] " (plist-get option :title))
                       :off (concat "[ ] " (plist-get option :title))
                       :value (plist-get option :default)
                       :key (plist-get option :key)))
          (let ((lines (line-number-at-pos)))
            (select-window (split-window-below (- 0 (max window-min-height (1+ lines)))))
