]> git.eshelyaron.com Git - emacs.git/commitdiff
Generic-ify xref-location-column
authorDmitry Gutov <dgutov@yandex.ru>
Mon, 21 Dec 2020 01:38:37 +0000 (03:38 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 21 Dec 2020 01:38:37 +0000 (03:38 +0200)
* 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.

lisp/progmodes/xref.el
test/lisp/progmodes/xref-tests.el

index f33dfb4f5de6715b57314d6996d7e2bc9c7a91a8..181f94b0bc679342293e4f9baed460e485e5ca90 100644 (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)
index 038f9d0e304d0df13c7c2938670ef0c3f35c5c26..e220d09dada9846037313a5b87e59ae5a7618e74 100644 (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))