Skip to content

Commit 5e6d996

Browse files
committed
Fix hilitghting of largest well-typed expr surrounding point.
Cancel exploration outside of this region. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5824 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent d10e45f commit 5e6d996

File tree

1 file changed

+62
-62
lines changed

1 file changed

+62
-62
lines changed

emacs/caml-types.el

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ For the moment, the only possible keyword is \"type\"."
7171
(if (not (face-differs-from-default-p 'caml-types-face))
7272
(set-face-background 'caml-types-face "#88FF44"))
7373

74-
(make-face 'caml-typed-face)
75-
(set-face-doc-string 'caml-typed-face
74+
(defvar caml-types-typed-ovl (make-overlay 1 1))
75+
76+
(make-face 'caml-types-typed-face)
77+
(set-face-doc-string 'caml-types-typed-face
7678
"face for hilighting typed expressions")
77-
(if (not (face-differs-from-default-p 'caml-typed-face))
78-
(set-face-background 'caml-typed-face "#FF8844"))
79+
(if (not (face-differs-from-default-p 'caml-types-typed-face))
80+
(set-face-background 'caml-types-typed-face "#FF8844"))
7981

8082
(overlay-put caml-types-expr-ovl 'face 'caml-types-face)
83+
(overlay-put caml-types-typed-ovl 'face 'caml-types-typed-face)
8184

8285

8386
(defvar caml-types-annotation-tree nil)
@@ -149,7 +152,8 @@ See `caml-types-location-re' for annotation file format.
149152
(display-buffer caml-types-buffer))
150153
(unwind-protect
151154
(sit-for 60)
152-
(delete-overlay caml-types-expr-ovl))))
155+
(delete-overlay caml-types-expr-ovl)
156+
)))
153157

154158
(defun caml-types-preprocess (type-file)
155159
(let* ((type-date (nth 5 (file-attributes type-file)))
@@ -392,81 +396,77 @@ and its type is displayed in the minibuffer, until the move is released."
392396
target-pos
393397
Left Right limits cnum node mes type
394398
(tree caml-types-annotation-tree)
395-
(unlocked font-lock-mode)
396399
region
397400
)
398401
(caml-types-preprocess type-file)
399402
(unless caml-types-buffer
400403
(setq caml-types-buffer (get-buffer-create caml-types-buffer-name)))
401-
; (message "Drag the mouse to explore types")
404+
;; (message "Drag the mouse to explore types")
402405
(unwind-protect
403406
(caml-track-mouse
404-
;(setq region (caml-types-typed-region
405-
; target-buf
406-
; (caml-event-point-start event)))
407+
(setq region
408+
(caml-types-typed-make-overlay target-buf
409+
(caml-event-point-start event)))
407410
(while (and event
408411
(integer-or-marker-p
409412
(setq cnum (caml-event-point-end event))))
410-
(if (and limits (>= cnum (car limits)) (< cnum (cdr limits)))
411-
(message mes)
412-
(setq target-bol
413-
(save-excursion (goto-char cnum)
414-
(caml-line-beginning-position)))
415-
(setq target-line
416-
(1+ (count-lines (point-min) target-bol)))
417-
(setq target-pos (vector target-file target-line target-bol cnum))
418-
(save-excursion
419-
(setq node (caml-types-find-location target-pos () tree))
420-
(set-buffer caml-types-buffer)
421-
(erase-buffer)
422-
(cond
423-
(node
424-
(setq Left (caml-types-get-pos target-buf (elt node 0)))
425-
(setq Right (caml-types-get-pos target-buf (elt node 1)))
426-
(move-overlay caml-types-expr-ovl Left Right target-buf)
427-
(setq limits (caml-types-find-interval target-buf target-pos
428-
node))
429-
(setq type (elt node 2))
430-
)
431-
(t
432-
(delete-overlay caml-types-expr-ovl)
433-
(setq type "*no type information*")
434-
(setq limits (caml-types-find-interval target-buf target-pos
435-
tree))
436-
))
437-
(message (setq mes (format "type: %s" type)))
438-
(insert type)
439-
))
440-
(setq event (caml-read-event))
441-
(unless (mouse-movement-p event) (setq event nil))
442-
)
413+
(if (and region (<= (car region) cnum) (<= cnum (cdr region)))
414+
(if (and limits (>= cnum (car limits)) (< cnum (cdr limits)))
415+
(message mes)
416+
(setq target-bol
417+
(save-excursion (goto-char cnum)
418+
(caml-line-beginning-position)))
419+
(setq target-line
420+
(1+ (count-lines (point-min) target-bol)))
421+
(setq target-pos (vector target-file target-line target-bol cnum))
422+
(save-excursion
423+
(setq node (caml-types-find-location target-pos () tree))
424+
(set-buffer caml-types-buffer)
425+
(erase-buffer)
426+
(cond
427+
(node
428+
(setq Left (caml-types-get-pos target-buf (elt node 0)))
429+
(setq Right (caml-types-get-pos target-buf (elt node 1)))
430+
(move-overlay caml-types-expr-ovl Left Right target-buf)
431+
(setq limits (caml-types-find-interval target-buf target-pos
432+
node))
433+
(setq type (elt node 2))
434+
)
435+
(t
436+
(delete-overlay caml-types-expr-ovl)
437+
(setq type "*no type information*")
438+
(setq limits (caml-types-find-interval target-buf target-pos
439+
tree))
440+
))
441+
(message (setq mes (format "type: %s" type)))
442+
(insert type)
443+
)))
444+
(setq event (caml-read-event))
445+
(unless (mouse-movement-p event) (setq event nil))
446+
)
443447
)
444448
(delete-overlay caml-types-expr-ovl)
445-
;(if unlocked (font-lock-mode 1)
446-
; (remove-text-properties (car region) (cdr region) '(face)))
449+
(delete-overlay caml-types-typed-ovl)
447450
)))
448451

449-
(defun caml-types-typed-region (target-buf pos)
452+
(defun caml-types-typed-make-overlay (target-buf pos)
450453
(interactive "p")
451-
(if (functionp 'caml-find-phrase)
452-
(save-excursion
453-
(goto-char pos)
454-
(setq start (caml-find-phrase))
455-
(setq end (point)))
456-
(setq start (point-min))
457-
(setq end (point-max)))
458-
(message "%S %S" start end)
459-
(let (len node)
454+
(let ((start pos) (end pos) len node left right)
460455
(setq len (length caml-types-annotation-tree))
461-
(if font-lock-mode (font-lock-mode 0))
462456
(while (> len 3)
463457
(setq len (- len 1))
464458
(setq node (aref caml-types-annotation-tree len))
465-
(if (caml-types-pos-contains start end node)
466-
(put-text-property
467-
(caml-types-get-pos target-buf (elt node 0))
468-
(caml-types-get-pos target-buf (elt node 1))
469-
'face 'caml-typed-face))))
470-
(cons start end))
459+
(if (and (equal target-buf (current-buffer))
460+
(setq left (caml-types-get-pos target-buf (elt node 0))
461+
right (caml-types-get-pos target-buf (elt node 1)))
462+
(<= left pos) (>= right pos)
463+
)
464+
(setq start (min start left)
465+
end (max end right))
466+
))
467+
(move-overlay caml-types-typed-ovl
468+
(max (point-min) (- start 1))
469+
(min (point-max) (+ end 1)) target-buf)
470+
(cons start end)))
471471

472472
(provide 'caml-types)

0 commit comments

Comments
 (0)