diff --git a/emacs/merlin.el b/emacs/merlin.el index 9100dfa360..06212e1b41 100644 --- a/emacs/merlin.el +++ b/emacs/merlin.el @@ -1784,24 +1784,20 @@ Empty string defaults to jumping to all these." (let ((inhibit-read-only t) (buffer-undo-list t) (pending-line) - (pending-lines-text)) + (pending-lines-text) + (previous-buf)) (erase-buffer) (occur-mode) - (insert (propertize (format "%d occurrences in buffer: %s" - (length lst) - src-buff) - 'font-lock-face list-matching-lines-buffer-name-face - 'read-only t - 'occur-title (get-buffer src-buff))) - (insert "\n") (dolist (pos positions) - (let* ((marker (cdr (assoc 'marker pos))) - (start (assoc 'start pos)) + (let* ((start (assoc 'start pos)) (end (assoc 'end pos)) + (occ-buff (find-file-noselect (cdr (assoc 'file pos)))) + (marker (with-current-buffer occ-buff + (copy-marker (merlin--point-of-pos start)))) (line (cdr (assoc 'line start))) - (start-buf-pos (with-current-buffer src-buff + (start-buf-pos (with-current-buffer occ-buff (merlin--point-of-pos start))) - (end-buf-pos (with-current-buffer src-buff + (end-buf-pos (with-current-buffer occ-buff (merlin--point-of-pos end))) (prefix-length 8) (start-offset (+ prefix-length @@ -1813,8 +1809,7 @@ Empty string defaults to jumping to all these." marker start-buf-pos end-buf-pos - src-buff)))) - + occ-buff)))) ;; Insert the critical text properties that occur-mode ;; makes use of (add-text-properties start-offset @@ -1828,9 +1823,22 @@ Empty string defaults to jumping to all these." ;; found in order to accumulate multiple matches within ;; one line. (when (and pending-lines-text - (not (equal line pending-line))) + (or (not (equal line pending-line)) + (not (equal previous-buf occ-buff)))) (insert pending-lines-text)) + + (when (not (equal previous-buf occ-buff)) + (insert (propertize (format "Occurrences in buffer: %s" + ;(length lst) + occ-buff) + 'font-lock-face + list-matching-lines-buffer-name-face + 'read-only t + 'occur-title occ-buff)) + (insert "\n")) + (setq pending-line line) + (setq previous-buf occ-buff) (setq pending-lines-text lines-text))) ;; Catch final pending text @@ -1860,6 +1868,19 @@ Empty string defaults to jumping to all these." (merlin-occurrences-list r) (error "%s" r))))) +(defun merlin--project-occurrences () + (merlin-call "occurrences" "-scope" "project" "-identifier-at" + (merlin-unmake-point (point)))) + +(defun merlin-project-occurrences () + "List all occurrences of identifier under cursor in buffer." + (interactive) + (let ((r (merlin--project-occurrences))) + (when r + (if (listp r) + (merlin-occurrences-list r) + (error "%s" r))))) + ;;;;;;;;;;;;;;;;;;; ;; OPEN REFACTOR ;; ;;;;;;;;;;;;;;;;;;;