Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose a REPL session target from list #828

Merged
merged 3 commits into from
Sep 2, 2015
Merged

Conversation

vlatkoB
Copy link
Contributor

@vlatkoB vlatkoB commented Aug 22, 2015

New function haskell-session-choose-target enables choosing from available targets list from .cabal file.
It is just a wrapper around haskell-session-change-target which can still be used to select a target directly, by specifying it as an arg.

@vlatkoB vlatkoB mentioned this pull request Aug 22, 2015
@gracjan
Copy link
Contributor

gracjan commented Aug 22, 2015

@vlatkoB: almost great!

I think (interactive) can do what you need it to do, look here: http://stackoverflow.com/questions/2382524/adding-completion-to-interactive

  • please embed this functionality in an already existing function haskell-session-change-target
  • look through haskell-cabal.el and see if there is anything you could use
  • put the cabal section enumeration function in haskell-cabal.el
  • -mapcar is not good, please find something elisp specific that fulfills the purpose

@vlatkoB
Copy link
Contributor Author

vlatkoB commented Aug 23, 2015

Almost all requests fulfilled, except the using something from haskell-cabal.el.
Actually, my first attempt used exclusively haskell-cabal functions:

(defun haskell-cabal-extract-targets ()
  "Enumerate targets from .cabal file."
  (interactive)
  (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)))

However, it works correctly only when invoked inside .cabal buffer. When called with with-temp-buffer, results are incorrect.

(defun test-in-temp ()
  (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)
    (print (haskell-cabal-extract-targets))))))

Either I'm blind to some obvious mistake, or functions in haskell-cabal are somehow dependent on "real" .cabal file or something.

I asked on IRC for help, but no answer. I'm very fresh in elisp, and can't solve it without going too deep, for what I currently have no time.

In other words, any help is appreciated.

@gracjan
Copy link
Contributor

gracjan commented Aug 23, 2015

I just tested the two functions that you've put here and those work (well, almost). I get all the answers plus some additional things.

  • please use haskell-cabal-source-bearing-sections to only find things that can be a target

@vlatkoB
Copy link
Contributor Author

vlatkoB commented Aug 23, 2015

If you mean the functions in the post above, the result is not correct. Not only there are more results than needed, but the result for test is prefixed with -suite.
("-version: >=1.20" "-type: Simple" "biblio" "biny" "-suite test1" "-suite test2" "benchy")

The result of the function should be the same when in the buffer with .cabal file, and when using with-temp-buffer. Input is the same, so should be the output. I don't trust it. Too much IO. :-)
At least until I find out what's causing the differences.

Can the author of haskell-cabal maybe comment the issue?

@gracjan
Copy link
Contributor

gracjan commented Aug 23, 2015

If you look into haskell-cabal-mode-syntax-table you will find:

    (modify-syntax-entry ?- "w"  st)

That says that in buffers where haskell-cabal-mode is enabled - char should match \\w regexp. If buffer is not in haskell-cabal-mode minus char is not word character so it does not match.

@vlatkoB
Copy link
Contributor Author

vlatkoB commented Aug 23, 2015

It is working now. Changed major-mode of temp buffer to haskell-cabal-mode.
Can you test on your side?

@gracjan
Copy link
Contributor

gracjan commented Aug 23, 2015

Works for me. Please clean up two more things and we are good to go.

@vlatkoB
Copy link
Contributor Author

vlatkoB commented Aug 23, 2015

What defvar are you talking about?
There was one in previous commit to satisfy tests, but none in this commit. In this commit I merged two functions in above post and replaced the previous haskell-cabal-enum-targets function, as the commit message says.

@gracjan
Copy link
Contributor

gracjan commented Aug 23, 2015

There are two commits in this pull request. defvar is in line 449 of the first one.

@vlatkoB
Copy link
Contributor Author

vlatkoB commented Aug 24, 2015

I'm a little lost. Could use a little help.

@gracjan
Copy link
Contributor

gracjan commented Aug 24, 2015

It was me who was lost, everything is fine.

I have one more request though: can you make it use its own separate history variable? Have a read here:

http://www.gnu.org/software/emacs/manual/html_node/elisp/Minibuffer-Completion.html

There is an argument called history and it defaults to minibuffer-history. This is suboptimal, better is to use special history variable for cabal targets, lets say haskell-cabal-targets-history.

Can you do this?

@vlatkoB
Copy link
Contributor Author

vlatkoB commented Aug 24, 2015

Can you check?

@gracjan
Copy link
Contributor

gracjan commented Sep 2, 2015

@vlatkoB: Can you fix these two small things? Your pull request is valuable and it is a shame that it wait in queue.

@vlatkoB
Copy link
Contributor Author

vlatkoB commented Sep 2, 2015

@gracjan They were fixed the day you asked for them. haskell-cabal-targets-history to symbol above.

@gracjan gracjan changed the title Choose a REPL session target from list, Fixes #817 Choose a REPL session target from list Sep 2, 2015
@gracjan
Copy link
Contributor

gracjan commented Sep 2, 2015

Fixes #817

gracjan added a commit that referenced this pull request Sep 2, 2015
Choose a REPL session target from list
@gracjan gracjan merged commit 23155e4 into haskell:master Sep 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants