Skip to content

Commit

Permalink
[emacs] handle project-wide-occurrences in occur-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed May 13, 2024
1 parent e249132 commit 4fd2cf3
Showing 1 changed file with 36 additions and 15 deletions.
51 changes: 36 additions & 15 deletions emacs/merlin.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ;;
;;;;;;;;;;;;;;;;;;;
Expand Down

0 comments on commit 4fd2cf3

Please sign in to comment.