Skip to content

Commit 8fe0bb6

Browse files
committed
haskell-session-choose-target - choose REPL target
Fix initial commit - selection moved to `(interactive)` part - functionality embeded in function `haskell-session-change-target` - cabal target enumeration function moved to `haskell-cabal.el` - `-mapcar` replaced with another function Fix failed tests
1 parent 318ccab commit 8fe0bb6

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

doc/haskell-mode.texi

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -601,32 +601,24 @@ TODO/WRITEME
601601
@findex haskell-session-change-target
602602
@vindex haskell-interactive-mode-hook
603603

604-
With @code{haskell-session-change-target} you can change the section
605-
(defined in project's @file{.cabal} file) the interactive REPL session is
606-
started with.
604+
With @code{haskell-session-change-target} you can change the target for
605+
REPL session.
607606

608-
After the session is started, you can switch the target for
607+
608+
After REPL session started, in @code{haskell-interactive-mode} buffer invoke the
609+
@code{haskell-session-change-target} and select from available targets for
609610

610611
@cindex testing
611612
- Testing
612613

613-
In @code{haskell-interactive-mode} buffer invoke the
614-
@code{haskell-session-change-target} and enter the name of the test you
615-
wish to perform, i.e. ``test''.
616-
Answer ``yes'' to restart the session.
617-
618614
@cindex benchmarking
619615
- Benchmark
620616

621-
In @code{haskell-interactive-mode} buffer invoke the @code{haskell-session-change-target}
622-
and enter the name of the benchmark you wish to perform, i.e. ``bench''.
623-
Answer ``yes'' to restart the session.
624-
625617
- Executable
626618

627-
In @code{haskell-interactive-mode} buffer invoke the @code{haskell-session-change-target}
628-
and enter the name of the executable you wish to work with.
629-
Answer ``yes'' to restart the session.
619+
- Library
620+
621+
Answer ``yes'' to restart the session and run your tests, benchmarks, executables.
630622

631623

632624
TODO/WRITEME

haskell-cabal.el

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,25 @@ OTHER-WINDOW use `find-file-other-window'."
444444
(defun haskell-cabal-section-data-start-column (section)
445445
(plist-get section :data-start-column))
446446

447+
(defun haskell-cabal-enum-targets ()
448+
"Enumerate targets from .cabal file."
449+
(defvar haskell-cabal-source-bearing-sections)
450+
(let ((cabal-file (haskell-cabal-find-file)))
451+
(when (and cabal-file (file-readable-p cabal-file))
452+
(with-temp-buffer
453+
(insert-file-contents cabal-file)
454+
(let* ((targets (mapcar (lambda (arg) (haskell-cabal--all-instances arg))
455+
haskell-cabal-source-bearing-sections)))
456+
(apply #'append targets))))))
457+
458+
(defun haskell-cabal--all-instances (target)
459+
"Return list of all instances of TARGET section."
460+
(goto-char (point-min))
461+
(let (matches)
462+
(while (re-search-forward (concat target " +\\([[:word:]-]+\\)") nil t)
463+
(push (match-string 1) matches))
464+
(sort matches 'string<)))
465+
447466
(defmacro haskell-cabal-with-subsection (subsection replace &rest funs)
448467
"Copy subsection data into a temporary buffer, save indentation
449468
and execute FORMS

haskell-commands.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@ inferior GHCi process."
773773
;;;###autoload
774774
(defun haskell-session-change-target (target)
775775
"Set the build TARGET for cabal REPL."
776-
(interactive "sNew build target:")
776+
(interactive
777+
(list (completing-read "New build target:" (haskell-cabal-enum-targets))))
777778
(let* ((session haskell-session)
778779
(old-target (haskell-session-get session 'target)))
779780
(when session

0 commit comments

Comments
 (0)