Commits

Anonymous committed 2ee99db

overlay for source

Comments (0)

Files changed (2)

ocamlspot/ocamlspot.el

 
 (defvar ocamlspot-debug nil "turn on debug output")
 
-;; the overlay
-(setq ocamlspot-overlay nil)
+;; the spot overlay
+(defvar ocamlspot-spot-overlay (make-overlay 1 1))
+(make-face 'ocamlspot-spot-face)
+(set-face-doc-string 'ocamlspot-spot-face "face for ocamlspot spot highlight")
+(set-face-background 'ocamlspot-spot-face "#88FF44")
+(overlay-put ocamlspot-spot-overlay 'face 'ocamlspot-spot-face)
 
-(defun ocamlspot-overlay-init ()
-  (setq ocamlspot-overlay (make-overlay 1 1 nil))
-  (make-face 'ocamlspot-face)
-  (set-face-doc-string 'ocamlspot-face "face for ocamlspot highlight")
-  (set-face-background 'ocamlspot-face "#88FF44")
-  (overlay-put ocamlspot-overlay 'face 'ocamlspot-face))
+(defun ocamlspot-display-spot-overlay (buffer start end)
+  (interactive)
+  ; (if (not (overlayp ocamlspot-spot-overlay)) (ocamlspot-spot-overlay-init))
+  (move-overlay ocamlspot-spot-overlay start end buffer))
 
-(defun ocamlspot-display-overlay (buffer start end)
-  (interactive)
-  (if (not (overlayp ocamlspot-overlay)) (ocamlspot-overlay-init))
-  (move-overlay ocamlspot-overlay start end buffer)
+;; the tree overlay
+(defvar ocamlspot-tree-overlay (make-overlay 1 1))
+(make-face 'ocamlspot-tree-face)
+(set-face-doc-string 'ocamlspot-tree-face "face for ocamlspot tree highlight")
+(set-face-background 'ocamlspot-tree-face "#44FF88")
+(overlay-put ocamlspot-tree-overlay 'face 'ocamlspot-tree-face)
+
+(defun ocamlspot-display-tree-overlay (buffer start end)
+  (move-overlay ocamlspot-tree-overlay start end buffer))
+
+;; CRv2 jfuruse: remove overlays after cursor move
+ (defun ocamlspot-delete-overlays ()
   (unwind-protect
       (sit-for 60)
-    (delete-overlay ocamlspot-overlay)))
+    (delete-overlay ocamlspot-spot-overlay)
+    (delete-overlay ocamlspot-tree-overlay)))
 
 (defun ocamlspot-cnum-of-point () (1- (point)))
 (defun ocamlspot-char-of-cnum (n) (1+ n))
                        (buffer-file-name) 
                        (ocamlspot-cnum-of-point))))  
       ;; ocamlspot buffer
+      (setq source-buffer (current-buffer))
       (save-current-buffer 
         (set-buffer (get-buffer-create ocamlspot-buffer))
         (erase-buffer)
             (call-process ocamlspot-path nil ocamlspot-buffer nil 
                           "-debug" arg)
           (call-process ocamlspot-path nil ocamlspot-buffer nil arg))
+
+        ;; search the found tree element
+        (goto-char (point-min))
+        (if (re-search-forward "^Tree found: \\([\-0-9]+\\):\\([\-0-9]+\\)$" 
+                               nil t)
+            (let ((start 
+                   (ocamlspot-char-of-cnum 
+                    (string-to-int 
+                     (buffer-substring (match-beginning 1) (match-end 1)))))
+                  (end 
+                   (ocamlspot-char-of-cnum
+                    (string-to-int
+                     (buffer-substring (match-beginning 2) (match-end 2))))))
+	      
+              ;; display the result
+	      (ocamlspot-display-tree-overlay source-buffer start end))
+	  (progn
+            ;; display debug info
+            (message "ERROR: no tree node found there")))
+
         ;; search the result
         (goto-char (point-min))
         (if (re-search-forward "^SPOT: \\(.*\\):\\([\-0-9]+\\):\\([\-0-9]+\\)$" 
               ;; display the result
               (setq target-buffer (ocamlspot-find-file-existing filename))
               (goto-char start)
-              (ocamlspot-display-overlay target-buffer start end))
+              (ocamlspot-display-spot-overlay target-buffer start end))
           (progn
             ;; display debug info
             (message "ERROR: no spot found there") 

ocamlspot/ocamlspot.ml

 	  | _ -> []
 	in
 	let annots = filter path in
-	Format.printf "found %s@.%s@." 
+	Format.printf "Tree found: %s@.%s@." 
 	  (Location.to_string l)
 	  (String.concat "\n" 
 	    (List.map Spot.Annot.to_string annots));