2003-04-01 17:32:09 -08:00
|
|
|
;(***********************************************************************)
|
|
|
|
;(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
;(* OCaml *)
|
2003-04-01 17:32:09 -08:00
|
|
|
;(* *)
|
|
|
|
;(* Damien Doligez, projet Moscova, INRIA Rocquencourt *)
|
|
|
|
;(* *)
|
|
|
|
;(* Copyright 2003 Institut National de Recherche en Informatique et *)
|
|
|
|
;(* en Automatique. All rights reserved. This file is distributed *)
|
2004-08-20 10:04:35 -07:00
|
|
|
;(* under the terms of the GNU General Public License. *)
|
2003-04-01 17:32:09 -08:00
|
|
|
;(* *)
|
|
|
|
;(***********************************************************************)
|
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
; An emacs-lisp complement to the "-annot" option of ocamlc and ocamlopt.
|
2003-06-12 05:52:17 -07:00
|
|
|
|
2003-07-28 11:06:49 -07:00
|
|
|
;; XEmacs compatibility
|
|
|
|
|
2003-07-28 23:54:28 -07:00
|
|
|
(eval-and-compile
|
2008-07-29 08:42:44 -07:00
|
|
|
(if (and (boundp 'running-xemacs) running-xemacs)
|
2003-07-28 23:54:28 -07:00
|
|
|
(require 'caml-xemacs)
|
|
|
|
(require 'caml-emacs)))
|
2003-06-12 05:52:17 -07:00
|
|
|
|
2003-10-10 06:25:38 -07:00
|
|
|
|
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
(defvar caml-types-location-re nil "Regexp to parse *.annot files.
|
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
Annotation files *.annot may be generated with the \"-annot\" option
|
|
|
|
of ocamlc and ocamlopt.
|
2003-07-24 01:46:52 -07:00
|
|
|
|
|
|
|
Their format is:
|
2003-06-12 05:52:17 -07:00
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
file ::= block *
|
|
|
|
block ::= position <SP> position <LF> annotation *
|
|
|
|
position ::= filename <SP> num <SP> num <SP> num
|
2007-05-16 01:21:41 -07:00
|
|
|
annotation ::= keyword open-paren <LF> <SP> <SP> data <LF> close-paren <LF>
|
2003-06-12 05:52:17 -07:00
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
<SP> is a space character (ASCII 0x20)
|
|
|
|
<LF> is a line-feed character (ASCII 0x0A)
|
|
|
|
num is a sequence of decimal digits
|
2012-02-10 08:15:24 -08:00
|
|
|
filename is a string with the lexical conventions of OCaml
|
2003-07-24 01:46:52 -07:00
|
|
|
open-paren is an open parenthesis (ASCII 0x28)
|
|
|
|
close-paren is a closed parenthesis (ASCII 0x29)
|
|
|
|
data is any sequence of characters where <LF> is always followed by
|
|
|
|
at least two space characters.
|
2003-06-12 05:52:17 -07:00
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
- in each block, the two positions are respectively the start and the
|
2007-02-09 05:31:15 -08:00
|
|
|
end of the range described by the block.
|
2003-07-24 01:46:52 -07:00
|
|
|
- in a position, the filename is the name of the file, the first num
|
|
|
|
is the line number, the second num is the offset of the beginning
|
|
|
|
of the line, the third num is the offset of the position itself.
|
|
|
|
- the char number within the line is the difference between the third
|
|
|
|
and second nums.
|
2003-06-12 05:52:17 -07:00
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
The current list of keywords is:
|
|
|
|
type call ident"
|
2003-07-24 01:46:52 -07:00
|
|
|
)
|
2003-06-12 05:52:17 -07:00
|
|
|
|
2013-03-22 11:19:21 -07:00
|
|
|
(defvar caml-types-position-re nil)
|
|
|
|
|
2003-04-03 05:59:38 -08:00
|
|
|
(let* ((caml-types-filename-re "\"\\(\\([^\\\"]\\|\\\\.\\)*\\)\"")
|
2007-05-16 01:21:41 -07:00
|
|
|
(caml-types-number-re "\\([0-9]*\\)"))
|
|
|
|
(setq caml-types-position-re
|
2003-04-03 05:59:38 -08:00
|
|
|
(concat caml-types-filename-re " "
|
|
|
|
caml-types-number-re " "
|
|
|
|
caml-types-number-re " "
|
2007-05-16 01:21:41 -07:00
|
|
|
caml-types-number-re))
|
2003-07-24 07:16:26 -07:00
|
|
|
(setq caml-types-location-re
|
|
|
|
(concat "^" caml-types-position-re " " caml-types-position-re)))
|
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
(defvar caml-types-expr-ovl (make-overlay 1 1))
|
2007-05-16 01:21:41 -07:00
|
|
|
(make-face 'caml-types-expr-face)
|
|
|
|
(set-face-doc-string 'caml-types-expr-face
|
2003-07-24 07:16:26 -07:00
|
|
|
"face for hilighting expressions and types")
|
2007-05-16 01:21:41 -07:00
|
|
|
(if (not (face-differs-from-default-p 'caml-types-expr-face))
|
|
|
|
(set-face-background 'caml-types-expr-face "#88FF44"))
|
|
|
|
(overlay-put caml-types-expr-ovl 'face 'caml-types-expr-face)
|
2003-07-24 07:16:26 -07:00
|
|
|
|
2003-09-05 11:01:46 -07:00
|
|
|
(defvar caml-types-typed-ovl (make-overlay 1 1))
|
|
|
|
(make-face 'caml-types-typed-face)
|
|
|
|
(set-face-doc-string 'caml-types-typed-face
|
2003-07-29 09:44:56 -07:00
|
|
|
"face for hilighting typed expressions")
|
2003-09-05 11:01:46 -07:00
|
|
|
(if (not (face-differs-from-default-p 'caml-types-typed-face))
|
|
|
|
(set-face-background 'caml-types-typed-face "#FF8844"))
|
|
|
|
(overlay-put caml-types-typed-ovl 'face 'caml-types-typed-face)
|
2003-04-01 17:32:09 -08:00
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
(defvar caml-types-scope-ovl (make-overlay 1 1))
|
|
|
|
(make-face 'caml-types-scope-face)
|
|
|
|
(set-face-doc-string 'caml-types-scope-face
|
|
|
|
"face for hilighting variable scopes")
|
|
|
|
(if (not (face-differs-from-default-p 'caml-types-scope-face))
|
|
|
|
(set-face-background 'caml-types-scope-face "#BBFFFF"))
|
|
|
|
(overlay-put caml-types-scope-ovl 'face 'caml-types-scope-face)
|
|
|
|
|
|
|
|
(defvar caml-types-def-ovl (make-overlay 1 1))
|
|
|
|
(make-face 'caml-types-def-face)
|
|
|
|
(set-face-doc-string 'caml-types-def-face
|
|
|
|
"face for hilighting binding occurrences")
|
|
|
|
(if (not (face-differs-from-default-p 'caml-types-def-face))
|
|
|
|
(set-face-background 'caml-types-def-face "#FF4444"))
|
|
|
|
(overlay-put caml-types-def-ovl 'face 'caml-types-def-face)
|
|
|
|
|
|
|
|
(defvar caml-types-occ-ovl (make-overlay 1 1))
|
|
|
|
(make-face 'caml-types-occ-face)
|
|
|
|
(set-face-doc-string 'caml-types-occ-face
|
|
|
|
"face for hilighting variable occurrences")
|
|
|
|
(if (not (face-differs-from-default-p 'caml-types-occ-face))
|
|
|
|
(set-face-background 'caml-types-occ-face "#44FF44"))
|
|
|
|
(overlay-put caml-types-occ-ovl 'face 'caml-types-occ-face)
|
|
|
|
|
2003-07-25 10:59:59 -07:00
|
|
|
|
2003-07-28 08:19:15 -07:00
|
|
|
(defvar caml-types-annotation-tree nil)
|
|
|
|
(defvar caml-types-annotation-date nil)
|
2003-07-25 10:59:59 -07:00
|
|
|
(make-variable-buffer-local 'caml-types-annotation-tree)
|
|
|
|
(make-variable-buffer-local 'caml-types-annotation-date)
|
|
|
|
|
2003-07-28 08:19:15 -07:00
|
|
|
(defvar caml-types-buffer-name "*caml-types*"
|
|
|
|
"Name of buffer for diplaying caml types")
|
|
|
|
(defvar caml-types-buffer nil
|
|
|
|
"buffer for diplaying caml types")
|
2003-07-25 10:59:59 -07:00
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
(defun caml-types-show-type (arg)
|
2003-07-23 07:20:33 -07:00
|
|
|
"Show the type of expression or pattern at point.
|
|
|
|
The smallest expression or pattern that contains point is
|
|
|
|
temporarily highlighted. Its type is highlighted in the .annot
|
|
|
|
file and the mark is set to the beginning of the type.
|
|
|
|
The type is also displayed in the mini-buffer.
|
|
|
|
|
|
|
|
Hints on using the type display:
|
|
|
|
. If you want the type of an identifier, put point within any
|
|
|
|
occurrence of this identifier.
|
|
|
|
. If you want the result type of a function application, put point
|
|
|
|
at the first space after the function name.
|
|
|
|
. If you want the type of a list, put point on a bracket, on a
|
|
|
|
semicolon, or on the :: constructor.
|
|
|
|
. Even if type checking fails, you can still look at the types
|
2003-07-24 01:46:52 -07:00
|
|
|
in the file, up to where the type checker failed.
|
|
|
|
|
2005-03-24 09:20:54 -08:00
|
|
|
Types are also displayed in the buffer *caml-types*, which is
|
2008-07-29 08:42:44 -07:00
|
|
|
displayed when the command is called with Prefix argument 4.
|
2003-07-28 11:06:49 -07:00
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
See also `caml-types-explore' for exploration by mouse dragging.
|
|
|
|
See `caml-types-location-re' for annotation file format.
|
|
|
|
"
|
|
|
|
(interactive "p")
|
2003-04-03 05:59:38 -08:00
|
|
|
(let* ((target-buf (current-buffer))
|
2003-04-02 08:39:59 -08:00
|
|
|
(target-file (file-name-nondirectory (buffer-file-name)))
|
2003-07-28 23:54:28 -07:00
|
|
|
(target-line (1+ (count-lines (point-min)
|
|
|
|
(caml-line-beginning-position))))
|
|
|
|
(target-bol (caml-line-beginning-position))
|
2008-01-11 08:13:18 -08:00
|
|
|
(target-cnum (point)))
|
|
|
|
(caml-types-preprocess (buffer-file-name))
|
2005-08-13 13:59:37 -07:00
|
|
|
(setq caml-types-buffer (get-buffer-create caml-types-buffer-name))
|
2003-07-25 10:59:59 -07:00
|
|
|
(let* ((targ-loc (vector target-file target-line target-bol target-cnum))
|
2007-05-16 01:21:41 -07:00
|
|
|
(node (caml-types-find-location targ-loc "type" ()
|
2003-07-25 10:59:59 -07:00
|
|
|
caml-types-annotation-tree)))
|
|
|
|
(cond
|
|
|
|
((null node)
|
2005-08-13 13:59:37 -07:00
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
(message "Point is not within a typechecked expression or pattern."))
|
2003-07-25 10:59:59 -07:00
|
|
|
(t
|
|
|
|
(let ((left (caml-types-get-pos target-buf (elt node 0)))
|
|
|
|
(right (caml-types-get-pos target-buf (elt node 1)))
|
2007-05-16 01:21:41 -07:00
|
|
|
(type (cdr (assoc "type" (elt node 2)))))
|
2003-07-25 10:59:59 -07:00
|
|
|
(move-overlay caml-types-expr-ovl left right target-buf)
|
2003-07-28 08:19:15 -07:00
|
|
|
(with-current-buffer caml-types-buffer
|
|
|
|
(erase-buffer)
|
|
|
|
(insert type)
|
|
|
|
(message (format "type: %s" type)))
|
|
|
|
))))
|
2003-07-25 10:59:59 -07:00
|
|
|
(if (and (= arg 4)
|
2003-07-28 08:19:15 -07:00
|
|
|
(not (window-live-p (get-buffer-window caml-types-buffer))))
|
|
|
|
(display-buffer caml-types-buffer))
|
2003-07-25 10:59:59 -07:00
|
|
|
(unwind-protect
|
2003-10-20 05:06:42 -07:00
|
|
|
(caml-sit-for 60)
|
2003-09-05 11:01:46 -07:00
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
)))
|
2003-07-25 10:59:59 -07:00
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
(defun caml-types-show-call (arg)
|
|
|
|
"Show the kind of call at point.
|
|
|
|
The smallest function call that contains point is
|
|
|
|
temporarily highlighted. Its kind is highlighted in the .annot
|
|
|
|
file and the mark is set to the beginning of the kind.
|
|
|
|
The kind is also displayed in the mini-buffer.
|
|
|
|
|
|
|
|
The kind is also displayed in the buffer *caml-types*, which is
|
2008-07-29 08:42:44 -07:00
|
|
|
displayed when the command is called with Prefix argument 4.
|
2007-05-16 01:21:41 -07:00
|
|
|
|
|
|
|
See `caml-types-location-re' for annotation file format.
|
|
|
|
"
|
|
|
|
(interactive "p")
|
|
|
|
(let* ((target-buf (current-buffer))
|
|
|
|
(target-file (file-name-nondirectory (buffer-file-name)))
|
|
|
|
(target-line (1+ (count-lines (point-min)
|
|
|
|
(caml-line-beginning-position))))
|
|
|
|
(target-bol (caml-line-beginning-position))
|
2008-07-29 08:49:31 -07:00
|
|
|
(target-cnum (point)))
|
|
|
|
(caml-types-preprocess (buffer-file-name))
|
2007-05-16 01:21:41 -07:00
|
|
|
(setq caml-types-buffer (get-buffer-create caml-types-buffer-name))
|
|
|
|
(let* ((targ-loc (vector target-file target-line target-bol target-cnum))
|
|
|
|
(node (caml-types-find-location targ-loc "call" ()
|
|
|
|
caml-types-annotation-tree)))
|
|
|
|
(cond
|
|
|
|
((null node)
|
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
(message "Point is not within a function call."))
|
|
|
|
(t
|
|
|
|
(let ((left (caml-types-get-pos target-buf (elt node 0)))
|
|
|
|
(right (caml-types-get-pos target-buf (elt node 1)))
|
|
|
|
(kind (cdr (assoc "call" (elt node 2)))))
|
|
|
|
(move-overlay caml-types-expr-ovl left right target-buf)
|
|
|
|
(with-current-buffer caml-types-buffer
|
|
|
|
(erase-buffer)
|
|
|
|
(insert kind)
|
|
|
|
(message (format "%s call" kind)))
|
|
|
|
))))
|
|
|
|
(if (and (= arg 4)
|
|
|
|
(not (window-live-p (get-buffer-window caml-types-buffer))))
|
|
|
|
(display-buffer caml-types-buffer))
|
|
|
|
(unwind-protect
|
|
|
|
(caml-sit-for 60)
|
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
)))
|
|
|
|
|
|
|
|
(defun caml-types-show-ident (arg)
|
2008-07-29 08:42:44 -07:00
|
|
|
"Show the binding of identifier at point.
|
2007-10-08 05:27:15 -07:00
|
|
|
The identifier that contains point is
|
2008-07-29 08:42:44 -07:00
|
|
|
temporarily highlighted. Its binding is highlighted in the .annot
|
|
|
|
file and the mark is set to the beginning of the binding.
|
|
|
|
The binding is also displayed in the mini-buffer.
|
2007-05-16 01:21:41 -07:00
|
|
|
|
2008-07-29 08:42:44 -07:00
|
|
|
The binding is also displayed in the buffer *caml-types*, which is
|
|
|
|
displayed when the command is called with Prefix argument 4.
|
2007-05-16 01:21:41 -07:00
|
|
|
|
|
|
|
See `caml-types-location-re' for annotation file format.
|
|
|
|
"
|
|
|
|
(interactive "p")
|
|
|
|
(let* ((target-buf (current-buffer))
|
|
|
|
(target-file (file-name-nondirectory (buffer-file-name)))
|
|
|
|
(target-line (1+ (count-lines (point-min)
|
|
|
|
(caml-line-beginning-position))))
|
|
|
|
(target-bol (caml-line-beginning-position))
|
2008-07-29 08:49:31 -07:00
|
|
|
(target-cnum (point)))
|
|
|
|
(caml-types-preprocess (buffer-file-name))
|
2007-05-16 01:21:41 -07:00
|
|
|
(setq caml-types-buffer (get-buffer-create caml-types-buffer-name))
|
|
|
|
(let* ((targ-loc (vector target-file target-line target-bol target-cnum))
|
|
|
|
(node (caml-types-find-location targ-loc "ident" ()
|
|
|
|
caml-types-annotation-tree)))
|
|
|
|
(cond
|
|
|
|
((null node)
|
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
(message "Point is not within an identifier."))
|
|
|
|
(t
|
|
|
|
(let ((left (caml-types-get-pos target-buf (elt node 0)))
|
|
|
|
(right (caml-types-get-pos target-buf (elt node 1)))
|
|
|
|
(kind (cdr (assoc "ident" (elt node 2)))))
|
|
|
|
(move-overlay caml-types-expr-ovl left right target-buf)
|
|
|
|
(let* ((loc-re (concat caml-types-position-re " "
|
|
|
|
caml-types-position-re))
|
|
|
|
(end-re (concat caml-types-position-re " --"))
|
2010-01-20 08:26:46 -08:00
|
|
|
(def-re (concat "def \\([^ ]*\\) " loc-re))
|
|
|
|
(def-end-re (concat "def \\([^ ]*\\) " end-re))
|
|
|
|
(internal-re (concat "int_ref \\([^ ]*\\) " loc-re))
|
2008-07-29 08:42:44 -07:00
|
|
|
(external-re "ext_ref \\(.*\\)"))
|
2007-05-16 01:21:41 -07:00
|
|
|
(cond
|
|
|
|
((string-match def-re kind)
|
2008-07-29 08:42:44 -07:00
|
|
|
(let ((var-name (match-string 1 kind))
|
|
|
|
(l-file (file-name-nondirectory (match-string 2 kind)))
|
2011-07-20 02:17:07 -07:00
|
|
|
(l-line (caml-string-to-int (match-string 4 kind)))
|
|
|
|
(l-bol (caml-string-to-int (match-string 5 kind)))
|
|
|
|
(l-cnum (caml-string-to-int (match-string 6 kind)))
|
2008-07-29 08:42:44 -07:00
|
|
|
(r-file (file-name-nondirectory (match-string 7 kind)))
|
2011-07-20 02:17:07 -07:00
|
|
|
(r-line (caml-string-to-int (match-string 9 kind)))
|
|
|
|
(r-bol (caml-string-to-int (match-string 10 kind)))
|
|
|
|
(r-cnum (caml-string-to-int (match-string 11 kind))))
|
2007-05-16 01:21:41 -07:00
|
|
|
(let* ((lpos (vector l-file l-line l-bol l-cnum))
|
|
|
|
(rpos (vector r-file r-line r-bol r-cnum))
|
|
|
|
(left (caml-types-get-pos target-buf lpos))
|
|
|
|
(right (caml-types-get-pos target-buf rpos)))
|
2008-07-29 08:42:44 -07:00
|
|
|
(message (format "local variable %s is bound here" var-name))
|
2007-05-16 01:21:41 -07:00
|
|
|
(move-overlay caml-types-scope-ovl left right target-buf))))
|
|
|
|
((string-match def-end-re kind)
|
2008-07-29 08:42:44 -07:00
|
|
|
(let ((var-name (match-string 1 kind))
|
|
|
|
(l-file (file-name-nondirectory (match-string 2 kind)))
|
2011-07-20 02:17:07 -07:00
|
|
|
(l-line (caml-string-to-int (match-string 4 kind)))
|
|
|
|
(l-bol (caml-string-to-int (match-string 5 kind)))
|
|
|
|
(l-cnum (caml-string-to-int (match-string 6 kind))))
|
2007-05-16 01:21:41 -07:00
|
|
|
(let* ((lpos (vector l-file l-line l-bol l-cnum))
|
|
|
|
(left (caml-types-get-pos target-buf lpos))
|
|
|
|
(right (buffer-size target-buf)))
|
2008-07-29 08:42:44 -07:00
|
|
|
(message (format "global variable %s is bound here" var-name))
|
2007-05-16 01:21:41 -07:00
|
|
|
(move-overlay caml-types-scope-ovl left right target-buf))))
|
|
|
|
((string-match internal-re kind)
|
2008-07-29 08:42:44 -07:00
|
|
|
(let ((var-name (match-string 1 kind))
|
|
|
|
(l-file (file-name-nondirectory (match-string 2 kind)))
|
2011-07-20 02:17:07 -07:00
|
|
|
(l-line (caml-string-to-int (match-string 4 kind)))
|
|
|
|
(l-bol (caml-string-to-int (match-string 5 kind)))
|
|
|
|
(l-cnum (caml-string-to-int (match-string 6 kind)))
|
2008-07-29 08:42:44 -07:00
|
|
|
(r-file (file-name-nondirectory (match-string 7 kind)))
|
2011-07-20 02:17:07 -07:00
|
|
|
(r-line (caml-string-to-int (match-string 9 kind)))
|
|
|
|
(r-bol (caml-string-to-int (match-string 10 kind)))
|
|
|
|
(r-cnum (caml-string-to-int (match-string 11 kind))))
|
2007-05-16 01:21:41 -07:00
|
|
|
(let* ((lpos (vector l-file l-line l-bol l-cnum))
|
|
|
|
(rpos (vector r-file r-line r-bol r-cnum))
|
|
|
|
(left (caml-types-get-pos target-buf lpos))
|
|
|
|
(right (caml-types-get-pos target-buf rpos)))
|
|
|
|
(move-overlay caml-types-def-ovl left right target-buf)
|
2008-07-29 08:42:44 -07:00
|
|
|
(message (format "%s is bound at line %d char %d"
|
|
|
|
var-name l-line (- l-cnum l-bol))))))
|
2007-05-16 01:21:41 -07:00
|
|
|
((string-match external-re kind)
|
|
|
|
(let ((fullname (match-string 1 kind)))
|
|
|
|
(with-current-buffer caml-types-buffer
|
|
|
|
(erase-buffer)
|
|
|
|
(insert fullname)
|
|
|
|
(message (format "external ident: %s" fullname)))))))
|
|
|
|
))))
|
|
|
|
(if (and (= arg 4)
|
|
|
|
(not (window-live-p (get-buffer-window caml-types-buffer))))
|
|
|
|
(display-buffer caml-types-buffer))
|
|
|
|
(unwind-protect
|
|
|
|
(caml-sit-for 60)
|
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
(delete-overlay caml-types-def-ovl)
|
|
|
|
(delete-overlay caml-types-scope-ovl)
|
|
|
|
)))
|
|
|
|
|
2008-01-11 08:13:18 -08:00
|
|
|
(defun caml-types-preprocess (target-path)
|
|
|
|
(let* ((type-path (caml-types-locate-type-file target-path))
|
|
|
|
(type-date (nth 5 (file-attributes (file-chase-links type-path))))
|
2003-07-25 12:12:50 -07:00
|
|
|
(target-date (nth 5 (file-attributes target-file))))
|
2010-06-29 05:15:52 -07:00
|
|
|
(unless (and caml-types-annotation-tree
|
|
|
|
type-date
|
|
|
|
caml-types-annotation-date
|
|
|
|
(not (caml-types-date< caml-types-annotation-date type-date)))
|
2003-10-10 06:25:38 -07:00
|
|
|
(if (and type-date target-date (caml-types-date< type-date target-date))
|
2013-03-09 14:38:52 -08:00
|
|
|
(error (format "`%s' is more recent than `%s'"
|
|
|
|
target-path type-path)))
|
2003-07-28 08:19:15 -07:00
|
|
|
(message "Reading annotation file...")
|
2008-01-11 08:13:18 -08:00
|
|
|
(let* ((type-buf (caml-types-find-file type-path))
|
2003-07-28 08:19:15 -07:00
|
|
|
(tree (with-current-buffer type-buf
|
2003-07-25 10:59:59 -07:00
|
|
|
(widen)
|
|
|
|
(goto-char (point-min))
|
2008-07-29 08:42:44 -07:00
|
|
|
(caml-types-build-tree
|
2010-06-29 05:15:52 -07:00
|
|
|
(file-name-nondirectory target-path)))))
|
2003-07-25 10:59:59 -07:00
|
|
|
(setq caml-types-annotation-tree tree
|
|
|
|
caml-types-annotation-date type-date)
|
2003-07-28 08:19:15 -07:00
|
|
|
(kill-buffer type-buf)
|
2007-05-16 01:21:41 -07:00
|
|
|
(message "done"))
|
2003-07-28 08:19:15 -07:00
|
|
|
)))
|
2003-04-02 08:39:59 -08:00
|
|
|
|
2011-07-20 02:17:07 -07:00
|
|
|
(defun caml-types-parent-dir (d) (file-name-directory (directory-file-name d)))
|
|
|
|
|
2008-01-11 08:13:18 -08:00
|
|
|
(defun caml-types-locate-type-file (target-path)
|
2010-06-29 05:15:52 -07:00
|
|
|
(let ((sibling (concat (file-name-sans-extension target-path) ".annot")))
|
|
|
|
(if (file-exists-p sibling)
|
|
|
|
sibling
|
|
|
|
(let ((project-dir (file-name-directory sibling))
|
|
|
|
type-path)
|
|
|
|
(while (not (file-exists-p
|
|
|
|
(setq type-path
|
|
|
|
(expand-file-name
|
|
|
|
(file-relative-name sibling project-dir)
|
|
|
|
(expand-file-name "_build" project-dir)))))
|
2011-07-20 02:17:07 -07:00
|
|
|
(if (equal project-dir (caml-types-parent-dir project-dir))
|
2010-06-29 05:15:52 -07:00
|
|
|
(error (concat "No annotation file. "
|
|
|
|
"You should compile with option \"-annot\".")))
|
2011-07-20 02:17:07 -07:00
|
|
|
(setq project-dir (caml-types-parent-dir project-dir)))
|
2010-06-29 05:15:52 -07:00
|
|
|
type-path))))
|
2008-07-29 08:42:44 -07:00
|
|
|
|
2003-04-02 08:39:59 -08:00
|
|
|
(defun caml-types-date< (date1 date2)
|
|
|
|
(or (< (car date1) (car date2))
|
|
|
|
(and (= (car date1) (car date2))
|
|
|
|
(< (nth 1 date1) (nth 1 date2)))))
|
|
|
|
|
2003-08-25 08:01:20 -07:00
|
|
|
|
|
|
|
; we use an obarray for hash-consing the strings within each tree
|
|
|
|
|
|
|
|
(defun caml-types-make-hash-table ()
|
|
|
|
(make-vector 255 0))
|
|
|
|
|
|
|
|
(defun caml-types-hcons (elem table)
|
|
|
|
(symbol-name (intern elem table)))
|
|
|
|
|
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
(defun next-annotation ()
|
|
|
|
(forward-char 1)
|
|
|
|
(if (re-search-forward "^[a-z\"]" () t)
|
|
|
|
(forward-char -1)
|
|
|
|
(goto-char (point-max)))
|
|
|
|
(looking-at "[a-z]")
|
|
|
|
)
|
|
|
|
|
2003-07-25 10:59:59 -07:00
|
|
|
; tree of intervals
|
|
|
|
; each node is a vector
|
2007-05-16 01:21:41 -07:00
|
|
|
; [ pos-left pos-right annotation child child child... ]
|
|
|
|
; annotation is a list of:
|
|
|
|
; (kind . info) where kind = "type" "call" etc.
|
|
|
|
; and info = the contents of the annotation
|
2003-07-25 10:59:59 -07:00
|
|
|
|
2003-07-25 12:12:50 -07:00
|
|
|
(defun caml-types-build-tree (target-file)
|
2003-07-25 10:59:59 -07:00
|
|
|
(let ((stack ())
|
|
|
|
(accu ())
|
2003-08-25 08:01:20 -07:00
|
|
|
(table (caml-types-make-hash-table))
|
2007-05-16 01:21:41 -07:00
|
|
|
(annotation ()))
|
2003-07-24 01:46:52 -07:00
|
|
|
(while (re-search-forward caml-types-location-re () t)
|
2003-07-25 10:59:59 -07:00
|
|
|
(let ((l-file (file-name-nondirectory (match-string 1)))
|
2011-07-20 02:17:07 -07:00
|
|
|
(l-line (caml-string-to-int (match-string 3)))
|
|
|
|
(l-bol (caml-string-to-int (match-string 4)))
|
|
|
|
(l-cnum (caml-string-to-int (match-string 5)))
|
2003-07-25 10:59:59 -07:00
|
|
|
(r-file (file-name-nondirectory (match-string 6)))
|
2011-07-20 02:17:07 -07:00
|
|
|
(r-line (caml-string-to-int (match-string 8)))
|
|
|
|
(r-bol (caml-string-to-int (match-string 9)))
|
|
|
|
(r-cnum (caml-string-to-int (match-string 10))))
|
2003-09-04 10:38:13 -07:00
|
|
|
(unless (caml-types-not-in-file l-file r-file target-file)
|
2007-05-16 01:21:41 -07:00
|
|
|
(setq annotation ())
|
|
|
|
(while (next-annotation)
|
2012-02-03 12:37:26 -08:00
|
|
|
(cond ((looking-at "^\\([a-z]+\\)(\n \\(\\(.*\n \\)*.*\\)\n)")
|
2007-05-16 01:21:41 -07:00
|
|
|
(let ((kind (caml-types-hcons (match-string 1) table))
|
|
|
|
(info (caml-types-hcons (match-string 2) table)))
|
|
|
|
(setq annotation (cons (cons kind info) annotation))))))
|
2003-07-25 12:12:50 -07:00
|
|
|
(setq accu ())
|
|
|
|
(while (and stack
|
|
|
|
(caml-types-pos-contains l-cnum r-cnum (car stack)))
|
|
|
|
(setq accu (cons (car stack) accu))
|
|
|
|
(setq stack (cdr stack)))
|
|
|
|
(let* ((left-pos (vector l-file l-line l-bol l-cnum))
|
|
|
|
(right-pos (vector r-file r-line r-bol r-cnum))
|
2007-05-16 01:21:41 -07:00
|
|
|
(node (caml-types-make-node left-pos right-pos annotation
|
2003-07-25 12:12:50 -07:00
|
|
|
accu)))
|
|
|
|
(setq stack (cons node stack))))))
|
2003-07-25 10:59:59 -07:00
|
|
|
(if (null stack)
|
2003-07-25 14:51:51 -07:00
|
|
|
(error "no annotations found for this source file")
|
2003-07-25 10:59:59 -07:00
|
|
|
(let* ((left-pos (elt (car (last stack)) 0))
|
|
|
|
(right-pos (elt (car stack) 1)))
|
|
|
|
(if (null (cdr stack))
|
|
|
|
(car stack)
|
|
|
|
(caml-types-make-node left-pos right-pos () (nreverse stack)))))))
|
|
|
|
|
2003-09-04 10:38:13 -07:00
|
|
|
(defun caml-types-not-in-file (l-file r-file target-file)
|
|
|
|
(or (and (not (string= l-file target-file))
|
|
|
|
(not (string= l-file "")))
|
|
|
|
(and (not (string= r-file target-file))
|
|
|
|
(not (string= r-file "")))))
|
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
(defun caml-types-make-node (left-pos right-pos annotation children)
|
2003-07-25 10:59:59 -07:00
|
|
|
(let ((result (make-vector (+ 3 (length children)) ()))
|
|
|
|
(i 3))
|
|
|
|
(aset result 0 left-pos)
|
|
|
|
(aset result 1 right-pos)
|
2007-05-16 01:21:41 -07:00
|
|
|
(aset result 2 annotation)
|
2003-07-25 10:59:59 -07:00
|
|
|
(while children
|
|
|
|
(aset result i (car children))
|
|
|
|
(setq children (cdr children))
|
|
|
|
(setq i (1+ i)))
|
|
|
|
result))
|
|
|
|
|
|
|
|
(defun caml-types-pos-contains (l-cnum r-cnum node)
|
|
|
|
(and (<= l-cnum (elt (elt node 0) 3))
|
|
|
|
(>= r-cnum (elt (elt node 1) 3))))
|
|
|
|
|
2007-05-16 01:21:41 -07:00
|
|
|
(defun caml-types-find-location (targ-pos kind curr node)
|
2003-07-25 12:12:50 -07:00
|
|
|
(if (not (caml-types-pos-inside targ-pos node))
|
|
|
|
curr
|
2007-05-16 01:21:41 -07:00
|
|
|
(if (and (elt node 2) (assoc kind (elt node 2)))
|
2003-07-25 12:12:50 -07:00
|
|
|
(setq curr node))
|
|
|
|
(let ((i (caml-types-search node targ-pos)))
|
|
|
|
(if (and (> i 3)
|
|
|
|
(caml-types-pos-inside targ-pos (elt node (1- i))))
|
2007-05-16 01:21:41 -07:00
|
|
|
(caml-types-find-location targ-pos kind curr (elt node (1- i)))
|
2003-07-25 10:59:59 -07:00
|
|
|
curr))))
|
|
|
|
|
2003-07-25 12:12:50 -07:00
|
|
|
; trouve le premier fils qui commence apres la position
|
|
|
|
; ou (length node) si tous commencent avant
|
|
|
|
(defun caml-types-search (node pos)
|
2003-07-25 12:23:28 -07:00
|
|
|
(let ((min 3)
|
|
|
|
(max (length node))
|
|
|
|
med)
|
|
|
|
(while (< min max)
|
|
|
|
(setq med (/ (+ min max) 2))
|
|
|
|
(if (caml-types-pos<= (elt (elt node med) 0) pos)
|
|
|
|
(setq min (1+ med))
|
|
|
|
(setq max med)))
|
|
|
|
min))
|
2003-07-25 12:12:50 -07:00
|
|
|
|
2003-07-25 10:59:59 -07:00
|
|
|
(defun caml-types-pos-inside (pos node)
|
|
|
|
(let ((left-pos (elt node 0))
|
|
|
|
(right-pos (elt node 1)))
|
|
|
|
(and (caml-types-pos<= left-pos pos)
|
|
|
|
(caml-types-pos> right-pos pos))))
|
|
|
|
|
|
|
|
(defun caml-types-find-interval (buf targ-pos node)
|
|
|
|
(let ((nleft (elt node 0))
|
|
|
|
(nright (elt node 1))
|
|
|
|
(left ())
|
|
|
|
(right ())
|
2003-07-25 14:51:51 -07:00
|
|
|
i)
|
2003-07-25 10:59:59 -07:00
|
|
|
(cond
|
|
|
|
((not (caml-types-pos-inside targ-pos node))
|
|
|
|
(if (not (caml-types-pos<= nleft targ-pos))
|
|
|
|
(setq right nleft))
|
|
|
|
(if (not (caml-types-pos> nright targ-pos))
|
|
|
|
(setq left nright)))
|
|
|
|
(t
|
|
|
|
(setq left nleft
|
|
|
|
right nright)
|
2003-07-25 12:12:50 -07:00
|
|
|
(setq i (caml-types-search node targ-pos))
|
2003-07-25 10:59:59 -07:00
|
|
|
(if (< i (length node))
|
|
|
|
(setq right (elt (elt node i) 0)))
|
|
|
|
(if (> i 3)
|
|
|
|
(setq left (elt (elt node (1- i)) 1)))))
|
|
|
|
(cons (if left
|
|
|
|
(caml-types-get-pos buf left)
|
|
|
|
(with-current-buffer buf (point-min)))
|
|
|
|
(if right
|
|
|
|
(caml-types-get-pos buf right)
|
|
|
|
(with-current-buffer buf (point-max))))))
|
2003-04-03 05:59:38 -08:00
|
|
|
|
|
|
|
|
|
|
|
;; Warning: these comparison functions are not symmetric.
|
|
|
|
;; The first argument determines the format:
|
|
|
|
;; when its file component is empty, only the cnum is compared.
|
|
|
|
|
2003-07-25 10:59:59 -07:00
|
|
|
(defun caml-types-pos<= (pos1 pos2)
|
|
|
|
(let ((file1 (elt pos1 0))
|
|
|
|
(line1 (elt pos1 1))
|
|
|
|
(bol1 (elt pos1 2))
|
|
|
|
(cnum1 (elt pos1 3))
|
|
|
|
(file2 (elt pos2 0))
|
|
|
|
(line2 (elt pos2 1))
|
|
|
|
(bol2 (elt pos2 2))
|
|
|
|
(cnum2 (elt pos2 3)))
|
|
|
|
(if (string= file1 "")
|
|
|
|
(<= cnum1 cnum2)
|
|
|
|
(and (string= file1 file2)
|
|
|
|
(or (< line1 line2)
|
|
|
|
(and (= line1 line2)
|
|
|
|
(<= (- cnum1 bol1) (- cnum2 bol2))))))))
|
2003-04-03 05:59:38 -08:00
|
|
|
|
2003-07-25 10:59:59 -07:00
|
|
|
(defun caml-types-pos> (pos1 pos2)
|
|
|
|
(let ((file1 (elt pos1 0))
|
|
|
|
(line1 (elt pos1 1))
|
|
|
|
(bol1 (elt pos1 2))
|
|
|
|
(cnum1 (elt pos1 3))
|
|
|
|
(file2 (elt pos2 0))
|
|
|
|
(line2 (elt pos2 1))
|
|
|
|
(bol2 (elt pos2 2))
|
|
|
|
(cnum2 (elt pos2 3)))
|
|
|
|
(if (string= file1 "")
|
|
|
|
(> cnum1 cnum2)
|
|
|
|
(and (string= file1 file2)
|
|
|
|
(or (> line1 line2)
|
|
|
|
(and (= line1 line2)
|
|
|
|
(> (- cnum1 bol1) (- cnum2 bol2))))))))
|
2003-07-24 01:46:52 -07:00
|
|
|
|
2003-07-25 10:59:59 -07:00
|
|
|
(defun caml-types-get-pos (buf pos)
|
2003-04-02 08:39:59 -08:00
|
|
|
(save-excursion
|
|
|
|
(set-buffer buf)
|
2003-07-25 10:59:59 -07:00
|
|
|
(goto-line (elt pos 1))
|
|
|
|
(forward-char (- (elt pos 3) (elt pos 2)))
|
2003-04-02 08:39:59 -08:00
|
|
|
(point)))
|
2003-04-03 05:59:38 -08:00
|
|
|
|
|
|
|
; find-file-read-only-noselect seems to be missing from emacs...
|
|
|
|
(defun caml-types-find-file (name)
|
2003-07-24 01:46:52 -07:00
|
|
|
(let (buf)
|
|
|
|
(cond
|
|
|
|
((setq buf (get-file-buffer name))
|
|
|
|
(unless (verify-visited-file-modtime buf)
|
|
|
|
(if (buffer-modified-p buf)
|
|
|
|
(find-file-noselect name)
|
|
|
|
(with-current-buffer buf (revert-buffer t t)))
|
|
|
|
))
|
|
|
|
((and (file-readable-p name)
|
|
|
|
(setq buf (find-file-noselect name)))
|
|
|
|
(with-current-buffer buf (toggle-read-only 1))
|
|
|
|
)
|
|
|
|
(t
|
2008-01-11 08:13:18 -08:00
|
|
|
(error (format "Can't read the annotation file `%s'" name)))
|
2003-07-24 01:46:52 -07:00
|
|
|
)
|
2010-06-29 05:15:52 -07:00
|
|
|
buf))
|
2003-07-24 01:46:52 -07:00
|
|
|
|
2003-10-10 06:25:38 -07:00
|
|
|
(defun caml-types-mouse-ignore (event)
|
|
|
|
(interactive "e")
|
|
|
|
nil)
|
2003-07-28 11:06:49 -07:00
|
|
|
|
2003-10-20 05:06:42 -07:00
|
|
|
(defun caml-types-time ()
|
|
|
|
(let ((time (current-time)))
|
|
|
|
(+ (* (mod (cadr time) 1000) 1000)
|
|
|
|
(/ (cadr (cdr time)) 1000))))
|
|
|
|
|
2003-07-24 01:46:52 -07:00
|
|
|
(defun caml-types-explore (event)
|
|
|
|
"Explore type annotations by mouse dragging.
|
|
|
|
|
2008-07-29 08:42:44 -07:00
|
|
|
The expression under the mouse is highlighted and its type is displayed
|
2003-10-20 05:06:42 -07:00
|
|
|
in the minibuffer, until the move is released, much as `caml-types-show-type'.
|
2008-07-29 08:42:44 -07:00
|
|
|
The function uses two overlays.
|
2003-10-20 05:06:42 -07:00
|
|
|
|
2008-07-29 08:42:44 -07:00
|
|
|
. One overlay delimits the largest region whose all subnodes
|
|
|
|
are well-typed.
|
2003-10-20 05:06:42 -07:00
|
|
|
. Another overlay delimits the current node under the mouse (whose type
|
2012-07-10 10:51:04 -07:00
|
|
|
annotation is being displayed).
|
2003-10-20 05:06:42 -07:00
|
|
|
"
|
2003-07-24 01:46:52 -07:00
|
|
|
(interactive "e")
|
2003-07-28 23:54:28 -07:00
|
|
|
(set-buffer (window-buffer (caml-event-window event)))
|
2003-07-24 01:46:52 -07:00
|
|
|
(let* ((target-buf (current-buffer))
|
|
|
|
(target-file (file-name-nondirectory (buffer-file-name)))
|
|
|
|
(target-line) (target-bol)
|
2003-07-25 10:59:59 -07:00
|
|
|
target-pos
|
2003-07-28 08:19:15 -07:00
|
|
|
Left Right limits cnum node mes type
|
2003-07-29 09:44:56 -07:00
|
|
|
region
|
2003-10-20 05:06:42 -07:00
|
|
|
(window (caml-event-window event))
|
2003-10-10 17:00:14 -07:00
|
|
|
target-tree
|
2003-10-20 05:06:42 -07:00
|
|
|
(speed 100)
|
|
|
|
(last-time (caml-types-time))
|
|
|
|
(original-event event)
|
2003-07-24 01:46:52 -07:00
|
|
|
)
|
2003-10-20 05:06:42 -07:00
|
|
|
(select-window window)
|
2003-07-24 01:46:52 -07:00
|
|
|
(unwind-protect
|
2003-10-10 06:25:38 -07:00
|
|
|
(progn
|
2008-01-11 08:13:18 -08:00
|
|
|
(caml-types-preprocess (buffer-file-name))
|
2003-10-10 17:00:14 -07:00
|
|
|
(setq target-tree caml-types-annotation-tree)
|
2005-08-13 13:59:37 -07:00
|
|
|
(setq caml-types-buffer (get-buffer-create caml-types-buffer-name))
|
2003-10-10 06:25:38 -07:00
|
|
|
;; (message "Drag the mouse to explore types")
|
|
|
|
(unwind-protect
|
|
|
|
(caml-track-mouse
|
2003-10-20 05:06:42 -07:00
|
|
|
(while event
|
|
|
|
(cond
|
2008-07-29 08:42:44 -07:00
|
|
|
;; we ignore non mouse events
|
2003-10-20 05:06:42 -07:00
|
|
|
((caml-ignore-event-p event))
|
2003-10-21 00:36:06 -07:00
|
|
|
;; we stop when the original button is released
|
2003-10-20 05:06:42 -07:00
|
|
|
((caml-release-event-p original-event event)
|
|
|
|
(setq event nil))
|
2003-10-21 00:36:06 -07:00
|
|
|
;; we scroll when the motion is outside the window
|
2003-10-20 05:06:42 -07:00
|
|
|
((and (caml-mouse-movement-p event)
|
|
|
|
(not (and (equal window (caml-event-window event))
|
|
|
|
(integer-or-marker-p
|
|
|
|
(caml-event-point-end event)))))
|
|
|
|
(let* ((win (caml-window-edges window))
|
|
|
|
(top (nth 1 win))
|
|
|
|
(bottom (- (nth 3 win) 1))
|
|
|
|
mouse
|
|
|
|
time
|
|
|
|
)
|
|
|
|
(while (and
|
|
|
|
(caml-sit-for 0 (/ 500 speed))
|
2008-07-29 08:42:44 -07:00
|
|
|
(setq time (caml-types-time))
|
2003-10-20 05:06:42 -07:00
|
|
|
(> (- time last-time) (/ 500 speed))
|
|
|
|
(setq mouse (caml-mouse-vertical-position))
|
|
|
|
(or (< mouse top) (>= mouse bottom))
|
|
|
|
)
|
|
|
|
(setq last-time time)
|
|
|
|
(cond
|
|
|
|
((< mouse top)
|
|
|
|
(setq speed (- top mouse))
|
|
|
|
(condition-case nil
|
|
|
|
(scroll-down 1)
|
|
|
|
(error (message "Beginning of buffer!"))))
|
|
|
|
((>= mouse bottom)
|
|
|
|
(setq speed (+ 1 (- mouse bottom)))
|
|
|
|
(condition-case nil
|
|
|
|
(scroll-up 1)
|
|
|
|
(error (message "End of buffer!"))))
|
2008-07-29 08:42:44 -07:00
|
|
|
)
|
2003-10-20 05:06:42 -07:00
|
|
|
(setq speed (* speed speed))
|
|
|
|
)))
|
2003-10-21 00:36:06 -07:00
|
|
|
;; main action, when the motion is inside the window
|
|
|
|
;; or on orginal button down event
|
2003-10-20 05:06:42 -07:00
|
|
|
((or (caml-mouse-movement-p event)
|
|
|
|
(equal original-event event))
|
|
|
|
(setq cnum (caml-event-point-end event))
|
|
|
|
(if (and region
|
|
|
|
(<= (car region) cnum) (< cnum (cdr region)))
|
2003-10-21 00:36:06 -07:00
|
|
|
;; mouse remains in outer region
|
2003-10-20 05:06:42 -07:00
|
|
|
nil
|
2008-07-29 08:42:44 -07:00
|
|
|
;; otherwise, reset the outer region
|
2003-10-20 05:06:42 -07:00
|
|
|
(setq region
|
|
|
|
(caml-types-typed-make-overlay
|
|
|
|
target-buf (caml-event-point-start event))))
|
2003-10-21 00:36:06 -07:00
|
|
|
(if
|
|
|
|
(and limits
|
2003-10-20 05:06:42 -07:00
|
|
|
(>= cnum (car limits)) (< cnum (cdr limits)))
|
2003-10-21 00:36:06 -07:00
|
|
|
;; inner region is unchanged
|
|
|
|
nil
|
|
|
|
;; recompute the inner region and type annotation
|
2003-10-20 05:06:42 -07:00
|
|
|
(setq target-bol
|
|
|
|
(save-excursion
|
|
|
|
(goto-char cnum) (caml-line-beginning-position))
|
|
|
|
target-line (1+ (count-lines (point-min)
|
|
|
|
target-bol))
|
|
|
|
target-pos
|
|
|
|
(vector target-file target-line target-bol cnum))
|
|
|
|
(save-excursion
|
2012-07-10 10:51:04 -07:00
|
|
|
(setq node (caml-types-find-location target-pos "type" ()
|
2012-07-30 11:04:46 -07:00
|
|
|
target-tree))
|
2003-10-20 05:06:42 -07:00
|
|
|
(set-buffer caml-types-buffer)
|
|
|
|
(erase-buffer)
|
|
|
|
(cond
|
2012-07-30 11:04:46 -07:00
|
|
|
((null node)
|
2003-10-20 05:06:42 -07:00
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
(setq type "*no type information*")
|
|
|
|
(setq limits
|
|
|
|
(caml-types-find-interval
|
2012-07-10 10:51:04 -07:00
|
|
|
target-buf target-pos target-tree)))
|
|
|
|
(t
|
2012-07-30 11:04:46 -07:00
|
|
|
(let ((left
|
|
|
|
(caml-types-get-pos target-buf (elt node 0)))
|
2012-07-10 10:51:04 -07:00
|
|
|
(right
|
2012-07-30 11:04:46 -07:00
|
|
|
(caml-types-get-pos target-buf (elt node 1))))
|
2012-07-10 10:51:04 -07:00
|
|
|
(move-overlay
|
|
|
|
caml-types-expr-ovl left right target-buf)
|
|
|
|
(setq limits
|
|
|
|
(caml-types-find-interval target-buf
|
|
|
|
target-pos node)
|
|
|
|
type (cdr (assoc "type" (elt node 2))))
|
2003-10-20 05:06:42 -07:00
|
|
|
))
|
2012-07-30 11:04:46 -07:00
|
|
|
)
|
2003-10-21 00:36:06 -07:00
|
|
|
(setq mes (format "type: %s" type))
|
2003-10-20 05:06:42 -07:00
|
|
|
(insert type)
|
|
|
|
))
|
2003-10-21 00:36:06 -07:00
|
|
|
(message mes)
|
2003-10-20 05:06:42 -07:00
|
|
|
)
|
|
|
|
)
|
2003-10-21 00:36:06 -07:00
|
|
|
;; we read next event, unless it is nil, and loop back.
|
2003-10-20 05:06:42 -07:00
|
|
|
(if event (setq event (caml-read-event)))
|
2003-10-10 06:25:38 -07:00
|
|
|
)
|
|
|
|
)
|
2003-10-21 00:36:06 -07:00
|
|
|
;; delete overlays at end of exploration
|
2003-10-10 06:25:38 -07:00
|
|
|
(delete-overlay caml-types-expr-ovl)
|
|
|
|
(delete-overlay caml-types-typed-ovl)
|
|
|
|
))
|
2003-10-20 05:06:42 -07:00
|
|
|
;; When an error occurs, the mouse release event has not been read.
|
|
|
|
;; We could wait for mouse release to prevent execution of
|
|
|
|
;; a binding of mouse release, such as cut or paste.
|
|
|
|
;; In most common cases, next event will be the mouse release.
|
2003-10-10 17:00:14 -07:00
|
|
|
;; However, it could also be a key stroke before mouse release.
|
2003-10-10 06:25:38 -07:00
|
|
|
;; Emacs does not allow to test whether mouse is up or down.
|
2003-10-20 05:06:42 -07:00
|
|
|
;; Not sure it is robust to loop for mouse release after an error
|
2008-07-29 08:42:44 -07:00
|
|
|
;; occured, as is done for exploration.
|
2003-10-20 05:06:42 -07:00
|
|
|
;; So far, we just ignore next event. (Next line also be uncommenting.)
|
|
|
|
(if event (caml-read-event))
|
2003-10-10 17:00:14 -07:00
|
|
|
)))
|
2003-07-29 09:44:56 -07:00
|
|
|
|
2003-09-05 11:01:46 -07:00
|
|
|
(defun caml-types-typed-make-overlay (target-buf pos)
|
2003-07-29 09:44:56 -07:00
|
|
|
(interactive "p")
|
2003-09-05 11:01:46 -07:00
|
|
|
(let ((start pos) (end pos) len node left right)
|
2003-07-29 09:44:56 -07:00
|
|
|
(setq len (length caml-types-annotation-tree))
|
|
|
|
(while (> len 3)
|
|
|
|
(setq len (- len 1))
|
|
|
|
(setq node (aref caml-types-annotation-tree len))
|
2003-09-05 11:01:46 -07:00
|
|
|
(if (and (equal target-buf (current-buffer))
|
|
|
|
(setq left (caml-types-get-pos target-buf (elt node 0))
|
|
|
|
right (caml-types-get-pos target-buf (elt node 1)))
|
2003-10-10 17:00:14 -07:00
|
|
|
(<= left pos) (> right pos)
|
2003-09-05 11:01:46 -07:00
|
|
|
)
|
|
|
|
(setq start (min start left)
|
|
|
|
end (max end right))
|
|
|
|
))
|
|
|
|
(move-overlay caml-types-typed-ovl
|
|
|
|
(max (point-min) (- start 1))
|
|
|
|
(min (point-max) (+ end 1)) target-buf)
|
|
|
|
(cons start end)))
|
2003-07-24 01:46:52 -07:00
|
|
|
|
2005-08-13 13:59:37 -07:00
|
|
|
(defun caml-types-version ()
|
|
|
|
"internal version number of caml-types.el"
|
|
|
|
(interactive)
|
2008-07-29 08:42:44 -07:00
|
|
|
(message "4")
|
2005-08-13 13:59:37 -07:00
|
|
|
)
|
|
|
|
|
2003-07-23 07:20:33 -07:00
|
|
|
(provide 'caml-types)
|