2010-11-15 03:46:55 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;;
|
|
|
|
;;; ghc-info.el
|
|
|
|
;;;
|
|
|
|
|
|
|
|
;; Author: Kazu Yamamoto <Kazu@Mew.org>
|
|
|
|
;; Created: Nov 15, 2010
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'ghc-func)
|
|
|
|
|
2010-11-15 05:46:59 +00:00
|
|
|
(defun ghc-show-type (&optional ask)
|
|
|
|
(interactive "P")
|
2010-11-15 03:46:55 +00:00
|
|
|
(if (not (ghc-which ghc-module-command))
|
|
|
|
(message "%s not found" ghc-module-command)
|
2010-11-17 08:07:33 +00:00
|
|
|
(let ((modname (ghc-find-module-name)))
|
|
|
|
(if (not modname)
|
|
|
|
(message "module should be specified")
|
|
|
|
(ghc-show-type0 ask modname)))))
|
|
|
|
|
|
|
|
(defun ghc-show-type0 (ask modname)
|
2012-01-23 06:12:24 +00:00
|
|
|
(let* ((expr0 (ghc-things-at-point))
|
2010-11-17 08:07:33 +00:00
|
|
|
(expr (if ask (ghc-read-expression expr0) expr0))
|
|
|
|
(cdir default-directory)
|
|
|
|
(file (buffer-name)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(cd cdir)
|
2011-11-15 11:40:25 +00:00
|
|
|
(apply 'call-process ghc-module-command nil t nil
|
|
|
|
`(,@(ghc-make-ghc-options) "type" ,file ,modname ,expr))
|
2010-11-17 08:07:33 +00:00
|
|
|
(message (buffer-substring (point-min) (1- (point-max)))))))
|
2010-11-15 03:46:55 +00:00
|
|
|
|
2010-11-15 05:46:59 +00:00
|
|
|
(defun ghc-show-info (&optional ask)
|
|
|
|
(interactive "P")
|
|
|
|
(if (not (ghc-which ghc-module-command))
|
|
|
|
(message "%s not found" ghc-module-command)
|
2010-11-17 08:07:33 +00:00
|
|
|
(let ((modname (ghc-find-module-name)))
|
|
|
|
(if (not modname)
|
|
|
|
(message "module should be specified")
|
|
|
|
(ghc-show-info0 ask modname)))))
|
|
|
|
|
|
|
|
(defun ghc-show-info0 (ask modname)
|
2012-01-23 06:12:24 +00:00
|
|
|
(let* ((expr0 (ghc-things-at-point))
|
2010-11-17 08:07:33 +00:00
|
|
|
(expr (if ask (ghc-read-expression expr0) expr0))
|
|
|
|
(cdir default-directory)
|
|
|
|
(file (buffer-name))
|
|
|
|
(buf (get-buffer-create ghc-error-buffer-name)))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(erase-buffer)
|
|
|
|
(insert
|
|
|
|
(with-temp-buffer
|
|
|
|
(cd cdir)
|
2011-11-15 11:40:25 +00:00
|
|
|
(apply 'call-process ghc-module-command nil t nil
|
|
|
|
`(,@(ghc-make-ghc-options) "info" ,file ,modname ,expr))
|
2010-11-17 08:07:33 +00:00
|
|
|
(buffer-substring (point-min) (1- (point-max))))))
|
|
|
|
(display-buffer buf)))
|
2010-11-15 05:46:59 +00:00
|
|
|
|
2012-02-12 16:01:58 +00:00
|
|
|
(defun ghc-show-annot (&optional ask)
|
|
|
|
(interactive "P")
|
|
|
|
(if (not (ghc-which ghc-module-command))
|
|
|
|
(message "%s not found" ghc-module-command)
|
|
|
|
(let ((modname (ghc-find-module-name)))
|
|
|
|
(if (not modname)
|
|
|
|
(message "module should be specified")
|
|
|
|
(ghc-show-annot0 ask modname)))))
|
|
|
|
|
|
|
|
(defvar *annot-point* 0)
|
|
|
|
(defvar *annot-ix* 0)
|
|
|
|
(defvar *annot-ovl* (make-overlay 0 0))
|
|
|
|
(overlay-put *annot-ovl* 'face 'region)
|
|
|
|
|
2012-02-12 16:25:49 +00:00
|
|
|
(defun delete-annot-ovl (beg end len)
|
|
|
|
(delete-overlay *annot-ovl*))
|
|
|
|
|
|
|
|
(setq after-change-functions
|
|
|
|
(cons 'delete-annot-ovl
|
|
|
|
after-change-functions))
|
|
|
|
|
2012-02-12 16:01:58 +00:00
|
|
|
(defun ghc-show-annot0 (ask modname)
|
|
|
|
(let* ((pt (point))
|
|
|
|
(ln (int-to-string (line-number-at-pos)))
|
|
|
|
(cn (int-to-string (current-column)))
|
|
|
|
(cdir default-directory)
|
|
|
|
(buf (current-buffer))
|
|
|
|
(file (buffer-name)))
|
|
|
|
(if (= *annot-point* pt)
|
|
|
|
(setq *annot-ix* (+ 1 *annot-ix*))
|
|
|
|
(progn
|
|
|
|
(setq *annot-point* pt)
|
|
|
|
(setq *annot-ix* 0)))
|
|
|
|
(save-excursion
|
|
|
|
(with-temp-buffer
|
|
|
|
(cd cdir)
|
|
|
|
(apply 'call-process ghc-module-command nil t nil
|
|
|
|
`(,@(ghc-make-ghc-options) "annot" ,file ,modname ,ln ,cn))
|
|
|
|
(let* ((types (read (buffer-substring (point-min) (1- (point-max)))))
|
|
|
|
(cix (mod *annot-ix* (length types)))
|
|
|
|
(tinfo (nth cix types))
|
|
|
|
(pos (nth 0 tinfo))
|
|
|
|
(type (nth 1 tinfo))
|
|
|
|
(left (ghc-get-pos buf (nth 0 pos) (nth 1 pos)))
|
|
|
|
(right (ghc-get-pos buf (nth 2 pos) (nth 3 pos))))
|
|
|
|
(move-overlay *annot-ovl* (- left 1) (- right 1) buf)
|
|
|
|
(message type))))))
|
|
|
|
|
|
|
|
(defun ghc-get-pos (buf line col)
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer buf)
|
|
|
|
(goto-line line)
|
|
|
|
(forward-char col)
|
|
|
|
(point)))
|
|
|
|
|
2010-11-15 05:46:59 +00:00
|
|
|
(defun ghc-read-expression (default)
|
2012-01-06 02:12:28 +00:00
|
|
|
(if default
|
|
|
|
(let ((prompt (format "Expression (%s): " default)))
|
|
|
|
(read-string prompt default nil))
|
|
|
|
(read-string "Expression: ")))
|
2010-11-15 05:46:59 +00:00
|
|
|
|
2010-11-17 08:07:33 +00:00
|
|
|
(defun ghc-find-module-name ()
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (re-search-forward "^module[ ]+\\([^ ]+\\)" nil t)
|
|
|
|
(match-string-no-properties 1))))
|
|
|
|
|
2010-11-15 03:46:55 +00:00
|
|
|
(provide 'ghc-info)
|