Generic-ify xref-location-column

* lisp/progmodes/xref.el (xref-location-column):
Create a generic from xref-file-location-column, to use in the
common rendering code (bug#36967).
(xref--insert-xrefs): Update accordingly.

* test/lisp/progmodes/xref-tests.el
(xref-matches-in-directory-finds-two-matches-on-the-same-line)
(xref-matches-in-directory-finds-an-empty-line-regexp-match):
Ditto.
This commit is contained in:
Dmitry Gutov 2020-12-21 03:38:37 +02:00
parent c3ad28c290
commit 759ec25769
2 changed files with 9 additions and 5 deletions

View file

@ -97,6 +97,10 @@ This is typically the filename.")
"Return the line number corresponding to the location."
nil)
(cl-defgeneric xref-location-column (_location)
"Return the exact column corresponding to the location."
nil)
(cl-defgeneric xref-match-length (_item)
"Return the length of the match."
nil)
@ -118,7 +122,7 @@ part of the file name."
(defclass xref-file-location (xref-location)
((file :type string :initarg :file)
(line :type fixnum :initarg :line :reader xref-location-line)
(column :type fixnum :initarg :column :reader xref-file-location-column))
(column :type fixnum :initarg :column :reader xref-location-column))
:documentation "A file location is a file/line/column triple.
Line numbers start from 1 and columns from 0.")
@ -869,7 +873,7 @@ GROUP is a string for decoration purposes and XREF is an
" ")))
;; Render multiple matches on the same line, together.
(when (and line (equal prev-line-key line-key))
(let ((column (xref-file-location-column location)))
(when-let ((column (xref-location-column location)))
(delete-region
(save-excursion
(forward-line -1)

View file

@ -52,8 +52,8 @@
(should (string-match-p "file1\\.txt\\'" (xref-location-group (nth 1 locs))))
(should (equal 1 (xref-location-line (nth 0 locs))))
(should (equal 1 (xref-location-line (nth 1 locs))))
(should (equal 0 (xref-file-location-column (nth 0 locs))))
(should (equal 4 (xref-file-location-column (nth 1 locs))))))
(should (equal 0 (xref-location-column (nth 0 locs))))
(should (equal 4 (xref-location-column (nth 1 locs))))))
(ert-deftest xref-matches-in-directory-finds-an-empty-line-regexp-match ()
(let* ((matches (xref-matches-in-directory "^$" "*" xref-tests-data-dir nil))
@ -61,7 +61,7 @@
(should (= 1 (length matches)))
(should (string-match-p "file2\\.txt\\'" (xref-location-group (nth 0 locs))))
(should (equal 1 (xref-location-line (nth 0 locs))))
(should (equal 0 (xref-file-location-column (nth 0 locs))))))
(should (equal 0 (xref-location-column (nth 0 locs))))))
(ert-deftest xref--buf-pairs-iterator-groups-markers-by-buffers-1 ()
(let* ((xrefs (xref-matches-in-directory "foo" "*" xref-tests-data-dir nil))