diff options
| -rw-r--r-- | lisp/progmodes/etags.el | 4 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 39 |
2 files changed, 31 insertions, 12 deletions
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 4e923aac197..6acafdbaba0 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el | |||
| @@ -2143,6 +2143,10 @@ for \\[find-tag] (which see)." | |||
| 2143 | (etags-goto-tag-location tag-info) | 2143 | (etags-goto-tag-location tag-info) |
| 2144 | (point-marker))))) | 2144 | (point-marker))))) |
| 2145 | 2145 | ||
| 2146 | (cl-defmethod xref-location-line ((l xref-etags-location)) | ||
| 2147 | (with-slots (tag-info) l | ||
| 2148 | (nth 1 tag-info))) | ||
| 2149 | |||
| 2146 | 2150 | ||
| 2147 | (provide 'etags) | 2151 | (provide 'etags) |
| 2148 | 2152 | ||
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index ae0fbb82617..657657c687a 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -73,13 +73,17 @@ | |||
| 73 | "Return a string used to group a set of locations. | 73 | "Return a string used to group a set of locations. |
| 74 | This is typically the filename.") | 74 | This is typically the filename.") |
| 75 | 75 | ||
| 76 | (cl-defgeneric xref-location-line (_location) | ||
| 77 | "Return the line number corresponding to the location." | ||
| 78 | nil) | ||
| 79 | |||
| 76 | ;;;; Commonly needed location classes are defined here: | 80 | ;;;; Commonly needed location classes are defined here: |
| 77 | 81 | ||
| 78 | ;; FIXME: might be useful to have an optional "hint" i.e. a string to | 82 | ;; FIXME: might be useful to have an optional "hint" i.e. a string to |
| 79 | ;; search for in case the line number is sightly out of date. | 83 | ;; search for in case the line number is sightly out of date. |
| 80 | (defclass xref-file-location (xref-location) | 84 | (defclass xref-file-location (xref-location) |
| 81 | ((file :type string :initarg :file) | 85 | ((file :type string :initarg :file) |
| 82 | (line :type fixnum :initarg :line) | 86 | (line :type fixnum :initarg :line :reader xref-location-line) |
| 83 | (column :type fixnum :initarg :column)) | 87 | (column :type fixnum :initarg :column)) |
| 84 | :documentation "A file location is a file/line/column triple. | 88 | :documentation "A file location is a file/line/column triple. |
| 85 | Line numbers start from 1 and columns from 0.") | 89 | Line numbers start from 1 and columns from 0.") |
| @@ -435,9 +439,10 @@ Used for temporary buffers.") | |||
| 435 | (xref-show-location-at-point)) | 439 | (xref-show-location-at-point)) |
| 436 | 440 | ||
| 437 | (defun xref--location-at-point () | 441 | (defun xref--location-at-point () |
| 438 | (save-excursion | 442 | (let ((pos (next-single-char-property-change (line-beginning-position) |
| 439 | (back-to-indentation) | 443 | 'xref-location |
| 440 | (get-text-property (point) 'xref-location))) | 444 | nil (line-end-position)))) |
| 445 | (and pos (get-text-property pos 'xref-location)))) | ||
| 441 | 446 | ||
| 442 | (defvar-local xref--window nil | 447 | (defvar-local xref--window nil |
| 443 | "ACTION argument to call `display-buffer' with.") | 448 | "ACTION argument to call `display-buffer' with.") |
| @@ -531,11 +536,24 @@ XREF-ALIST is of the form ((GROUP . (XREF ...)) ...). Where | |||
| 531 | GROUP is a string for decoration purposes and XREF is an | 536 | GROUP is a string for decoration purposes and XREF is an |
| 532 | `xref--xref' object." | 537 | `xref--xref' object." |
| 533 | (require 'compile) ;; For the compilation-info face. | 538 | (require 'compile) ;; For the compilation-info face. |
| 534 | (cl-loop for ((group . xrefs) . more1) on xref-alist do | 539 | (cl-loop for ((group . xrefs) . more1) on xref-alist |
| 540 | for max-line-width = | ||
| 541 | (cl-loop for xref in xrefs | ||
| 542 | maximize (let ((line (xref-location-line | ||
| 543 | (oref xref :location)))) | ||
| 544 | (length (and line (format "%d" line))))) | ||
| 545 | for line-format = (and max-line-width | ||
| 546 | (format "%%%dd: " max-line-width)) | ||
| 547 | do | ||
| 535 | (xref--insert-propertized '(face compilation-info) group "\n") | 548 | (xref--insert-propertized '(face compilation-info) group "\n") |
| 536 | (cl-loop for (xref . more2) on xrefs do | 549 | (cl-loop for (xref . more2) on xrefs do |
| 537 | (insert " ") | ||
| 538 | (with-slots (description location) xref | 550 | (with-slots (description location) xref |
| 551 | (let ((line (xref-location-line location))) | ||
| 552 | (if line | ||
| 553 | (xref--insert-propertized | ||
| 554 | '(face compilation-line-number) | ||
| 555 | (format line-format line)) | ||
| 556 | (insert " "))) | ||
| 539 | (xref--insert-propertized | 557 | (xref--insert-propertized |
| 540 | (list 'xref-location location | 558 | (list 'xref-location location |
| 541 | ;; 'face 'font-lock-keyword-face | 559 | ;; 'face 'font-lock-keyword-face |
| @@ -729,12 +747,9 @@ tools are used, and when." | |||
| 729 | (regexp-quote name)) | 747 | (regexp-quote name)) |
| 730 | (line-end-position) t) | 748 | (line-end-position) t) |
| 731 | (goto-char (match-beginning 0)) | 749 | (goto-char (match-beginning 0)) |
| 732 | (xref-make (format | 750 | (xref-make (buffer-substring |
| 733 | "%d: %s" | 751 | (line-beginning-position) |
| 734 | line | 752 | (line-end-position)) |
| 735 | (buffer-substring | ||
| 736 | (line-beginning-position) | ||
| 737 | (line-end-position))) | ||
| 738 | (xref-make-file-location file line | 753 | (xref-make-file-location file line |
| 739 | (current-column)))))))) | 754 | (current-column)))))))) |
| 740 | 755 | ||