Skip to content

Commit

Permalink
Improve session switching
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed May 12, 2014
1 parent c8a72bd commit ff2f361
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions haskell-session.el
Expand Up @@ -158,9 +158,11 @@ If DONTCREATE is non-nil don't create a new session."

(defun haskell-session-new-assume-from-cabal ()
"Prompt to create a new project based on a guess from the nearest Cabal file."
(when (y-or-n-p (format "Start a new project named “%s”? "
(haskell-session-default-name)))
(haskell-session-make (haskell-session-default-name))))
(let ((name (haskell-session-default-name)))
(unless (haskell-session-lookup name)
(when (y-or-n-p (format "Start a new project named “%s”? "
name))
(haskell-session-make name)))))

(defun haskell-session-from-buffer ()
"Get the session based on the buffer."
Expand All @@ -187,7 +189,11 @@ If DONTCREATE is non-nil don't create a new session."
"Make a new session."
(let ((name (read-from-minibuffer "Project name: " (haskell-session-default-name))))
(when (not (string= name ""))
(haskell-session-make name))))
(let ((session (haskell-session-lookup name)))
(if session
(when (y-or-n-p (format "Session %s already exists. Use it?" name))
session)
(haskell-session-make name))))))

(defun haskell-session-default-name ()
"Generate a default project name for the new project prompt."
Expand All @@ -206,7 +212,11 @@ If DONTCREATE is non-nil don't create a new session."
(when haskell-sessions
(let* ((session-name (funcall haskell-completing-read-function
"Choose Haskell session: "
(mapcar 'haskell-session-name haskell-sessions)))
(remove-if (lambda (name)
(and haskell-session
(string= (haskell-session-name haskell-session)
name)))
(mapcar 'haskell-session-name haskell-sessions))))
(session (find-if (lambda (session)
(string= (haskell-session-name session)
session-name))
Expand All @@ -220,7 +230,6 @@ If DONTCREATE is non-nil don't create a new session."
(defun haskell-session-change ()
"Change the session for the current buffer."
(interactive)
(haskell-session-clear)
(haskell-session-assign (or (haskell-session-new-assume-from-cabal)
(haskell-session-choose)
(haskell-session-new))))
Expand Down Expand Up @@ -249,6 +258,12 @@ If DONTCREATE is non-nil don't create a new session."
file)
file)))

(defun haskell-session-lookup (name)
"Get the session by name."
(remove-if-not (lambda (s)
(string= name (haskell-session-name s)))
haskell-sessions))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Building the session

Expand Down

0 comments on commit ff2f361

Please sign in to comment.