M-t inserts module or undefine.
This commit is contained in:
parent
dc6424454e
commit
97b3de7328
@ -157,12 +157,15 @@
|
||||
(forward-line)
|
||||
(if (not (bolp)) (insert "\n")))
|
||||
(insert (match-string 1) " = undefined\n")))
|
||||
((string-match "Not in scope: `\\([^']+\\)'" data)
|
||||
(save-match-data
|
||||
(unless (re-search-forward "^$" nil t)
|
||||
(goto-char (point-max))
|
||||
(insert "\n")))
|
||||
(insert "\n" (match-string 1 data) " = undefined\n"))
|
||||
;; GHC 7.8 uses Unicode for single-quotes.
|
||||
((string-match "Not in scope: `\\([^'\n\0]+\\)'" data)
|
||||
(let ((sym (match-string 1 data)))
|
||||
(if (y-or-n-p (format "Import module for %s?" sym))
|
||||
(ghc-ins-mod sym)
|
||||
(unless (re-search-forward "^$" nil t)
|
||||
(goto-char (point-max))
|
||||
(insert "\n"))
|
||||
(insert "\n" (ghc-enclose sym) " = undefined\n"))))
|
||||
((string-match "Pattern match(es) are non-exhaustive" data)
|
||||
(let* ((fn (ghc-get-function-name))
|
||||
(arity (ghc-get-function-arity fn)))
|
||||
@ -175,7 +178,9 @@
|
||||
(let ((end (point)))
|
||||
(search-backward old nil t)
|
||||
(delete-region (point) end))
|
||||
(insert new))))))))
|
||||
(insert new))))
|
||||
(t
|
||||
(message "Nothing is done"))))))
|
||||
|
||||
(defun ghc-extract-type (str)
|
||||
(with-temp-buffer
|
||||
|
@ -197,4 +197,11 @@
|
||||
(insert (format "%% %s %s\n" cmd (mapconcat 'identity args " ")))
|
||||
(insert-buffer-substring cbuf)))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun ghc-enclose (expr)
|
||||
(if (string-match "^[a-zA-Z0-9_]$" expr)
|
||||
expr
|
||||
(concat "(" expr ")")))
|
||||
|
||||
(provide 'ghc-func)
|
||||
|
@ -6,6 +6,8 @@
|
||||
;; Author: Kazu Yamamoto <Kazu@Mew.org>
|
||||
;; Created: Dec 27, 2011
|
||||
|
||||
(require 'ghc-process)
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defvar ghc-ins-mod-rendezvous nil)
|
||||
@ -14,15 +16,16 @@
|
||||
(interactive)
|
||||
(let* ((expr0 (ghc-things-at-point))
|
||||
(expr (ghc-read-expression expr0)))
|
||||
(let ((mods (ghc-function-to-modules expr)))
|
||||
(if (null mods)
|
||||
(message "No module guessed")
|
||||
(let ((mod (ghc-completing-read "Module name (%s): " mods)))
|
||||
(save-excursion
|
||||
(ghc-goto-module-position)
|
||||
(if (string-match "^[a-zA-Z0-9_]$" expr)
|
||||
(insert "import " mod " (" expr ")\n")
|
||||
(insert "import " mod " ((" expr "))\n"))))))))
|
||||
(ghc-ins-mod expr)))
|
||||
|
||||
(defun ghc-ins-mod (expr)
|
||||
(let ((mods (ghc-function-to-modules expr)))
|
||||
(if (null mods)
|
||||
(message "No module guessed")
|
||||
(let ((mod (ghc-completing-read "Module name (%s): " mods)))
|
||||
(save-excursion
|
||||
(ghc-goto-module-position)
|
||||
(insert "import " mod " (" (ghc-enclose expr) ")\n"))))))
|
||||
|
||||
(defun ghc-completing-read (fmt lst)
|
||||
(let* ((def (car lst))
|
||||
@ -35,7 +38,12 @@
|
||||
(if (re-search-backward "^import" nil t)
|
||||
(ghc-goto-empty-line)
|
||||
(if (re-search-backward "^module" nil t)
|
||||
(ghc-goto-empty-line)
|
||||
(progn
|
||||
(ghc-goto-empty-line)
|
||||
(forward-line)
|
||||
(unless (eolp)
|
||||
(save-excursion
|
||||
(insert "\n"))))
|
||||
(goto-char (point-min)))))
|
||||
|
||||
(defun ghc-goto-empty-line ()
|
||||
|
Loading…
Reference in New Issue
Block a user