Skip to content

Commit a34cc1c

Browse files
committed
[emacs] handle project-wide-occurrences in occur-mode
1 parent 34e2688 commit a34cc1c

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

emacs/merlin.el

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,37 +1784,33 @@ Empty string defaults to jumping to all these."
17841784
(let ((inhibit-read-only t)
17851785
(buffer-undo-list t)
17861786
(pending-line)
1787-
(pending-lines-text))
1787+
(pending-lines-text)
1788+
(previous-buf))
17881789
(erase-buffer)
17891790
(occur-mode)
1790-
(insert (propertize (format "%d occurrences in buffer: %s"
1791-
(length lst)
1792-
src-buff)
1793-
'font-lock-face list-matching-lines-buffer-name-face
1794-
'read-only t
1795-
'occur-title (get-buffer src-buff)))
1796-
(insert "\n")
17971791
(dolist (pos positions)
1798-
(let* ((marker (cdr (assoc 'marker pos)))
1799-
(start (assoc 'start pos))
1792+
(let* ((start (assoc 'start pos))
18001793
(end (assoc 'end pos))
1794+
(file (cdr (assoc 'file pos)))
1795+
(occ-buff (if file (find-file-noselect file) src-buff))
1796+
(marker (with-current-buffer occ-buff
1797+
(copy-marker (merlin--point-of-pos start))))
18011798
(line (cdr (assoc 'line start)))
1802-
(start-buf-pos (with-current-buffer src-buff
1799+
(start-buf-pos (with-current-buffer occ-buff
18031800
(merlin--point-of-pos start)))
1804-
(end-buf-pos (with-current-buffer src-buff
1801+
(end-buf-pos (with-current-buffer occ-buff
18051802
(merlin--point-of-pos end)))
18061803
(prefix-length 8)
18071804
(start-offset (+ prefix-length
18081805
(cdr (assoc 'col start))))
18091806
(lines-text
1810-
(if (equal line pending-line)
1811-
pending-lines-text
1807+
(if (and (equal line pending-line) occ-buff)
1808+
pending-lines-text
18121809
(merlin--occurrence-text line
18131810
marker
18141811
start-buf-pos
18151812
end-buf-pos
1816-
src-buff))))
1817-
1813+
occ-buff))))
18181814
;; Insert the critical text properties that occur-mode
18191815
;; makes use of
18201816
(add-text-properties start-offset
@@ -1828,9 +1824,22 @@ Empty string defaults to jumping to all these."
18281824
;; found in order to accumulate multiple matches within
18291825
;; one line.
18301826
(when (and pending-lines-text
1831-
(not (equal line pending-line)))
1827+
(or (not (equal line pending-line))
1828+
(not (equal previous-buf occ-buff))))
18321829
(insert pending-lines-text))
1830+
1831+
(when (not (equal previous-buf occ-buff))
1832+
(insert (propertize (format "Occurrences in buffer %s:"
1833+
;(length lst)
1834+
occ-buff)
1835+
'font-lock-face
1836+
list-matching-lines-buffer-name-face
1837+
'read-only t
1838+
'occur-title occ-buff))
1839+
(insert "\n"))
1840+
18331841
(setq pending-line line)
1842+
(setq previous-buf occ-buff)
18341843
(setq pending-lines-text lines-text)))
18351844

18361845
;; Catch final pending text
@@ -1860,6 +1869,19 @@ Empty string defaults to jumping to all these."
18601869
(merlin-occurrences-list r)
18611870
(error "%s" r)))))
18621871

1872+
(defun merlin--project-occurrences ()
1873+
(merlin-call "occurrences" "-scope" "project" "-identifier-at"
1874+
(merlin-unmake-point (point))))
1875+
1876+
(defun merlin-project-occurrences ()
1877+
"List all occurrences of identifier under cursor in buffer."
1878+
(interactive)
1879+
(let ((r (merlin--project-occurrences)))
1880+
(when r
1881+
(if (listp r)
1882+
(merlin-occurrences-list r)
1883+
(error "%s" r)))))
1884+
18631885
;;;;;;;;;;;;;;;;;;;
18641886
;; OPEN REFACTOR ;;
18651887
;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)