Stephen Weeks avatar Stephen Weeks committed c33764b

Added dwang's improvement to ocamlspot-query-uses that uses grep-mode. It doesn't work
yet for me.

Comments (0)

Files changed (1)


 ;   Show the use information of the identifier under the cursor.
 ; ocamlspot-xtype
-;   Same as ocamlspot-type but it shows you more detailed information: 
+;   Same as ocamlspot-type but it shows you more detailed information:
 ;   path id numbers. You can browse path names in this result using C-c;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Configurable variables
     (ocamlspot-string-of-line-to-point) buffer-file-coding-system)))
-; It count one line less when the cursor is at (point-max) 
+; It count one line less when the cursor is at (point-max)
 ; and it is at the top of the line.
 (defun ocamlspot-lines-of-point ()
   (count-lines (point-min) (min (1+ (point)) (point-max))))
 ; Otherwise, returns nil
 (defun ocamlspot-message-display (&optional may-pop)
   (with-current-buffer (get-buffer-create ocamlspot-message-buffer)
-    (let ((lines ; how many lines in minibuffer-window ? 
+    (let ((lines ; how many lines in minibuffer-window ?
            (count-screen-lines nil nil nil (minibuffer-window)))
-          (max-echo-height 
+          (max-echo-height
            (if resize-mini-windows
                (cond ((floatp max-mini-window-height)
                       (* (frame-height) max-mini-window-height))
   (let ((file-name (buffer-file-name))
 	(arg (ocamlspot-query-string-at-cursor))
 	(post_sep (if post_extra_args " " "")))
-    (ocamlspot-run-query (concat pre_extra_args " " arg post_sep post_extra_args) 
+    (ocamlspot-run-query (concat pre_extra_args " " arg post_sep post_extra_args)
 			 (file-name-directory file-name))))
 ;;; Search ocamlspot-process-buffer and return the first line which matches with ^<pattern>: "
       (with-current-buffer (get-buffer-create ocamlspot-process-buffer)
 	;; search the found tree element
 	(let ((tree (ocamlspot-find-query-result "Tree")))
-	  (if tree 
+	  (if tree
 	      (if (string-match "^\\(l[\-0-9]+c[\-0-9]+b[\-0-9]+:l[\-0-9]+c[\-0-9]+b[\-0-9]+\\|[0-9]+:[0-9]+\\)$" tree)
 		  (let ((pos (match-string 1 tree)))
 		    ;; display the result
 (defun ocamlspot-find-type (&optional to-kill)
   (let ((type (ocamlspot-find-query-result "Type" to-kill)))
-    (if type 
+    (if type
 	  (ocamlspot-message-add (format "Type: %s" type))
 	  (ocamlspot-type-add (format "Type: %s" type))
 (defun ocamlspot-find-val-or-type (&optional to-kill)
   (let ((type (ocamlspot-find-query-result "Val" to-kill)))
     (if type
-	(progn 
+	(progn
 	  (ocamlspot-message-add (format "Val: %s" type))
 	  (ocamlspot-type-add (format "Val: %s" type))
 (defun ocamlspot-find-use ()
   (let ((use (ocamlspot-find-query-result "Use")))
     (if use
-	(progn 
+	(progn
 	  (ocamlspot-message-add (format "Use: %s" use))
       (ocamlspot-message-add "no use information found here")
   (ocamlspot-message-init (buffer-file-name))
-  (ocamlspot-query-at-cursor "-n")  
+  (ocamlspot-query-at-cursor "-n")
   (if (ocamlspot-find-tree)
         (ocamlspot-find-val-or-type to-kill)))
   (ocamlspot-wait t))
 ; CR can be shared with ocamlspot-type
+;; (defun ocamlspot-query-uses ()
+;;   (interactive)
+;;   (let ((dir (read-directory-name "Search directory: "
+;; 				  (file-name-directory (buffer-file-name)))))
+;;     (ocamlspot-message-init (buffer-file-name))
+;;     (ocamlspot-type-init)
+;;     (ocamlspot-delete-overlays-now)
+;;     (ocamlspot-query-at-cursor "use" dir)
+;;     (if (ocamlspot-find-tree)
+;; 	(progn
+;; 	 (ocamlspot-find-spot)
+;;          (select-window (display-buffer ocamlspot-process-buffer))
+;;          (grep-mode)
+;; 	 (ocamlspot-find-use)))
+;;     (ocamlspot-wait t)))
+;; dwang's improved ocamlspot-query-uses that uses grep mode so one can easily step
+;; through the uses.
+(add-to-list 'grep-regexp-alist
+             '("^<\\([^:]+\\):l\\([0-9]+\\)c\\([0-9]+\\)b[0-9]+:l\\([0-9]+\\)c\\([0-9]+\\)"
+               1 (2 . 4) (3 . 5)))
 (defun ocamlspot-query-uses ()
   (let ((dir (read-directory-name "Search directory: "
-				  (file-name-directory (buffer-file-name)))))
+                                  (file-name-directory (buffer-file-name)))))
     (ocamlspot-message-init (buffer-file-name))
     (ocamlspot-query-at-cursor "use" dir)
     (if (ocamlspot-find-tree)
-	(progn
-	 (ocamlspot-find-spot)
-	 (display-buffer ocamlspot-process-buffer)
-	 (ocamlspot-find-use)))
+        (progn
+          (ocamlspot-find-spot)
+          ;; put the point into the ocamlspot-process-buffer
+          (select-window (display-buffer ocamlspot-process-buffer))
+          ;; turn on grep mode
+          (with-current-buffer ocamlspot-process-buffer (grep-mode))
+          (ocamlspot-find-use)))
     (ocamlspot-wait t)))
 ;; Browsing of path-range <file:lxcxbx:lxcxbx>
 ;; build query string for the cursor point
 (defun ocamlspot-xtype-build-query-at-cursor ()
-  (let ((path-name 
+  (let ((path-name
 	   (let ((end
 ;; Preferable, but not working correctly yet for A.B<cursor>.t
 		  (if (skip-chars-backward "A-z0-9_().")
-	     (if (and start end) 
+	     (if (and start end)
 		   (move-overlay ocamlspot-tree-overlay start end)
 		   (buffer-substring-no-properties start end)))))))
     (message (concat "path-name " path-name))
-    (let ((file-name 
+    (let ((file-name
 	     (goto-char (point-min))
 	     (if (re-search-forward "^(\\* \\(.*\\) \\*)$" nil t)
 		 (match-string 1)))))
-      (if (and 
-	   file-name 
-	   path-name 
-	   (not (string= file-name "")) 
+      (if (and
+	   file-name
+	   path-name
+	   (not (string= file-name ""))
 	   (not (string= path-name "")))
 	  (concat file-name ":t:" path-name)))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.