Skip to content

Commit

Permalink
Fix initial commit
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
vlatkoB committed Aug 23, 2015
1 parent 9e54f23 commit 8a44831
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions doc/haskell-mode.texi
Original file line number Diff line number Diff line change
Expand Up @@ -611,15 +611,15 @@ TODO/WRITEME
@node Changing REPL target
@chapter Changing REPL target

@findex haskell-session-choose-target
@findex haskell-session-change-target
@vindex haskell-interactive-mode-hook

With @code{haskell-session-choose-target} you can change the target for
With @code{haskell-session-change-target} you can change the target for
REPL session.


After REPL session started, in @code{haskell-interactive-mode} buffer invoke the
@code{haskell-session-choose-target} and select from available targets for
@code{haskell-session-change-target} and select from available targets for

@cindex testing
- Testing
Expand Down
19 changes: 19 additions & 0 deletions haskell-cabal.el
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,25 @@ 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 targets from .cabal file."
;; (interactive)
(let ((cabal-file (haskell-cabal-find-file)))
(when (and cabal-file (file-readable-p cabal-file))
(with-temp-buffer
(insert-file-contents cabal-file)
(let* ((targets (mapcar (lambda (arg) (haskell-cabal--all-instances arg))
haskell-cabal-source-bearing-sections)))
(apply #'append targets))))))

(defun haskell-cabal--all-instances (target)
"Return list of all instances of TARGET section."
(goto-char (point-min))
(let (matches)
(while (re-search-forward (concat target " +\\([[:word:]-]+\\)") nil t)
(push (match-string 1) matches))
(sort matches 'string<)))

(defmacro haskell-cabal-with-subsection (subsection replace &rest funs)
"Copy subsection data into a temporary buffer, save indentation
and execute FORMS
Expand Down
3 changes: 2 additions & 1 deletion haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ 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))))
(let* ((session haskell-session)
(old-target (haskell-session-get session 'target)))
(when session
Expand Down

0 comments on commit 8a44831

Please sign in to comment.