Commits

camlspotter committed dd08122

backport

Comments (0)

Files changed (6)

ocamlspot/.depend

 command.cmx: command.cmi 
 dotfile.cmo: 
 dotfile.cmx: 
-ocamlspot.cmo: utils.cmo treeset.cmi dotfile.cmo command.cmi 
-ocamlspot.cmx: utils.cmx treeset.cmx dotfile.cmx command.cmx 
+ocamlspot.cmo: utils.cmo ../typing/types.cmi treeset.cmi \
+    ../typing/spotcrc.cmo ../typing/spot.cmi ../typing/printtyp.cmi \
+    ../typing/predef.cmi ../typing/path.cmi ../typing/ident.cmi dotfile.cmo \
+    command.cmi ../typing/btype.cmi ../typing/annot.cmi 
+ocamlspot.cmx: utils.cmx ../typing/types.cmx treeset.cmx \
+    ../typing/spotcrc.cmx ../typing/spot.cmx ../typing/printtyp.cmx \
+    ../typing/predef.cmx ../typing/path.cmx ../typing/ident.cmx dotfile.cmx \
+    command.cmx ../typing/btype.cmx ../typing/annot.cmi 
 treeset.cmo: xset.cmo treeset.cmi 
 treeset.cmx: xset.cmx treeset.cmi 
 utils.cmo: 

ocamlspot/Makefile

 beforedepend::
 
 depend: beforedepend
-	$(CAMLRUN) ../tools/ocamldep $(INCLUDES) *.mli *.ml > .depend
+	$(CAMLRUN) ../tools/ocamldep $(INCLUDES) -I ../typing *.mli *.ml > .depend
 
 .PHONY: clean install installopt beforedepend depend test
 

ocamlspot/ocamlspot.el

 ; 	     (local-set-key "\C-c\C-t" 'caml-types-show-type)
 ; 	     (local-set-key "\C-c;" 'ocamlspot-query)))
 
-; CR jfuruse: run directory!
-
 (defvar ocamlspot-buffer "*ocamlspot*")
 
-(defvar ocamlspot-debug-buffer "*ocamlspot-debug*")
-(defun ocamlspot-debug-message (s)
-  (if (get-buffer ocamlspot-debug-buffer)
-      ()
-    (generate-new-buffer ocamlspot-debug-buffer))
-  (save-excursion
-    (set-buffer ocamlspot-debug-buffer)
-    (insert s)
-    (insert "\n")))
-
 (defvar ocamlspot-path "OCAML-SOURCE-TREE/ocamlspot/ocamlspot"
   "ocamlspot program path")
 
+;; debug
+
 (defvar ocamlspot-debug nil "turn on debug output")
 
+(defvar ocamlspot-debug-buffer "*ocamlspot-debug*")
+(defun ocamlspot-debug-message (s)
+  (save-excursion
+    (if (get-buffer ocamlspot-debug-buffer) ()
+      (generate-new-buffer ocamlspot-debug-buffer))
+    (set-buffer ocamlspot-debug-buffer)
+    (insert s)
+    (insert "\n")))
+
 ;; the spot overlay
 (defvar ocamlspot-spot-overlay (make-overlay 1 1))
 (make-face 'ocamlspot-spot-face)
 (set-face-background 'ocamlspot-tree-face "#FF88FF")
 (overlay-put ocamlspot-tree-overlay 'face 'ocamlspot-tree-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-tree-overlay (buffer start end)
-  (move-overlay ocamlspot-tree-overlay start end buffer))
-
 (defun ocamlspot-delete-overlays-now ()
   (interactive)
-  (delete-overlay ocamlspot-spot-overlay)
-  (delete-overlay ocamlspot-tree-overlay))
+  (delete-overlay ocamlspot-tree-overlay)
+  (delete-overlay ocamlspot-spot-overlay))
 
 (defun ocamlspot-delete-overlays ()
   (unwind-protect
       (sit-for 10)
     (ocamlspot-delete-overlays-now)))
 
-(defun ocamlspot-cnum-of-point () (1- (point)))
-(defun ocamlspot-char-of-cnum (n) (1+ n))
+; (defun ocamlspot-cnum-of-point () (1- (point)))
+; (defun ocamlspot-char-of-cnum (n) (1+ n))
 
 (defun ocamlspot-find-file-existing (path)
   (if (file-exists-p path)
       (find-file-other-window path)
-;;      (or (display-buffer (find-buffer-visiting path) t) (find-file-other-window path))
     (message "ERROR: source file %s was not found" path)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; column chars => column bytes
     (point)))
  
 (defun ocamlspot-string-of-line-to-point ()
-  (save-excursion
-    (buffer-substring-no-properties 
-     (ocamlspot-pos-beginning-of-line) (point))))
+  (buffer-substring-no-properties 
+   (ocamlspot-pos-beginning-of-line) (point)))
 
 (defun ocamlspot-bytes-of-line-to-point ()
   (length 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; column bytes => column chars  
 
+; goto-line set mark and we see the result in the minibuffer
+(defun ocamlspot-goto-line (line)
+  (goto-char (point-min))
+  (forward-line (- line 1)))
+
 ;; get the string at line
 (defun ocamlspot-buffer-substring-at-line (line)
-  (save-excursion
-    (goto-line line)
-    (beginning-of-line)
-    (let ((start (point)))
-      (end-of-line)
-      (buffer-substring-no-properties start (point)))))
+  ; no need of save-excursion
+  (ocamlspot-goto-line line)
+  (beginning-of-line)
+  (let ((start (point)))
+    (end-of-line)
+    (buffer-substring-no-properties start (point))))
 
 (defun ocamlspot-chars-of-bytes-of-string (str bytes)
   (length 
     buffer-file-coding-system)))
 
 (defun ocamlspot-pos-of-bytes-at-line (line bytes)
-  (save-excursion
-    (goto-line line)
-    (let ((pos-at-beginning-of-line (ocamlspot-pos-beginning-of-line))
-          (chars-from-beginning-of-line 
-           (ocamlspot-chars-of-bytes-of-string 
-            (ocamlspot-buffer-substring-at-line line) bytes)))
-      (+ pos-at-beginning-of-line chars-from-beginning-of-line))))
+  ; no need of save-excursion
+  (ocamlspot-goto-line line)
+  (let ((pos-at-beginning-of-line (ocamlspot-pos-beginning-of-line))
+        (chars-from-beginning-of-line 
+         (ocamlspot-chars-of-bytes-of-string 
+          (ocamlspot-buffer-substring-at-line line) bytes)))
+    (+ pos-at-beginning-of-line chars-from-beginning-of-line)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; location parser
 
 (defun ocamlspot-pos-of-location (buffer s)
   (destructuring-bind (line colbytes bytes) (ocamlspot-parse-location s)
     (if (= line -1) bytes
-      (save-current-buffer
+      (save-excursion
         (set-buffer buffer)
         (ocamlspot-pos-of-bytes-at-line line colbytes)))))
 
           (move-overlay overlay start end buffer)))
     ; this should be all
     (progn
-      (set-buffer buffer)
+      (display-buffer buffer)
       (move-overlay overlay (point-min) (point-max) buffer))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   (interactive)
   (ocamlspot-delete-overlays-now)
   ;; arguments
-  (let ((arg
-;         (format "%s:b%d" 
-;                 (buffer-file-name) 
-;                 (ocamlspot-cnum-of-point))
+  (let ((file-name (buffer-file-name))
+        (arg
          (format "%s:l%dc%d"
                  (buffer-file-name)
                  (ocamlspot-lines-of-point)
 		      debug
 		      extra_args
 		      '(arg))))
+        ;; chdir is required
+        (cd (file-name-directory file-name))
 	(eval command))
       ;; search the found tree element
       (goto-char (point-min))
         (message "Packed module: %s" filename)
         ;; CR jfuruse: opening a binary file is not good
         )
-    (progn
-      (let ((target-buffer (ocamlspot-find-file-existing filename)))
-        (ocamlspot-display-overlay target-buffer position ocamlspot-spot-overlay)))))
+    (ocamlspot-display-overlay 
+     (ocamlspot-find-file-existing filename)
+     position ocamlspot-spot-overlay)))
 
 (defun ocamlspot-query ()
   (interactive)
-  (if (ocamlspot-gen-query nil)
-      (save-current-buffer 
-        (save-selected-window
+  (save-selected-window
+    (if (ocamlspot-gen-query nil)
+        (save-excursion
           ;; search the result
-          (set-buffer (get-buffer-create ocamlspot-buffer))
-          (goto-char (point-min))
-          (if (re-search-forward "^Spot: \\(.*\\):\\(l[\-0-9]+c[\-0-9]+b[\-0-9]+:l[\-0-9]+c[\-0-9]+b[\-0-9]+\\|all\\)$" 
-                                 nil t)
-              (let ((filename (buffer-substring (match-beginning 1) 
-                                                (match-end 1)))
-                    (position (buffer-substring (match-beginning 2)
-                                                (match-end 2))))
-                ;; display the result
-                (ocamlspot-jump-to-spot filename position))
-            (progn
-              (if (re-search-forward "^Spot: \\(.*\\)" nil t)
-                  (message (buffer-substring (match-beginning 1) (match-end 1)))
-                (if (re-search-forward "^\\(Error: .*\\)" nil t)
+          (progn 
+            (set-buffer (get-buffer-create ocamlspot-buffer))
+            (goto-char (point-min))
+            (if (re-search-forward "^Spot: \\(.*\\):\\(l[\-0-9]+c[\-0-9]+b[\-0-9]+:l[\-0-9]+c[\-0-9]+b[\-0-9]+\\|all\\)$" 
+                                   nil t)
+                (let ((filename (buffer-substring (match-beginning 1) 
+                                                  (match-end 1)))
+                      (position (buffer-substring (match-beginning 2)
+                                                  (match-end 2))))
+                  ;; display the result
+                  (ocamlspot-jump-to-spot filename position))
+              (progn
+                (if (re-search-forward "^Spot: \\(.*\\)" nil t)
                     (message (buffer-substring (match-beginning 1) (match-end 1)))
-                  (progn
-                    ;; display debug info
-                    (message "No spot found there") 
-                    (display-buffer ocamlspot-buffer)))))))
-        (ocamlspot-delete-overlays) ; CR jfuruse: it depends on one's taste
-        )))
+                  (if (re-search-forward "^\\(Error: .*\\)" nil t)
+                      (message (buffer-substring (match-beginning 1) (match-end 1)))
+                    (progn
+                      ;; display debug info
+                      (message "No spot found there") 
+                      (display-buffer ocamlspot-buffer))))))))
+        )
+    (ocamlspot-delete-overlays)) ; CR jfuruse: it depends on one's taste
+  ; I dunno why but we need the following line to list-buffers work nicely
+  (select-window (selected-window)))
 
 (defun ocamlspot-type ()
   (interactive)

ocamlspot/ocamlspot.ml

     ident : Ident.t option; (* None means the top module *)
   } (* <= PIdent.t *)
 
-  let format ppf id = 
-    Format.fprintf ppf "%s:%s" 
-	(let len = String.length id.path (* ? PIdent.t *) in
-	if len > 20 then
-	  "..." ^ String.sub id.path (len - 20) 20 
-	else id.path)
+  let format ppf id =
+    Format.fprintf ppf "%s%s" 
+      (if id.path = "" then ""
+        else 
+          (let len = String.length id.path (* ? PIdent.t *) in
+	  if len > 20 then
+	    "..." ^ String.sub id.path (len - 20) 20 
+	  else id.path) ^ ":")
 	(match id.ident with
 	| Some id -> Ident.name id
 	| None -> "TOP")
 	      pident.PIdent.path
 	      (Location.to_string loc)
         | File.Predefined ->
-	    Format.printf "Spot: Predefined %s@."
-	      (Kind.name kind)
+	    Format.printf "Spot: %a: predefined %s@."
+	      PIdent.format pident
+              (Kind.name kind)
       with
       | Not_found -> Format.printf "Spot: no spot@."  
     in

ocamlspot/tests/Makefile.targets

 type_def.cmo \
 types_in_type_def.cmo \
 use_record.cmo \
+utf8.cmo \
 variant.cmo \
 variant_external.cmo \
 with_type.cmo \
+with_type2.cmo \

ocamlspot/tests/with_type.ml

 end
 (* <= S *)
 
-module type T = S (* ? S *) with type elt (* ? elt *) = int
+module type T = S (* ? S *) 
+  with type elt (* ? elt *) = int (* We have no position info for [elt] *)
 
 module M : functor(M' : S) -> sig type t end with type t = M'.elt (* ? elt *)
   = functor(M' : S) -> struct