diff --git a/doc/haskell-mode.texi b/doc/haskell-mode.texi index ab7e330b2..895ee29c3 100644 --- a/doc/haskell-mode.texi +++ b/doc/haskell-mode.texi @@ -601,32 +601,24 @@ TODO/WRITEME @findex haskell-session-change-target @vindex haskell-interactive-mode-hook -With @code{haskell-session-change-target} you can change the section -(defined in project's @file{.cabal} file) the interactive REPL session is -started with. +With @code{haskell-session-change-target} you can change the target for +REPL session. -After the session is started, you can switch the target for + +After REPL session started, in @code{haskell-interactive-mode} buffer invoke the +@code{haskell-session-change-target} and select from available targets for @cindex testing - Testing -In @code{haskell-interactive-mode} buffer invoke the -@code{haskell-session-change-target} and enter the name of the test you -wish to perform, i.e. ``test''. -Answer ``yes'' to restart the session. - @cindex benchmarking - Benchmark -In @code{haskell-interactive-mode} buffer invoke the @code{haskell-session-change-target} -and enter the name of the benchmark you wish to perform, i.e. ``bench''. -Answer ``yes'' to restart the session. - - Executable -In @code{haskell-interactive-mode} buffer invoke the @code{haskell-session-change-target} -and enter the name of the executable you wish to work with. -Answer ``yes'' to restart the session. +- Library + +Answer ``yes'' to restart the session and run your tests, benchmarks, executables. TODO/WRITEME diff --git a/haskell-cabal.el b/haskell-cabal.el index b659726b4..d51524e57 100644 --- a/haskell-cabal.el +++ b/haskell-cabal.el @@ -444,6 +444,21 @@ OTHER-WINDOW use `find-file-other-window'." (defun haskell-cabal-section-data-start-column (section) (plist-get section :data-start-column)) +(defun haskell-cabal-enum-targets () + "Enumerate .cabal targets." + (let ((cabal-file (haskell-cabal-find-file))) + (when (and cabal-file (file-readable-p cabal-file)) + (with-temp-buffer + (insert-file-contents cabal-file) + (haskell-cabal-mode) + (let (matches) + (goto-char (point-min)) + (haskell-cabal-next-section) + (while (not (eobp)) + (push (haskell-cabal-section-value (haskell-cabal-section)) matches) + (haskell-cabal-next-section)) + (reverse matches)))))) + (defmacro haskell-cabal-with-subsection (subsection replace &rest funs) "Copy subsection data into a temporary buffer, save indentation and execute FORMS diff --git a/haskell-commands.el b/haskell-commands.el index 0b808f4f5..74b2b968c 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -169,6 +169,8 @@ Use to update mtime on BUFFER's file." (defvar url-http-response-status) (defvar url-http-end-of-headers) +(defvar haskell-cabal-targets-history nil + "History list for session targets.") (defun haskell-process-hayoo-ident (ident) ;; FIXME Obsolete doc string, CALLBACK is not used. @@ -773,7 +775,10 @@ inferior GHCi process." ;;;###autoload (defun haskell-session-change-target (target) "Set the build TARGET for cabal REPL." - (interactive "sNew build target:") + (interactive + (list + (completing-read "New build target: " (haskell-cabal-enum-targets) + nil nil nil 'haskell-cabal-targets-history))) (let* ((session haskell-session) (old-target (haskell-session-get session 'target))) (when session