haskell-interactive-bring should split windows vertically #60

Closed
nurpax opened this Issue Jun 12, 2012 · 5 comments

Comments

Projects
None yet
2 participants
Contributor

nurpax commented Jun 12, 2012

When I load a cabal file and hit C-c C-c to build the cabal project, my screen is split vertically just as it gets split when I use the standard Emacs M-x compile command.

However, when the compile fails and I hit enter on the error message in the interactive shell, the screen gets split horizontally. This happens even when I already have .hs file and the interactive windows both open in a vertical split configuration.

I think the problem is in haskell-interactive-bring. I see that it splits windows horizontally.

However, it seems to me that the code actually tries to avoid splitting in case the current window configuration is already split such that there's a source file and an interactive window already active. I think the find-if search somehow fails to detect this configuration.

So two things: 1) correctly detect the window configuration and don't split if the config is already ok and 2) split vertically if a split needs to be done.

PS. The new interactive stuff w/ cabal-dev is great! I've been looking for this for quite some time.

;;;###autoload
(defun haskell-interactive-bring ()
  "Bring up the interactive mode for this session."
  (interactive)
  (let ((session (haskell-session)))
    (let ((buffer (haskell-session-interactive-buffer session)))
      (unless (and (find-if (lambda (window) (equal (window-buffer window) buffer))
                            (window-list))
                   (= 2 (length (window-list))))
        (delete-other-windows)
        (split-window-horizontally)
        (switch-to-buffer-other-window buffer)
        (other-window 1)))))

Edit: More specific repro steps:

  1. Open file foo.hs (which is part of a foo.cabal project)
  2. C-c C-c
  3. Answer the usual questions in minibuffer relating to setting up the project, the screen is split vertically and I see the interactive shell
  4. Insert an error into foo.hs, save and hit C-c C-c again
  5. See the error in the interactive haskell window
  6. Find the error and hit enter on top of it
  7. The screen is split horizontally even though the expected behavior would be to retain the existing split window configuration.

I'm trying to debug the Elisp code to understand why this happens.

Contributor

nurpax commented Jun 12, 2012

I'm on Emacs 24.1.

Contributor

nurpax commented Jun 12, 2012

I don't get it..

I added some debug prints into the window name search:

        (princ (find-if (lambda (window) (progn (princ (window-buffer window)) (equal (window-buffer window) buffer)))
                        (window-list)))

In my problematic case it does NOT print "Main.hs" "foo" as I would've expected, but "Main.hs" "Main.hs".

Contributor

nurpax commented Jun 12, 2012

I think I know what happens.

I have a vertically split windows with upper half being Main.hs and lower part being the interactive haskell window. When I see an error on the interactive window, I set cursor on top of the error and hit enter.

At this point haskell-interactive-jump-to-error-line is called. The erroneous file gets identified and the file is "find-file"'d:

           (when file
             (find-file file)
             (haskell-interactive-bring)

My previously focused window was the interactive shell, but find-file loads the errored .hs file and replaces the current interactive shell window with the newly loaded .hs file.

When haskell-interactive-bring gets called, two windows are open but neither of them is the interactive haskell window. Thus the horizontal split code gets always called.

Contributor

nurpax commented Jun 12, 2012

This makes it work as I think was intended:

diff --git a/haskell-interactive-mode.el b/haskell-interactive-mode.el
index 513422b..4368b81 100644
--- a/haskell-interactive-mode.el
+++ b/haskell-interactive-mode.el
@@ -191,6 +191,7 @@
                                ((file-exists-p cabal-relative-file-rel) 
                                 cabal-relative-file))))
                (when file
+                 (other-window 1)
                  (find-file file)
                  (haskell-interactive-bring)
                  (goto-line (string-to-number line))
Member

chrisdone commented Jun 12, 2012

Seems to work my good fellow!

chrisdone closed this in 2bc8278 Jun 12, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment