Skip to content

Commit dd73154

Browse files
authored
make find-references behave better with simpler code (#100)
ensime-mode has a similar implementation, which does not rely on tabulated mode and I liked the shorter implementation (grep-mode makes it easy to kill the buffer with a single keystroke). Besides, set-window-dedicated-p helps make the buffer sticky.
1 parent 654f267 commit dd73154

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

phpactor.el

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -356,38 +356,26 @@ of GitHub.")
356356
(concat "..." (substring string (- 3 width)))
357357
string))
358358

359-
(defun phpactor-open-file-other-window (path offset)
360-
"Open PATH at OFFSET in a different window."
361-
(save-selected-window
362-
(when (buffer-live-p (get-file-buffer path))
363-
(switch-to-buffer-other-window (get-file-buffer path)))
364-
(phpactor-action-open-file :path path :offset offset)))
365-
366-
(defun phpactor-references-list-make-entry (file-reference index)
367-
"Return an entry for the tabulated list, for FILE-REFERENCE at INDEX."
368-
(let ((path (plist-get file-reference :file))
369-
(in-project-path (string-remove-prefix (phpactor-get-working-dir) (plist-get file-reference :file)))
370-
(references (car (plist-get file-reference :references))))
371-
(list index
372-
(vector (list
373-
(phpactor-truncate-left in-project-path phpactor-references-list-col1-width)
374-
. ('action
375-
(lambda (_event) (phpactor-open-file-other-window path (plist-get references :start)))
376-
'help-echo path))
377-
(number-to-string (plist-get references :line_no))))))
378-
379-
;; adapted from flycheck-list-errors
380-
(cl-defun phpactor-list-references ()
359+
(defun phpactor-list-references ()
360+
"View references in a new buffer."
381361
(interactive)
382362
(let ((current-references phpactor-references))
383-
(with-current-buffer (get-buffer-create phpactor-references-buffer)
384-
(setq tabulated-list-format (vector `("File" ,phpactor-references-list-col1-width nil) '("Line" 12 nil :right-align t))
385-
tabulated-list-padding 2
386-
tabulated-list-entries (seq-map-indexed #'phpactor-references-list-make-entry current-references))
387-
(tabulated-list-mode)
388-
(tabulated-list-init-header)
389-
(tabulated-list-print t)
390-
(switch-to-buffer-other-window phpactor-references-buffer))))
363+
(switch-to-buffer (get-buffer-create phpactor-references-buffer))
364+
(set-window-dedicated-p (get-buffer-window) t)
365+
(setq buffer-read-only nil)
366+
(erase-buffer)
367+
(dolist (file-reference current-references)
368+
(let ((path (plist-get file-reference :file)))
369+
(dolist (reference (plist-get file-reference :references))
370+
(when path
371+
(insert-text-button (phpactor-truncate-left path phpactor-references-list-col1-width)
372+
'action (lambda (_) (find-file path) (goto-char (plist-get reference :start)))
373+
'help-echo "mouse-2: visit this file in other window")
374+
(insert ": ")
375+
(insert (number-to-string (plist-get reference :line_no)))
376+
(insert "\n")))))
377+
(goto-char 0)
378+
(grep-mode)))
391379

392380
(cl-defun phpactor-action-collection (&key actions)
393381
"Executes a collection of actions."

0 commit comments

Comments
 (0)