summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2015-11-09 05:24:23 +0200
committerDmitry Gutov <dgutov@yandex.ru>2015-11-10 13:32:10 +0200
commit61dbe7654eeb732bf7b3128554f86bbba69245f9 (patch)
tree5f1465507df02dc162644c51bed819564f33f4e3
parenteddace3c0ec5c7eb412494e0dc9cc5b3dc415617 (diff)
downloademacs-scratch/xref-next.tar.gz
Handle multiple matches on the same line; add highlightingscratch/xref-next
-rw-r--r--lisp/progmodes/xref.el44
1 files changed, 23 insertions, 21 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index c6af6c25c90..8675c95ff9e 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -114,7 +114,7 @@ Line numbers start from 1 and columns from 0.")
(save-excursion
(goto-char (point-min))
(beginning-of-line line)
- (move-to-column column)
+ (forward-char column)
(point-marker))))))
(cl-defmethod xref-location-group ((l xref-file-location))
@@ -821,10 +821,9 @@ tools are used, and when."
(hits (and res (oref res hit-lines)))
(orig-buffers (buffer-list)))
(unwind-protect
- (delq nil
- (mapcar (lambda (hit) (xref--collect-match
- hit (format "\\_<%s\\_>" (regexp-quote symbol))))
- hits))
+ (cl-mapcan (lambda (hit) (xref--collect-matches
+ hit (format "\\_<%s\\_>" (regexp-quote symbol))))
+ hits)
(mapc #'kill-buffer
(cl-set-difference (buffer-list) orig-buffers)))))
@@ -855,9 +854,8 @@ IGNORES is a list of glob patterns."
(match-string 1))
hits)))
(unwind-protect
- (delq nil
- (mapcar (lambda (hit) (xref--collect-match hit regexp))
- (nreverse hits)))
+ (cl-mapcan (lambda (hit) (xref--collect-matches hit regexp))
+ (nreverse hits))
(mapc #'kill-buffer
(cl-set-difference (buffer-list) orig-buffers)))))
@@ -913,7 +911,7 @@ IGNORES is a list of glob patterns."
(match-string 1 str)))))
str t t))
-(defun xref--collect-match (hit regexp)
+(defun xref--collect-matches (hit regexp)
(pcase-let* ((`(,line . ,file) hit)
(buf (or (find-buffer-visiting file)
(semantic-find-file-noselect file))))
@@ -921,18 +919,22 @@ IGNORES is a list of glob patterns."
(save-excursion
(goto-char (point-min))
(forward-line (1- line))
- (syntax-propertize (line-end-position))
- ;; TODO: Handle multiple matches per line.
- (when (re-search-forward regexp (line-end-position) t)
- (goto-char (match-beginning 0))
- (let ((loc (xref-make-file-location file line
- (current-column))))
- (goto-char (match-end 0))
- (xref-make-match (buffer-substring
- (line-beginning-position)
- (line-end-position))
- loc
- (- (match-end 0) (match-beginning 0)))))))))
+ (let ((line-end (line-end-position))
+ (line-beg (line-beginning-position))
+ matches)
+ (syntax-propertize line-end)
+ ;; FIXME: This results in several lines with the same
+ ;; summary. Solve with composite pattern?
+ (while (re-search-forward regexp line-end t)
+ (let* ((beg-column (- (match-beginning 0) line-beg))
+ (end-column (- (match-end 0) line-beg))
+ (loc (xref-make-file-location file line beg-column))
+ (summary (buffer-substring line-beg line-end)))
+ (add-face-text-property beg-column end-column 'highlight
+ t summary)
+ (push (xref-make-match summary loc (- end-column beg-column))
+ matches)))
+ (nreverse matches))))))
(provide 'xref)