Refinement in Emacs ghc-mode
This commit is contained in:
parent
ae49eab547
commit
efe440438b
@ -11,6 +11,22 @@
|
|||||||
(require 'ghc-func)
|
(require 'ghc-func)
|
||||||
(require 'ghc-process)
|
(require 'ghc-process)
|
||||||
|
|
||||||
|
;; Common code for case splitting and refinement
|
||||||
|
|
||||||
|
(defun ghc-perform-rewriting (info)
|
||||||
|
(let* ((current-line (line-number-at-pos))
|
||||||
|
(begin-line (ghc-sinfo-get-beg-line info))
|
||||||
|
(begin-line-diff (+ 1 (- begin-line current-line)))
|
||||||
|
(begin-line-pos (line-beginning-position begin-line-diff))
|
||||||
|
(begin-pos (- (+ begin-line-pos (ghc-sinfo-get-beg-column info)) 1))
|
||||||
|
(end-line (ghc-sinfo-get-end-line info))
|
||||||
|
(end-line-diff (+ 1 (- end-line current-line)))
|
||||||
|
(end-line-pos (line-beginning-position end-line-diff))
|
||||||
|
(end-pos (- (+ end-line-pos (ghc-sinfo-get-end-column info)) 1)) )
|
||||||
|
(delete-region begin-pos end-pos)
|
||||||
|
(insert (ghc-sinfo-get-info info)) )
|
||||||
|
)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;
|
;;;
|
||||||
;;; Case splitting
|
;;; Case splitting
|
||||||
@ -23,17 +39,7 @@
|
|||||||
(let ((info (ghc-obtain-case-split)))
|
(let ((info (ghc-obtain-case-split)))
|
||||||
(if (null info)
|
(if (null info)
|
||||||
(message "Cannot split in cases")
|
(message "Cannot split in cases")
|
||||||
(let* ((current-line (line-number-at-pos))
|
(ghc-perform-rewriting info)) ))
|
||||||
(begin-line (ghc-sinfo-get-beg-line info))
|
|
||||||
(begin-line-diff (+ 1 (- begin-line current-line)))
|
|
||||||
(begin-line-pos (line-beginning-position begin-line-diff))
|
|
||||||
(begin-pos (- (+ begin-line-pos (ghc-sinfo-get-beg-column info)) 1))
|
|
||||||
(end-line (ghc-sinfo-get-end-line info))
|
|
||||||
(end-line-diff (+ 1 (- end-line current-line)))
|
|
||||||
(end-line-pos (line-beginning-position end-line-diff))
|
|
||||||
(end-pos (- (+ end-line-pos (ghc-sinfo-get-end-column info)) 1)) )
|
|
||||||
(delete-region begin-pos end-pos)
|
|
||||||
(insert (ghc-sinfo-get-info info)) ) )))
|
|
||||||
|
|
||||||
(defun ghc-obtain-case-split ()
|
(defun ghc-obtain-case-split ()
|
||||||
(let* ((ln (int-to-string (line-number-at-pos)))
|
(let* ((ln (int-to-string (line-number-at-pos)))
|
||||||
@ -42,6 +48,25 @@
|
|||||||
(cmd (format "split %s %s %s\n" file ln cn)))
|
(cmd (format "split %s %s %s\n" file ln cn)))
|
||||||
(ghc-sync-process cmd)))
|
(ghc-sync-process cmd)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Refinement
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(defun ghc-refine ()
|
||||||
|
(interactive)
|
||||||
|
(let ((info (ghc-obtain-refine (read-string "Refine with: "))))
|
||||||
|
(if (null info)
|
||||||
|
(message "Cannot refine")
|
||||||
|
(ghc-perform-rewriting info)) ))
|
||||||
|
|
||||||
|
(defun ghc-obtain-refine (expr)
|
||||||
|
(let* ((ln (int-to-string (line-number-at-pos)))
|
||||||
|
(cn (int-to-string (1+ (current-column))))
|
||||||
|
(file (buffer-file-name))
|
||||||
|
(cmd (format "refine %s %s %s %s\n" file ln cn expr)))
|
||||||
|
(ghc-sync-process cmd)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;
|
;;;
|
||||||
;;; Initial code from signature
|
;;; Initial code from signature
|
||||||
|
@ -73,8 +73,9 @@
|
|||||||
(defvar ghc-hoogle-key (format "\C-c%c" (ghc-find-C-h)))
|
(defvar ghc-hoogle-key (format "\C-c%c" (ghc-find-C-h)))
|
||||||
(defvar ghc-shallower-key "\C-c<")
|
(defvar ghc-shallower-key "\C-c<")
|
||||||
(defvar ghc-deeper-key "\C-c>")
|
(defvar ghc-deeper-key "\C-c>")
|
||||||
(defvar ghc-case-split-key "\C-c\C-p")
|
(defvar ghc-case-split-key "\C-c\C-s")
|
||||||
(defvar ghc-initial-sig-key "\C-c\C-s")
|
(defvar ghc-initial-sig-key "\C-c\C-g")
|
||||||
|
(defvar ghc-refine-key "\C-c\C-r")
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;
|
;;;
|
||||||
@ -109,6 +110,7 @@
|
|||||||
(define-key haskell-mode-map ghc-deeper-key 'ghc-make-indent-deeper)
|
(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-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-initial-sig-key 'ghc-initial-code-from-signature)
|
||||||
|
(define-key haskell-mode-map ghc-refine-key 'ghc-refine)
|
||||||
(ghc-comp-init)
|
(ghc-comp-init)
|
||||||
(setq ghc-initialized t))
|
(setq ghc-initialized t))
|
||||||
(ghc-import-module)
|
(ghc-import-module)
|
||||||
|
Loading…
Reference in New Issue
Block a user