diff options
| author | K. Handa | 2015-05-02 22:39:54 +0900 |
|---|---|---|
| committer | K. Handa | 2015-05-02 22:39:54 +0900 |
| commit | 40e720d049693dfe0c5559a8a8285a0b5cc6c5e2 (patch) | |
| tree | 46b84f79be0930e7fa729ae06836b90892e3d9b5 /lisp/progmodes | |
| parent | c3c9dab41b637b53034dd2f3dce6bf042380adae (diff) | |
| parent | 0bbc027356b680f32ac7b2d47d43a65d01091032 (diff) | |
| download | emacs-40e720d049693dfe0c5559a8a8285a0b5cc6c5e2.tar.gz emacs-40e720d049693dfe0c5559a8a8285a0b5cc6c5e2.zip | |
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'lisp/progmodes')
| -rw-r--r-- | lisp/progmodes/cmacexp.el | 4 | ||||
| -rw-r--r-- | lisp/progmodes/elisp-mode.el | 21 | ||||
| -rw-r--r-- | lisp/progmodes/etags.el | 9 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 43 |
4 files changed, 75 insertions, 2 deletions
diff --git a/lisp/progmodes/cmacexp.el b/lisp/progmodes/cmacexp.el index 357625d10cf..19d0473c42d 100644 --- a/lisp/progmodes/cmacexp.el +++ b/lisp/progmodes/cmacexp.el | |||
| @@ -364,8 +364,8 @@ Optional arg DISPLAY non-nil means show messages in the echo area." | |||
| 364 | ;; Find and delete the mark of the start of the expansion. | 364 | ;; Find and delete the mark of the start of the expansion. |
| 365 | ;; Look for `# nn "file.c"' lines and delete them. | 365 | ;; Look for `# nn "file.c"' lines and delete them. |
| 366 | (goto-char (point-min)) | 366 | (goto-char (point-min)) |
| 367 | (search-forward startmarker) | 367 | (if (search-forward startmarker nil t) |
| 368 | (delete-region 1 (point))) | 368 | (delete-region 1 (point)))) |
| 369 | (while (re-search-forward (concat "^# [0-9]+ \"" | 369 | (while (re-search-forward (concat "^# [0-9]+ \"" |
| 370 | (regexp-quote filename) | 370 | (regexp-quote filename) |
| 371 | "\"") nil t) | 371 | "\"") nil t) |
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index f2890686e79..2bb661a59c8 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el | |||
| @@ -587,6 +587,8 @@ It can be quoted, or be inside a quoted form." | |||
| 587 | (let ((sym (intern-soft id))) | 587 | (let ((sym (intern-soft id))) |
| 588 | (when sym | 588 | (when sym |
| 589 | (elisp--xref-find-definitions sym)))) | 589 | (elisp--xref-find-definitions sym)))) |
| 590 | (`references | ||
| 591 | (elisp--xref-find-references id)) | ||
| 590 | (`apropos | 592 | (`apropos |
| 591 | (elisp--xref-find-apropos id)))) | 593 | (elisp--xref-find-apropos id)))) |
| 592 | 594 | ||
| @@ -635,6 +637,25 @@ It can be quoted, or be inside a quoted form." | |||
| 635 | lst)))) | 637 | lst)))) |
| 636 | lst))) | 638 | lst))) |
| 637 | 639 | ||
| 640 | (defun elisp--xref-find-references (symbol) | ||
| 641 | (let* ((dirs (sort | ||
| 642 | (mapcar | ||
| 643 | (lambda (dir) | ||
| 644 | (file-name-as-directory (expand-file-name dir))) | ||
| 645 | (cons package-user-dir load-path)) | ||
| 646 | #'string<)) | ||
| 647 | (ref dirs)) | ||
| 648 | ;; Delete subdirectories from the list. | ||
| 649 | (while (cdr ref) | ||
| 650 | (if (string-prefix-p (car ref) (cadr ref)) | ||
| 651 | (setcdr ref (cddr ref)) | ||
| 652 | (setq ref (cdr ref)))) | ||
| 653 | (cl-mapcan | ||
| 654 | (lambda (dir) | ||
| 655 | (and (file-exists-p dir) | ||
| 656 | (xref-collect-references symbol dir))) | ||
| 657 | dirs))) | ||
| 658 | |||
| 638 | (defun elisp--xref-find-apropos (regexp) | 659 | (defun elisp--xref-find-apropos (regexp) |
| 639 | (apply #'nconc | 660 | (apply #'nconc |
| 640 | (let (lst) | 661 | (let (lst) |
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index b4ce8b11c9c..4e923aac197 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el | |||
| @@ -2082,6 +2082,15 @@ for \\[find-tag] (which see)." | |||
| 2082 | (defun etags-xref-find (action id) | 2082 | (defun etags-xref-find (action id) |
| 2083 | (pcase action | 2083 | (pcase action |
| 2084 | (`definitions (etags--xref-find-definitions id)) | 2084 | (`definitions (etags--xref-find-definitions id)) |
| 2085 | (`references | ||
| 2086 | (let ((dirs (if tags-table-list | ||
| 2087 | (mapcar #'file-name-directory tags-table-list) | ||
| 2088 | ;; If no tags files are loaded, prompt for the dir. | ||
| 2089 | (list (read-directory-name "In directory: " nil nil t))))) | ||
| 2090 | (cl-mapcan | ||
| 2091 | (lambda (dir) | ||
| 2092 | (xref-collect-references id dir)) | ||
| 2093 | dirs))) | ||
| 2085 | (`apropos (etags--xref-find-definitions id t)))) | 2094 | (`apropos (etags--xref-find-definitions id t)))) |
| 2086 | 2095 | ||
| 2087 | (defun etags--xref-find-definitions (pattern &optional regexp?) | 2096 | (defun etags--xref-find-definitions (pattern &optional regexp?) |
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index fc27c268845..099c08045b2 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el | |||
| @@ -674,6 +674,49 @@ and just use etags." | |||
| 674 | (setq-local xref-identifier-completion-table-function | 674 | (setq-local xref-identifier-completion-table-function |
| 675 | (cdr xref-etags-mode--saved)))) | 675 | (cdr xref-etags-mode--saved)))) |
| 676 | 676 | ||
| 677 | (declare-function semantic-symref-find-references-by-name "semantic/symref") | ||
| 678 | (declare-function semantic-find-file-noselect "semantic/fw") | ||
| 679 | |||
| 680 | (defun xref-collect-references (name dir) | ||
| 681 | "Collect mentions of NAME inside DIR. | ||
| 682 | Uses the Semantic Symbol Reference API, see | ||
| 683 | `semantic-symref-find-references-by-name' for details on which | ||
| 684 | tools are used, and when." | ||
| 685 | (require 'semantic/symref) | ||
| 686 | (defvar semantic-symref-tool) | ||
| 687 | (cl-assert (directory-name-p dir)) | ||
| 688 | (let* ((default-directory dir) | ||
| 689 | (semantic-symref-tool 'detect) | ||
| 690 | (res (semantic-symref-find-references-by-name name 'subdirs)) | ||
| 691 | (hits (and res (oref res :hit-lines))) | ||
| 692 | (orig-buffers (buffer-list))) | ||
| 693 | (unwind-protect | ||
| 694 | (delq nil | ||
| 695 | (mapcar (lambda (hit) (xref--collect-reference hit name)) hits)) | ||
| 696 | (mapc #'kill-buffer | ||
| 697 | (cl-set-difference (buffer-list) orig-buffers))))) | ||
| 698 | |||
| 699 | (defun xref--collect-reference (hit name) | ||
| 700 | (pcase-let* ((`(,line . ,file) hit) | ||
| 701 | (buf (or (find-buffer-visiting file) | ||
| 702 | (semantic-find-file-noselect file)))) | ||
| 703 | (with-current-buffer buf | ||
| 704 | (save-excursion | ||
| 705 | (goto-char (point-min)) | ||
| 706 | (forward-line (1- line)) | ||
| 707 | (when (re-search-forward (format "\\_<%s\\_>" | ||
| 708 | (regexp-quote name)) | ||
| 709 | (line-end-position) t) | ||
| 710 | (goto-char (match-beginning 0)) | ||
| 711 | (xref-make (format | ||
| 712 | "%d: %s" | ||
| 713 | line | ||
| 714 | (buffer-substring | ||
| 715 | (line-beginning-position) | ||
| 716 | (line-end-position))) | ||
| 717 | (xref-make-file-location file line | ||
| 718 | (current-column)))))))) | ||
| 719 | |||
| 677 | 720 | ||
| 678 | (provide 'xref) | 721 | (provide 'xref) |
| 679 | 722 | ||