Showing type of an identifier at point

Ignore-this: 40b69923375d0ccdf6b1a98891b1bca6

darcs-hash:20120801020653-33bd9-7e0a38b19718bfe0965d9570388f9f5cb74dda48
This commit is contained in:
wojciech.meyer 2012-08-01 04:06:53 +02:00
parent 354b6d774a
commit ee65d72abd
1 changed files with 45 additions and 0 deletions

View File

@ -328,6 +328,51 @@ it is started."
(setq lines (cdr lines)))
(utop-send-string "end:\n")))
(defun utop-last-type ()
"Extract last inferred type from the uTop toplevel"
(with-current-buffer utop-buffer-name
(save-excursion
(goto-char utop-prompt-min)
(forward-line -1)
(let ((line (replace-in-string (thing-at-point 'line) "\n" "")))
(set-text-properties 0 (length line) nil line)
(message line)))))
;; Poor man's identifier at point
(defun utop-ident-looking (backward)
"Find limits of an OCaml identifier"
(save-excursion
(skip-chars-forward " \n\t")
(let ((iterating t)
(start-pos (point))
end-pos)
(while iterating
(setq end-pos (point))
(if (not backward)
(progn
(right-word 1)
(setq iterating (not (looking-back "[ \t\r\n].*" start-pos))))
(progn
(left-word 1)
(setq iterating (not (save-excursion
(search-forward-regexp "[ \t\r\n].*" start-pos t)))))))
end-pos)))
(defun utop-ident-at-point ()
"Identifier at point"
(let ((start-pos (utop-ident-looking t))
(end-pos (utop-ident-looking nil)))
(buffer-substring-no-properties start-pos end-pos)))
; Currently not working - the communication is asynchronous so how to
; make sure without implementing another state that the type
; information has been already printed?
(defun utop-type-at-point ()
"Find type of an identifier at point from uTop"
(utop-eval-string (utop-ident-at-point))
; (utop-last-type)
)
;; +-----------------------------------------------------------------+
;; | Edition control |
;; +-----------------------------------------------------------------+