From 97b3de7328328ad46f7d4995317c64ab445b2ef8 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Tue, 25 Mar 2014 14:58:20 +0900 Subject: [PATCH] M-t inserts module or undefine. --- elisp/ghc-check.el | 19 ++++++++++++------- elisp/ghc-func.el | 7 +++++++ elisp/ghc-ins-mod.el | 28 ++++++++++++++++++---------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/elisp/ghc-check.el b/elisp/ghc-check.el index 506878d..9369fe6 100644 --- a/elisp/ghc-check.el +++ b/elisp/ghc-check.el @@ -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 diff --git a/elisp/ghc-func.el b/elisp/ghc-func.el index 1c74451..b3d5491 100644 --- a/elisp/ghc-func.el +++ b/elisp/ghc-func.el @@ -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) diff --git a/elisp/ghc-ins-mod.el b/elisp/ghc-ins-mod.el index aef921f..6c1cc8e 100644 --- a/elisp/ghc-ins-mod.el +++ b/elisp/ghc-ins-mod.el @@ -6,6 +6,8 @@ ;; Author: Kazu Yamamoto ;; 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 ()