@@ -71,13 +71,16 @@ For the moment, the only possible keyword is \"type\"."
71
71
(if (not (face-differs-from-default-p 'caml-types-face ))
72
72
(set-face-background 'caml-types-face " #88FF44" ))
73
73
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
76
78
" 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" ))
79
81
80
82
(overlay-put caml-types-expr-ovl 'face 'caml-types-face )
83
+ (overlay-put caml-types-typed-ovl 'face 'caml-types-typed-face )
81
84
82
85
83
86
(defvar caml-types-annotation-tree nil )
@@ -149,7 +152,8 @@ See `caml-types-location-re' for annotation file format.
149
152
(display-buffer caml-types-buffer))
150
153
(unwind-protect
151
154
(sit-for 60 )
152
- (delete-overlay caml-types-expr-ovl))))
155
+ (delete-overlay caml-types-expr-ovl)
156
+ )))
153
157
154
158
(defun caml-types-preprocess (type-file )
155
159
(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."
392
396
target-pos
393
397
Left Right limits cnum node mes type
394
398
(tree caml-types-annotation-tree)
395
- (unlocked font-lock-mode)
396
399
region
397
400
)
398
401
(caml-types-preprocess type-file)
399
402
(unless caml-types-buffer
400
403
(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")
402
405
(unwind-protect
403
406
(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)))
407
410
(while (and event
408
411
(integer-or-marker-p
409
412
(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
+ )
443
447
)
444
448
(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)
447
450
)))
448
451
449
- (defun caml-types-typed-region (target-buf pos )
452
+ (defun caml-types-typed-make-overlay (target-buf pos )
450
453
(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)
460
455
(setq len (length caml-types-annotation-tree))
461
- (if font-lock-mode (font-lock-mode 0 ))
462
456
(while (> len 3 )
463
457
(setq len (- len 1 ))
464
458
(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)))
471
471
472
472
(provide 'caml-types )
0 commit comments