From eec141904078045e5e5211c4a372e7f1a8b50fae Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Tue, 12 Aug 2014 22:44:11 +0200 Subject: [PATCH] Make M-t run also code generation and case splitting Fixes #308 --- elisp/ghc-comp.el | 8 +++++--- elisp/ghc-rewrite.el | 34 ++++++++++++++++++++++++++++++---- elisp/ghc.el | 8 ++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/elisp/ghc-comp.el b/elisp/ghc-comp.el index dd40cf7..a8f067b 100644 --- a/elisp/ghc-comp.el +++ b/elisp/ghc-comp.el @@ -9,6 +9,7 @@ ;;; Code: (require 'ghc-func) +(require 'ghc-rewrite) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -124,9 +125,10 @@ unloaded modules are loaded") (defun ghc-complete () (interactive) - (if (ghc-should-scroll) - (ghc-scroll-completion-buffer) - (ghc-try-complete))) + (when (null (ghc-try-rewrite)) + (if (ghc-should-scroll) + (ghc-scroll-completion-buffer) + (ghc-try-complete)))) (defun ghc-should-scroll () (let ((window (ghc-completion-window))) diff --git a/elisp/ghc-rewrite.el b/elisp/ghc-rewrite.el index c861b94..01c87b2 100644 --- a/elisp/ghc-rewrite.el +++ b/elisp/ghc-rewrite.el @@ -31,6 +31,18 @@ (insert (ghc-sinfo-get-info info)) ) ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; Combined rewriting +;;; + +(defun ghc-try-rewrite () + "Try to apply initial code generation and case splitting" + (interactive) + (when (null (ghc-try-initial-code-from-signature)) + (ghc-try-case-split))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Case splitting @@ -41,9 +53,13 @@ (defun ghc-case-split () "Split the variable at point into its possible constructors" (interactive) + (when (null (ghc-try-case-split)) + (message "Cannot split into cases"))) + +(defun ghc-try-case-split () (let ((info (ghc-obtain-case-split))) (if (null info) - (message "Cannot split in cases") + '() (ghc-perform-rewriting info)) )) (defun ghc-obtain-case-split () @@ -61,10 +77,14 @@ (defun ghc-refine () "Refine a hole using a user-specified function" (interactive) + (when (null (ghc-try-refine)) + (message "Cannot refine"))) + +(defun ghc-try-refine () (let ((info (ghc-obtain-refine (read-string "Refine with: ")))) (if (null info) - (message "Cannot refine") - (ghc-perform-rewriting info)) )) + '() + (ghc-perform-rewriting info)) )) (defun ghc-obtain-refine (expr) (let* ((ln (int-to-string (line-number-at-pos))) @@ -144,11 +164,17 @@ (ghc-defstruct icsinfo sort pos fns) (defun ghc-initial-code-from-signature () + "Refine a hole using a user-specified function" + (interactive) + (when (null (ghc-try-initial-code-from-signature)) + (message "Cannot obtain initial code"))) + +(defun ghc-try-initial-code-from-signature () "Include initial code from a function signature or instance declaration" (interactive) (let ((info (ghc-obtain-initial-code-from-signature))) (if (null info) - (message "Cannot obtain initial code") + '() (let* ((ln-current (line-number-at-pos)) (sort (ghc-icsinfo-get-sort info)) (pos (ghc-icsinfo-get-pos info)) diff --git a/elisp/ghc.el b/elisp/ghc.el index 4b21304..5a196fb 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -73,8 +73,8 @@ (defvar ghc-hoogle-key (format "\C-c%c" (ghc-find-C-h))) (defvar ghc-shallower-key "\C-c<") (defvar ghc-deeper-key "\C-c>") -(defvar ghc-case-split-key "\C-c\C-s") -(defvar ghc-initial-sig-key "\C-c\C-g") +;(defvar ghc-case-split-key "\C-c\C-s") +;(defvar ghc-initial-sig-key "\C-c\C-g") (defvar ghc-refine-key "\C-c\C-f") (defvar ghc-auto-key "\C-c\C-a") (defvar ghc-prev-hole-key "\C-c\ep") @@ -111,8 +111,8 @@ (define-key haskell-mode-map ghc-hoogle-key 'haskell-hoogle) (define-key haskell-mode-map ghc-shallower-key 'ghc-make-indent-shallower) (define-key haskell-mode-map ghc-deeper-key 'ghc-make-indent-deeper) - (define-key haskell-mode-map ghc-case-split-key 'ghc-case-split) - (define-key haskell-mode-map ghc-initial-sig-key 'ghc-initial-code-from-signature) + ;(define-key haskell-mode-map ghc-case-split-key 'ghc-case-split) + ;(define-key haskell-mode-map ghc-initial-sig-key 'ghc-initial-code-from-signature) (define-key haskell-mode-map ghc-refine-key 'ghc-refine) (define-key haskell-mode-map ghc-auto-key 'ghc-auto) (define-key haskell-mode-map ghc-prev-hole-key 'ghc-goto-prev-hole)