diff options
| author | Dmitry Gutov | 2015-11-09 05:24:23 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2015-11-10 13:32:10 +0200 |
| commit | 61dbe7654eeb732bf7b3128554f86bbba69245f9 (patch) | |
| tree | 5f1465507df02dc162644c51bed819564f33f4e3 | |
| parent | eddace3c0ec5c7eb412494e0dc9cc5b3dc415617 (diff) | |
| download | emacs-scratch/xref-next.tar.gz emacs-scratch/xref-next.zip | |
Handle multiple matches on the same line; add highlightingscratch/xref-next
| -rw-r--r-- | lisp/progmodes/xref.el | 44 |
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.") | |||
| 114 | (save-excursion | 114 | (save-excursion |
| 115 | (goto-char (point-min)) | 115 | (goto-char (point-min)) |
| 116 | (beginning-of-line line) | 116 | (beginning-of-line line) |
| 117 | (move-to-column column) | 117 | (forward-char column) |
| 118 | (point-marker)))))) | 118 | (point-marker)))))) |
| 119 | 119 | ||
| 120 | (cl-defmethod xref-location-group ((l xref-file-location)) | 120 | (cl-defmethod xref-location-group ((l xref-file-location)) |
| @@ -821,10 +821,9 @@ tools are used, and when." | |||
| 821 | (hits (and res (oref res hit-lines))) | 821 | (hits (and res (oref res hit-lines))) |
| 822 | (orig-buffers (buffer-list))) | 822 | (orig-buffers (buffer-list))) |
| 823 | (unwind-protect | 823 | (unwind-protect |
| 824 | (delq nil | 824 | (cl-mapcan (lambda (hit) (xref--collect-matches |
| 825 | (mapcar (lambda (hit) (xref--collect-match | 825 | hit (format "\\_<%s\\_>" (regexp-quote symbol)))) |
| 826 | hit (format "\\_<%s\\_>" (regexp-quote symbol)))) | 826 | hits) |
| 827 | hits)) | ||
| 828 | (mapc #'kill-buffer | 827 | (mapc #'kill-buffer |
| 829 | (cl-set-difference (buffer-list) orig-buffers))))) | 828 | (cl-set-difference (buffer-list) orig-buffers))))) |
| 830 | 829 | ||
| @@ -855,9 +854,8 @@ IGNORES is a list of glob patterns." | |||
| 855 | (match-string 1)) | 854 | (match-string 1)) |
| 856 | hits))) | 855 | hits))) |
| 857 | (unwind-protect | 856 | (unwind-protect |
| 858 | (delq nil | 857 | (cl-mapcan (lambda (hit) (xref--collect-matches hit regexp)) |
| 859 | (mapcar (lambda (hit) (xref--collect-match hit regexp)) | 858 | (nreverse hits)) |
| 860 | (nreverse hits))) | ||
| 861 | (mapc #'kill-buffer | 859 | (mapc #'kill-buffer |
| 862 | (cl-set-difference (buffer-list) orig-buffers))))) | 860 | (cl-set-difference (buffer-list) orig-buffers))))) |
| 863 | 861 | ||
| @@ -913,7 +911,7 @@ IGNORES is a list of glob patterns." | |||
| 913 | (match-string 1 str))))) | 911 | (match-string 1 str))))) |
| 914 | str t t)) | 912 | str t t)) |
| 915 | 913 | ||
| 916 | (defun xref--collect-match (hit regexp) | 914 | (defun xref--collect-matches (hit regexp) |
| 917 | (pcase-let* ((`(,line . ,file) hit) | 915 | (pcase-let* ((`(,line . ,file) hit) |
| 918 | (buf (or (find-buffer-visiting file) | 916 | (buf (or (find-buffer-visiting file) |
| 919 | (semantic-find-file-noselect file)))) | 917 | (semantic-find-file-noselect file)))) |
| @@ -921,18 +919,22 @@ IGNORES is a list of glob patterns." | |||
| 921 | (save-excursion | 919 | (save-excursion |
| 922 | (goto-char (point-min)) | 920 | (goto-char (point-min)) |
| 923 | (forward-line (1- line)) | 921 | (forward-line (1- line)) |
| 924 | (syntax-propertize (line-end-position)) | 922 | (let ((line-end (line-end-position)) |
| 925 | ;; TODO: Handle multiple matches per line. | 923 | (line-beg (line-beginning-position)) |
| 926 | (when (re-search-forward regexp (line-end-position) t) | 924 | matches) |
| 927 | (goto-char (match-beginning 0)) | 925 | (syntax-propertize line-end) |
| 928 | (let ((loc (xref-make-file-location file line | 926 | ;; FIXME: This results in several lines with the same |
| 929 | (current-column)))) | 927 | ;; summary. Solve with composite pattern? |
| 930 | (goto-char (match-end 0)) | 928 | (while (re-search-forward regexp line-end t) |
| 931 | (xref-make-match (buffer-substring | 929 | (let* ((beg-column (- (match-beginning 0) line-beg)) |
| 932 | (line-beginning-position) | 930 | (end-column (- (match-end 0) line-beg)) |
| 933 | (line-end-position)) | 931 | (loc (xref-make-file-location file line beg-column)) |
| 934 | loc | 932 | (summary (buffer-substring line-beg line-end))) |
| 935 | (- (match-end 0) (match-beginning 0))))))))) | 933 | (add-face-text-property beg-column end-column 'highlight |
| 934 | t summary) | ||
| 935 | (push (xref-make-match summary loc (- end-column beg-column)) | ||
| 936 | matches))) | ||
| 937 | (nreverse matches)))))) | ||
| 936 | 938 | ||
| 937 | (provide 'xref) | 939 | (provide 'xref) |
| 938 | 940 | ||