haskell-process-set-response-cursor: Wrong type argument: consp, nil #117

Closed
Mikolaj opened this Issue Jan 27, 2013 · 28 comments

Projects

None yet

6 participants

@Mikolaj
Member
Mikolaj commented Jan 27, 2013

When I issue

M-x haskell-process-clear

(or mistakenly hit 'y' when asked about starting a new project and then input the directory) I get

haskell-process-set-response-cursor: Wrong type argument: consp, nil

and then I get it every time I try to compile (haskell-process-cabal-build). I have to restart emacs to make it work again.

@gregorycollins
Member

I get this too. So annoying! Especially since haskell-mode decides to randomly interrupt me when I'm typing in order to present the dialog, and sometimes the keystroke you enter isn't the right one, and then oops your session is borked.

I've looked into it a little bit but haven't quite figured out why it happens yet.

@nurpax
Contributor
nurpax commented Jan 27, 2013

+1!

@jubos
jubos commented Jan 28, 2013

I think I am encountering this issue as well.

@chrisdone chrisdone was assigned Jan 29, 2013
@chrisdone
Member

I'll fix it today.

@chrisdone
Member

That should do the trick.

@gregorycollins FWIW the problem starts in

(defun haskell-session ()
  "Get the Haskell session, prompt if there isn't one or fail."
  (or (haskell-session-maybe)
      (haskell-session-assign
       (or (haskell-session-from-buffer)
           (haskell-session-new-assume-from-cabal)
           (haskell-session-choose)
           (haskell-session-new)))))

Which is the function called to get the current session whenever it's needed (that's why it sometimes interrupts you for things that need a session, like the space key (for showing :i output in the minibuffer and import completion)), but for an already open project it's supposed to be able to guess it from the current buffer's path, which is here:

(defun haskell-session-from-buffer ()
  "Get the session based on the buffer."
  (when (buffer-file-name)
    (let ((sessions (remove-if-not (lambda (session)
                                     (haskell-is-prefix-of (file-name-directory (buffer-file-name))
                                                           (haskell-session-cabal-dir session)))
                                   haskell-sessions)))
      (sort sessions (lambda (a b) (< (length (haskell-session-cabal-dir a))
                                      (length (haskell-session-cabal-dir b)))))
      (when (consp sessions)
        (car sessions)))))

But (and this seems to have changed since I've written it, either as the result of patches applied to the project or Emacs update, otherwise this never would've worked) the haskell-session-cabal-dir is now something like ~/Projects/blah as opposed to the full-path, which the buffer gets, which is more like /home/chris/Projects/blah. So this patch just ensures that anything assigned as the paths of the current session are absolute.

@gregorycollins
Member

@chrisdone can you somehow fix the "it randomly interrupts you" problem?

@chrisdone
Member

Well, you're getting interrupted by running a command that uses (haskell-session), I'm guessing that you have SPC bound to haskell-mode-contextual-space and that's what's particularly annoying. So you could unbind that if you don't care about its functionality. But probably the better solution is to wrap it with a check that if the session is nil, just don't do anything.

@chrisdone
Member

E.g.

(defun haskell-mode-contextual-space ()
  "Contextually do clever stuff when hitting space."
  (interactive)
  (if (not (haskell-session-maybe))
      (self-insert-command 1)
    (cond ((save-excursion (forward-word -1)
                           (looking-at "^import$"))
           (insert " ")
           (let ((module (ido-completing-read "Module: " (haskell-session-all-modules))))
             (insert module)
             (haskell-mode-format-imports)))
          ((not (string= "" (save-excursion (forward-char -1) (haskell-ident-at-point))))
           (let ((ident (save-excursion (forward-char -1) (haskell-ident-at-point))))
             (insert " ")
             (haskell-process-do-try-info ident)))
          (t (insert " ")))))

If that fixes your problem, I can apply that.

@gregorycollins
Member

This version of haskell-mode-contextual-space didn't seem to do much for
me, sadly (I am still getting the "wrong type argument consp nil").

On Tue, Jan 29, 2013 at 1:53 PM, Chris Done notifications@github.comwrote:

E.g.

(defun haskell-mode-contextual-space ()
"Contextually do clever stuff when hitting space."
(interactive)
(if (not (haskell-session-maybe))
(self-insert-command 1)
(cond ((save-excursion (forward-word -1)
(looking-at "^import$"))
(insert " ")
(let ((module (ido-completing-read "Module: " (haskell-session-all-modules))))
(insert module)
(haskell-mode-format-imports)))
((not (string= "" (save-excursion (forward-char -1) (haskell-ident-at-point))))
(let ((ident (save-excursion (forward-char -1) (haskell-ident-at-point))))
(insert " ")
(haskell-process-do-try-info ident)))
(t (insert " ")))))

If that fixes your problem, I can apply that.


Reply to this email directly or view it on GitHubhttps://github.com/haskell/haskell-mode/issues/117#issuecomment-12835219.

Gregory Collins greg@gregorycollins.net

@gregorycollins
Member

That said, it's better than it was so I'll check that version in.

On Wed, Jan 30, 2013 at 12:14 AM, Gregory Collins
greg@gregorycollins.netwrote:

This version of haskell-mode-contextual-space didn't seem to do much for
me, sadly (I am still getting the "wrong type argument consp nil").

On Tue, Jan 29, 2013 at 1:53 PM, Chris Done notifications@github.comwrote:

E.g.

(defun haskell-mode-contextual-space ()
"Contextually do clever stuff when hitting space."
(interactive)
(if (not (haskell-session-maybe))
(self-insert-command 1)
(cond ((save-excursion (forward-word -1)
(looking-at "^import$"))
(insert " ")
(let ((module (ido-completing-read "Module: " (haskell-session-all-modules))))
(insert module)
(haskell-mode-format-imports)))
((not (string= "" (save-excursion (forward-char -1) (haskell-ident-at-point))))
(let ((ident (save-excursion (forward-char -1) (haskell-ident-at-point))))
(insert " ")
(haskell-process-do-try-info ident)))
(t (insert " ")))))

If that fixes your problem, I can apply that.


Reply to this email directly or view it on GitHubhttps://github.com/haskell/haskell-mode/issues/117#issuecomment-12835219.

Gregory Collins greg@gregorycollins.net

Gregory Collins greg@gregorycollins.net

@chrisdone
Member

“wrong type argument consp nil” wasn't fixed by 00f22bd? Did you restart emacs?

@gregorycollins
Member

I haven't encountered it since a restart. I'm not sure this patch makes it
impossible to get back into that state, however. It would be nice to have a
function to reset the whole subsystem and clean up all of the data
structures in use.

On Tue, Jan 29, 2013 at 11:18 PM, Chris Done notifications@github.comwrote:

“wrong type argument consp nil” wasn't fixed by 00f22bdhttps://github.com/haskell/haskell-mode/commit/00f22bd?
Did you restart emacs?


Reply to this email directly or view it on GitHubhttps://github.com/haskell/haskell-mode/issues/117#issuecomment-12877390.

Gregory Collins greg@gregorycollins.net

@Mikolaj
Member
Mikolaj commented Feb 21, 2013

I confirm that "M-x haskell-process-clear" does not break any more. However, when it keeps asking me about starting a new process and I hit 'y' by mistake, I still get "Wrong type argument: consp, nil" and the session is trashed and any subsequent "M-x haskell-process-clear" causes "Wrong type argument: consp, nil".

BTW, as reported in #124, I'm not getting the interruptions to start a new project if I load files by hand (as opposed to loading a bunch via emacs.desktop or emacs command line).

@Mikolaj
Member
Mikolaj commented Feb 21, 2013

Could everybody interested verify that the problem persists if you use no symbolic links in the paths of the files edited with emacs? I can't reproduce it any more when I use direct paths, with no links, see #124. If that's the same for everybody, I guess we can try to improve the code to cope with symbolic links, but we can alternatively write this down in a FAQ or other docs and I'd be happy to close the issue then.

@chrisdone
Member

Marking as P1 for 13.6.

@chrisdone
Member

Does this still happen to you, @Mikolaj?

@Mikolaj
Member
Mikolaj commented May 25, 2013

@chrisdone: I can't tell, because with the current master I can't confirm the dialog

Cabal dir (guessed from ../LambdaHack.cabal): .../mikolaj/repos/LambdaHack/

It just interprets Enter by moving the cursor to the new line. GNU Emacs 24.2.1. When I revert last 2 commits, it gets back to normal.

@chrisdone
Member

Try hitting return twice?

@Mikolaj
Member
Mikolaj commented May 25, 2013

@chrisdone: it then creates 2 empty lines below the prompt. :) But now I'm at cdb3637, after reverting two commits, and Enter works fine. Note that this may be a crazy interaction with the mad things in

https://github.com/Mikolaj/mydotflies/blob/master/.emacs

@chrisdone
Member

Well I'm using ido-read-directory-name. Try M-: (ido-read-directory-name "Test").

@Mikolaj
Member
Mikolaj commented May 26, 2013

@chrisdone: Yes, that's exactly what fails (and I reverted the commits, so this probably has nothing to do with any haskell-mode code). Even with 'emacs -Q' I get

Test.../Game/LambdaHack/Common/

and "test is read only", when I try to modify the path, and Enter just adds new lines and I can't get rid of the text in the minibuffer. I will update emacs in my Ubuntu and see what happens.

@Mikolaj
Member
Mikolaj commented May 26, 2013

@chrisdone: Nope, the upgrade didn't help, it still fails even with 'emacs -Q'. :< (upgrade from 24.2+1-1ppa1precise7 to emacs24-bin-common_24.3+1-1ppa1precise1)

@hvr
Member
hvr commented May 26, 2013

btw/fyi, org-mode uses a defcustom org-completion-use-ido for selecting whether to use ido completion. (and there's also a org-completion-use-iswitchb setting which is mutually exclusive to org-compleition-use-ido)

@chrisdone
Member

I'm specifically using ido because it handles path slashes. It's strange that it doesn't work on any Emacs, it's a pretty standard function.

@hvr
Member
hvr commented May 26, 2013

...have you actually tried ido-read-directory-name w/o having ido-mode active? :-)

@chrisdone
Member

Nope.

@chrisdone
Member

@Mikolaj Try master now.

@Mikolaj
Member
Mikolaj commented May 26, 2013

@chrisdone: thanks, it works great now. Moreover, the original problem is gone and the problem with starting compilation with files with symlinks in paths is gone. Closing the issue.

@Mikolaj Mikolaj closed this May 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment