diff --git a/Language/Haskell/GhcMod/Rewrite.hs b/Language/Haskell/GhcMod/Rewrite.hs index db09f88..488fd38 100644 --- a/Language/Haskell/GhcMod/Rewrite.hs +++ b/Language/Haskell/GhcMod/Rewrite.hs @@ -252,7 +252,7 @@ initialBody fname args = arglist -> if isSymbolName fname then (head arglist) ++ " " ++ fname ++ " " ++ (intercalate " " (tail arglist)) else fname ++ " " ++ (intercalate " " arglist) - ++ " = _" ++ fname ++ "_body" + ++ " = " ++ (if isSymbolName fname then "" else '_':fname) ++ "_body" initialBodyArgs :: [FnArg] -> [String] -> [String] -> [String] initialBodyArgs [] _ _ = [] diff --git a/elisp/ghc-rewrite.el b/elisp/ghc-rewrite.el index c3235c4..2354b4d 100644 --- a/elisp/ghc-rewrite.el +++ b/elisp/ghc-rewrite.el @@ -39,4 +39,31 @@ (cmd (format "split %s %s %s\n" file ln cn))) (ghc-sync-process cmd))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; Initial code from signature +;;; + +(defun ghc-initial-code-from-signature () + (interactive) + (let ((info (ghc-obtain-initial-code-from-signature))) + (if (null info) + (message "Cannot obtain initial code") + (let* ((ln-current (line-number-at-pos)) + (pos (car info)) + (ln-end (ghc-sinfo-get-end-line pos)) + (ln-diff (+ 1 (- ln-end ln-current))) + (fns-to-insert (cadr info))) + (goto-char (line-end-position ln-diff)) + (dolist (fn-to-insert fns-to-insert) + (newline-and-indent) + (insert fn-to-insert)))))) + +(defun ghc-obtain-initial-code-from-signature () + (let* ((ln (int-to-string (line-number-at-pos))) + (cn (int-to-string (1+ (current-column)))) + (file (buffer-file-name)) + (cmd (format "sig %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 85c2c9d..5640dad 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -74,6 +74,7 @@ (defvar ghc-shallower-key "\C-c<") (defvar ghc-deeper-key "\C-c>") (defvar ghc-case-split-key "\C-c\C-p") +(defvar ghc-initial-sig-key "\C-c\C-s") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -107,6 +108,7 @@ (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) (ghc-comp-init) (setq ghc-initialized t)) (ghc-import-module)