From 5a968225c3f97422c8c4ee1d8efe8042b52f5aa9 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Tue, 17 Jun 2014 18:15:36 +0200 Subject: [PATCH] Initial skeleton for case split in elisp --- Language/Haskell/GhcMod/Info.hs | 5 ++++ elisp/Makefile | 2 +- elisp/ghc-rewrite.el | 42 +++++++++++++++++++++++++++++++++ elisp/ghc.el | 3 +++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 elisp/ghc-rewrite.el diff --git a/Language/Haskell/GhcMod/Info.hs b/Language/Haskell/GhcMod/Info.hs index d07e554..353b3ae 100644 --- a/Language/Haskell/GhcMod/Info.hs +++ b/Language/Haskell/GhcMod/Info.hs @@ -388,6 +388,11 @@ initialBodyArgs (FnArgFunction:xs) vs (f:fs) = f : initialBodyArgs xs vs fs initialBodyArgs (FnArgNormal:xs) (v:vs) fs = v : initialBodyArgs xs vs fs initialBodyArgs _ _ _ = error "This should never happen" -- Lists are infinite +-- Getting the initial body of function and instances differ +-- This is because for functions we only use the parsed file +-- (so the full file doesn't have to be type correct) +-- but for instances we need to get information about the class + initialFnBody :: DynFlags -> PprStyle -> G.HsType G.RdrName -> G.RdrName -> String initialFnBody dflag style ty name = let fname = showOccName dflag style $ occName name -- get function name diff --git a/elisp/Makefile b/elisp/Makefile index d77aed3..96bec8b 100644 --- a/elisp/Makefile +++ b/elisp/Makefile @@ -1,5 +1,5 @@ SRCS = ghc.el ghc-func.el ghc-doc.el ghc-comp.el ghc-check.el ghc-process.el \ - ghc-command.el ghc-info.el ghc-ins-mod.el ghc-indent.el + ghc-command.el ghc-info.el ghc-ins-mod.el ghc-indent.el ghc-rewrite.el EMACS = emacs DETECT = xemacs diff --git a/elisp/ghc-rewrite.el b/elisp/ghc-rewrite.el new file mode 100644 index 0000000..c3235c4 --- /dev/null +++ b/elisp/ghc-rewrite.el @@ -0,0 +1,42 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; ghc-rewrite.el +;;; + +;; Author: Alejandro Serrano +;; Created: Jun 17, 2014 + +;;; Code: + +(require 'ghc-func) +(require 'ghc-process) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; Case splitting +;;; + +(ghc-defstruct sinfo beg-line beg-column end-line end-column info) + +(defun ghc-case-split () + (interactive) + (let ((info (ghc-obtain-case-split))) + (if (null info) + (message "Cannot split in cases") + (let ((varinfo (car info)) + (declinfo (cadr info)) + (cases (caddr info))) + (message cases) + ) + ) + ) + ) + +(defun ghc-obtain-case-split () + (let* ((ln (int-to-string (line-number-at-pos))) + (cn (int-to-string (1+ (current-column)))) + (file (buffer-file-name)) + (cmd (format "split %s %s %s\n" file ln cn))) + (ghc-sync-process cmd))) + +(provide 'ghc-rewrite) diff --git a/elisp/ghc.el b/elisp/ghc.el index 50b3146..85c2c9d 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -40,6 +40,7 @@ (require 'ghc-command) (require 'ghc-ins-mod) (require 'ghc-indent) +(require 'ghc-rewrite) (require 'dabbrev) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -72,6 +73,7 @@ (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-p") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -104,6 +106,7 @@ (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) (ghc-comp-init) (setq ghc-initialized t)) (ghc-import-module)