Skip to content

Commit

Permalink
(inferior-haskell-use-cabal): New custom var.
Browse files Browse the repository at this point in the history
Ignore-this: 4d006befacce0f8507f6fe1e68f0b7f7
(inferior-haskell-use-cabal): New custom var.
(inferior-haskell-cabal-of-buf): New fun.
(inferior-haskell-load-file): Use it to try and do the right thing in
multi-directory projects using a Cabal file.

darcs-hash:20070508200112-c2f2e-bcea30ad3157ee8c1a6c02a299d3def7ca480eb1.gz
  • Loading branch information
monnier committed May 8, 2007
1 parent 3b88c30 commit c7c6278
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,5 +1,13 @@
2007-05-08 Stefan Monnier <monnier@iro.umontreal.ca>

* inf-haskell.el (inferior-haskell-use-cabal): New custom var.
(inferior-haskell-cabal-of-buf): New fun.
(inferior-haskell-load-file): Use it to try and do the right thing in
multi-directory projects using a Cabal file.

* haskell-cabal.el (inferior-haskell-string-prefix-p)
(haskell-cabal-find-file): New functions.

* inf-haskell.el (inferior-haskell-string-to-strings):
Remove `separator' argument. Call split string without separator arg
either, so that it drops null strings.
Expand Down
5 changes: 5 additions & 0 deletions NEWS
@@ -1,5 +1,10 @@
Changes since 2.3:

* inf-haskell.el looks for a Cabal file to determine the root of a project.
If all works well, this will make C-c C-l automatically switch to the root
dir, so that dependencies in other directories are automatically found.
If it doesn't, complain and/or set inferior-haskell-use-cabal to nil.

* The new command haskell-hoogle helps you query Hoogle from Emacs.

Changes since 2.2:
Expand Down
36 changes: 29 additions & 7 deletions inf-haskell.el
Expand Up @@ -66,6 +66,10 @@ The command can include arguments."
"Regexps for error messages generated by inferior Haskell processes.
The format should be the same as for `compilation-error-regexp-alist'.")

(defcustom inferior-haskell-use-cabal t
"If non-nil, try and find a Cabal file to get the project root directory."
:type 'boolean)

(define-derived-mode inferior-haskell-mode comint-mode "Inf-Haskell"
"Major mode for interacting with an inferior Haskell process."
(set (make-local-variable 'comint-prompt-regexp)
Expand Down Expand Up @@ -170,22 +174,40 @@ The process PROC should be associated to a comint buffer."
(and (not (re-search-forward comint-prompt-regexp nil t))
(accept-process-output proc))))))

(defvar inferior-haskell-cabal-buffer nil)

(defun inferior-haskell-cabal-of-buf (buf)
(require 'haskell-cabal)
(with-current-buffer buf
(or inferior-haskell-cabal-buffer
(and (not (local-variable-p 'inferior-haskell-cabal-buffer))
(set (make-local-variable 'inferior-haskell-cabal-buffer)
(haskell-cabal-find-file))))))

;;;###autoload
(defun inferior-haskell-load-file (&optional reload)
"Pass the current buffer's file to the inferior haskell process."
(interactive)
;; Save first, so we're sure that `buffer-file-name' is non-nil afterward.
(save-buffer)
(let ((file buffer-file-name)
(let ((buf (current-buffer))
(file buffer-file-name)
(proc (inferior-haskell-process)))
(with-current-buffer (process-buffer proc)
;; Not sure if it's useful/needed and if it actually works.
;; (unless (equal (file-name-as-directory default-directory)
;; (file-name-directory file))
;; (inferior-haskell-send-string
;; proc (concat ":cd " (file-name-directory file) "\n")))
(compilation-forget-errors)
(let ((parsing-end (marker-position (process-mark proc))))
(let ((parsing-end (marker-position (process-mark proc)))
cabal)
;; Go to the root of the Cabal project, if applicable.
(when (and inferior-haskell-use-cabal
(setq cabal (inferior-haskell-cabal-of-buf buf)))
;; Not sure if it's useful/needed and if it actually works.
(unless (equal default-directory
(with-current-buffer cabal default-directory))
(setq default-directory
(with-current-buffer cabal default-directory))
(inferior-haskell-send-command
proc (concat ":cd " default-directory)))
(setq file (file-relative-name file)))
(inferior-haskell-send-command
proc (if reload ":reload" (concat ":load \"" file "\"")))
;; Move the parsing-end marker after sending the command so
Expand Down

0 comments on commit c7c6278

Please sign in to comment.