ghc-mod icon indicating copy to clipboard operation
ghc-mod copied to clipboard

buffer hanging when saving or changing buffer

Open leejaeyong7 opened this issue 11 years ago • 1 comments

Hi, I've recently started using ghc-mod and when configuring for my environment, found that the buffer hangs when I change buffer from any window to that of ghc-process enabled buffer. I've seen few issue sections with same errors, but couldn't find any solution regarding this issue.

I believe ghc-check-syntax is

When I look at minibuffer, it says that the error comes from ghc-check-syntax function. exact syntax:

ghc-check-syntax: ghc process may have hung or exited with an error

I believe ghc-check-syntax is triggered due to definition in ghc.el:

 (defadvice save-buffer (after ghc-check-syntax-on-save activate)
      "Check syntax with GHC when a haskell-mode buffer is saved."
      (when (eq 'haskell-mode major-mode) (ghc-check-syntax)))
 (defadvice switch-to-buffer (after ghc-check-syntax-on-switch-to-buffer activate)
      "Check syntax with GHC when switching to a haskell-mode buffer."
      (when (eq 'haskell-mode major-mode) (ghc-check-syntax))))

When I take a look at ghc-check-syntax function definition,

(defun ghc-check-syntax ()
  (interactive)
 ;; Only check syntax of visible buffers
 (when (get-buffer-window (current-buffer) t)
   (with-timeout
       (10 (error "ghc process may have hung or exited with an error"))
     (while ghc-process-running (sleep-for 0.1)))
   (ghc-with-process (ghc-check-send)
                     'ghc-check-callback
                     (lambda () (setq mode-line-process " -:-")))))

it calls (sleep-for 0.1) if ghc-process-running is true, and ghc-with-process with ghc-check-send / ghc-check-callback parameter. And when I look at ghc-with-process,

(defun ghc-with-process (cmd callback &optional hook1 hook2)
  (unless ghc-process-process-name
    (setq ghc-process-process-name (ghc-get-project-root)))
  (if ghc-process-running
    (error "ghc process already running")
    (progn
      (setq ghc-process-running t)
      (if hook1 (funcall hook1))
      (let* ((cbuf (current-buffer))
             (name ghc-process-process-name)
             (buf (get-buffer-create (concat " ghc-mod:" name)))
             (file (buffer-file-name))
             (cpro (get-process name)))
        (ghc-with-current-buffer buf
          (setq ghc-process-original-buffer cbuf)
          (setq ghc-process-original-file file)
          (setq ghc-process-callback callback)
          (setq ghc-process-hook hook2)
          (erase-buffer)
          (let ((pro (ghc-get-process cpro name buf)))
            (process-send-string pro cmd)
            (when ghc-debug
              (ghc-with-debug-buffer
               (insert (format "%% %s" cmd))))
            pro))))))

while ghc-with-process throw-out error if ghc-process is already running.

I can't figure out how to deal with this issue. Should I kill already running process when I check syntax? or is there an workaround?

Thanks in advance

leejaeyong7 avatar Aug 01 '15 00:08 leejaeyong7

I found that it can be fixed by creating .hs file using emacs. I don't know why it has been causing such errors but now that it is fixed, i'll close this issue

leejaeyong7 avatar Aug 01 '15 02:08 leejaeyong7