diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/etags.el | 152 |
1 files changed, 89 insertions, 63 deletions
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 7d4521c148d..c72f0616b10 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el | |||
| @@ -33,8 +33,9 @@ | |||
| 33 | ;;;###autoload | 33 | ;;;###autoload |
| 34 | (defvar tags-file-name nil | 34 | (defvar tags-file-name nil |
| 35 | "File name of tags table. | 35 | "File name of tags table. |
| 36 | To switch to a new tags table, setting this variable is sufficient. | 36 | To switch to a new tags table, do not set this variable; instead, |
| 37 | If you set this variable, do not also set `tags-table-list'. | 37 | invoke `visit-tags-table', which is the only reliable way of |
| 38 | setting the value of this variable, whether buffer-local or global. | ||
| 38 | Use the `etags' program to make a tags table file.") | 39 | Use the `etags' program to make a tags table file.") |
| 39 | ;; Make M-x set-variable tags-file-name like M-x visit-tags-table. | 40 | ;; Make M-x set-variable tags-file-name like M-x visit-tags-table. |
| 40 | ;;;###autoload (put 'tags-file-name 'variable-interactive (purecopy "fVisit tags table: ")) | 41 | ;;;###autoload (put 'tags-file-name 'variable-interactive (purecopy "fVisit tags table: ")) |
| @@ -288,7 +289,8 @@ FILE should be the name of a file created with the `etags' program. | |||
| 288 | A directory name is ok too; it means file TAGS in that directory. | 289 | A directory name is ok too; it means file TAGS in that directory. |
| 289 | 290 | ||
| 290 | Normally \\[visit-tags-table] sets the global value of `tags-file-name'. | 291 | Normally \\[visit-tags-table] sets the global value of `tags-file-name'. |
| 291 | With a prefix arg, set the buffer-local value instead. | 292 | With a prefix arg, set the buffer-local value instead. When called |
| 293 | from Lisp, if the optional arg LOCAL is non-nil, set the local value. | ||
| 292 | When you find a tag with \\[find-tag], the buffer it finds the tag | 294 | When you find a tag with \\[find-tag], the buffer it finds the tag |
| 293 | in is given a local value of this variable which is the name of the tags | 295 | in is given a local value of this variable which is the name of the tags |
| 294 | file the tag was in." | 296 | file the tag was in." |
| @@ -304,19 +306,28 @@ file the tag was in." | |||
| 304 | ;; Calling visit-tags-table-buffer with tags-file-name set to FILE will | 306 | ;; Calling visit-tags-table-buffer with tags-file-name set to FILE will |
| 305 | ;; initialize a buffer for FILE and set tags-file-name to the | 307 | ;; initialize a buffer for FILE and set tags-file-name to the |
| 306 | ;; fully-expanded name. | 308 | ;; fully-expanded name. |
| 307 | (let ((tags-file-name file)) | 309 | (let ((tags-file-name file) |
| 310 | (cbuf (current-buffer))) | ||
| 308 | (save-excursion | 311 | (save-excursion |
| 309 | (or (visit-tags-table-buffer file) | 312 | (or (visit-tags-table-buffer file) |
| 310 | (signal 'file-missing (list "Visiting tags table" | 313 | (signal 'file-missing (list "Visiting tags table" |
| 311 | "No such file or directory" | 314 | "No such file or directory" |
| 312 | file))) | 315 | file))) |
| 313 | ;; Set FILE to the expanded name. | 316 | ;; Set FILE to the expanded name. Do that in the buffer we |
| 314 | (setq file tags-file-name))) | 317 | ;; started from, because visit-tags-table-buffer switches |
| 318 | ;; buffers after updating tags-file-name, so if tags-file-name | ||
| 319 | ;; is local in the buffer we started, that value is only visible | ||
| 320 | ;; in that buffer. | ||
| 321 | (setq file (with-current-buffer cbuf tags-file-name)))) | ||
| 315 | (if local | 322 | (if local |
| 316 | ;; Set the local value of tags-file-name. | 323 | (progn |
| 317 | (set (make-local-variable 'tags-file-name) file) | 324 | ;; Force recomputation of tags-completion-table. |
| 325 | (setq-local tags-completion-table nil) | ||
| 326 | ;; Set the local value of tags-file-name. | ||
| 327 | (setq-local tags-file-name file)) | ||
| 318 | ;; Set the global value of tags-file-name. | 328 | ;; Set the global value of tags-file-name. |
| 319 | (setq-default tags-file-name file))) | 329 | (setq-default tags-file-name file) |
| 330 | (setq tags-completion-table nil))) | ||
| 320 | 331 | ||
| 321 | (defun tags-table-check-computed-list () | 332 | (defun tags-table-check-computed-list () |
| 322 | "Compute `tags-table-computed-list' from `tags-table-list' if necessary." | 333 | "Compute `tags-table-computed-list' from `tags-table-list' if necessary." |
| @@ -540,17 +551,21 @@ Returns nil when out of tables." | |||
| 540 | (setq tags-file-name (car tags-table-list-pointer)))) | 551 | (setq tags-file-name (car tags-table-list-pointer)))) |
| 541 | 552 | ||
| 542 | ;;;###autoload | 553 | ;;;###autoload |
| 543 | (defun visit-tags-table-buffer (&optional cont) | 554 | (defun visit-tags-table-buffer (&optional cont cbuf) |
| 544 | "Select the buffer containing the current tags table. | 555 | "Select the buffer containing the current tags table. |
| 545 | If optional arg is a string, visit that file as a tags table. | 556 | Optional arg CONT specifies which tags table to visit. |
| 546 | If optional arg is t, visit the next table in `tags-table-list'. | 557 | If CONT is a string, visit that file as a tags table. |
| 547 | If optional arg is the atom `same', don't look for a new table; | 558 | If CONT is t, visit the next table in `tags-table-list'. |
| 559 | If CONT is the atom `same', don't look for a new table; | ||
| 548 | just select the buffer visiting `tags-file-name'. | 560 | just select the buffer visiting `tags-file-name'. |
| 549 | If arg is nil or absent, choose a first buffer from information in | 561 | If CONT is nil or absent, choose a first buffer from information in |
| 550 | `tags-file-name', `tags-table-list', `tags-table-list-pointer'. | 562 | `tags-file-name', `tags-table-list', `tags-table-list-pointer'. |
| 563 | Optional second arg CBUF, if non-nil, specifies the initial buffer, | ||
| 564 | which is important if that buffer has a local value of `tags-file-name'. | ||
| 551 | Returns t if it visits a tags table, or nil if there are no more in the list." | 565 | Returns t if it visits a tags table, or nil if there are no more in the list." |
| 552 | 566 | ||
| 553 | ;; Set tags-file-name to the tags table file we want to visit. | 567 | ;; Set tags-file-name to the tags table file we want to visit. |
| 568 | (if cbuf (set-buffer cbuf)) | ||
| 554 | (cond ((eq cont 'same) | 569 | (cond ((eq cont 'same) |
| 555 | ;; Use the ambient value of tags-file-name. | 570 | ;; Use the ambient value of tags-file-name. |
| 556 | (or tags-file-name | 571 | (or tags-file-name |
| @@ -752,28 +767,33 @@ Assumes the tags table is the current buffer." | |||
| 752 | (or tags-included-tables | 767 | (or tags-included-tables |
| 753 | (setq tags-included-tables (funcall tags-included-tables-function)))) | 768 | (setq tags-included-tables (funcall tags-included-tables-function)))) |
| 754 | 769 | ||
| 755 | (defun tags-completion-table () | 770 | (defun tags-completion-table (&optional buf) |
| 756 | "Build `tags-completion-table' on demand. | 771 | "Build `tags-completion-table' on demand for a buffer's tags tables. |
| 772 | Optional argument BUF specifies the buffer for which to build | ||
| 773 | \`tags-completion-table', and defaults to the current buffer. | ||
| 757 | The tags included in the completion table are those in the current | 774 | The tags included in the completion table are those in the current |
| 758 | tags table and its (recursively) included tags tables." | 775 | tags table for BUF and its (recursively) included tags tables." |
| 759 | (or tags-completion-table | 776 | (if (not buf) (setq buf (current-buffer))) |
| 760 | ;; No cached value for this buffer. | 777 | (with-current-buffer buf |
| 761 | (condition-case () | 778 | (or tags-completion-table |
| 762 | (let (tables cont) | 779 | ;; No cached value for this buffer. |
| 763 | (message "Making tags completion table for %s..." buffer-file-name) | 780 | (condition-case () |
| 764 | (save-excursion | 781 | (let (tables cont) |
| 765 | ;; Iterate over the current list of tags tables. | 782 | (message "Making tags completion table for %s..." |
| 766 | (while (visit-tags-table-buffer cont) | 783 | buffer-file-name) |
| 767 | ;; Find possible completions in this table. | 784 | (save-excursion |
| 768 | (push (funcall tags-completion-table-function) tables) | 785 | ;; Iterate over the current list of tags tables. |
| 769 | (setq cont t))) | 786 | (while (visit-tags-table-buffer cont buf) |
| 770 | (message "Making tags completion table for %s...done" | 787 | ;; Find possible completions in this table. |
| 771 | buffer-file-name) | 788 | (push (funcall tags-completion-table-function) tables) |
| 772 | ;; Cache the result in a buffer-local variable. | 789 | (setq cont t))) |
| 773 | (setq tags-completion-table | 790 | (message "Making tags completion table for %s...done" |
| 774 | (nreverse (delete-dups (apply #'nconc tables))))) | 791 | buffer-file-name) |
| 775 | (quit (message "Tags completion table construction aborted.") | 792 | ;; Cache the result in a variable. |
| 776 | (setq tags-completion-table nil))))) | 793 | (setq tags-completion-table |
| 794 | (nreverse (delete-dups (apply #'nconc tables))))) | ||
| 795 | (quit (message "Tags completion table construction aborted.") | ||
| 796 | (setq tags-completion-table nil)))))) | ||
| 777 | 797 | ||
| 778 | ;;;###autoload | 798 | ;;;###autoload |
| 779 | (defun tags-lazy-completion-table () | 799 | (defun tags-lazy-completion-table () |
| @@ -784,7 +804,9 @@ tags table and its (recursively) included tags tables." | |||
| 784 | ;; If we need to ask for the tag table, allow that. | 804 | ;; If we need to ask for the tag table, allow that. |
| 785 | (let ((enable-recursive-minibuffers t)) | 805 | (let ((enable-recursive-minibuffers t)) |
| 786 | (visit-tags-table-buffer)) | 806 | (visit-tags-table-buffer)) |
| 787 | (complete-with-action action (tags-completion-table) string pred)))))) | 807 | (complete-with-action action |
| 808 | (tags-completion-table buf) | ||
| 809 | string pred)))))) | ||
| 788 | 810 | ||
| 789 | ;;;###autoload (defun tags-completion-at-point-function () | 811 | ;;;###autoload (defun tags-completion-at-point-function () |
| 790 | ;;;###autoload (if (or tags-table-list tags-file-name) | 812 | ;;;###autoload (if (or tags-table-list tags-file-name) |
| @@ -1084,6 +1106,7 @@ error message." | |||
| 1084 | (case-fold-search (if (memq tags-case-fold-search '(nil t)) | 1106 | (case-fold-search (if (memq tags-case-fold-search '(nil t)) |
| 1085 | tags-case-fold-search | 1107 | tags-case-fold-search |
| 1086 | case-fold-search)) | 1108 | case-fold-search)) |
| 1109 | (cbuf (current-buffer)) | ||
| 1087 | ) | 1110 | ) |
| 1088 | (save-excursion | 1111 | (save-excursion |
| 1089 | 1112 | ||
| @@ -1104,8 +1127,7 @@ error message." | |||
| 1104 | (catch 'qualified-match-found | 1127 | (catch 'qualified-match-found |
| 1105 | 1128 | ||
| 1106 | ;; Iterate over the list of tags tables. | 1129 | ;; Iterate over the list of tags tables. |
| 1107 | (while (or first-table | 1130 | (while (or first-table (visit-tags-table-buffer t cbuf)) |
| 1108 | (visit-tags-table-buffer t)) | ||
| 1109 | 1131 | ||
| 1110 | (and first-search first-table | 1132 | (and first-search first-table |
| 1111 | ;; Start at beginning of tags file. | 1133 | ;; Start at beginning of tags file. |
| @@ -1707,25 +1729,26 @@ if the file was newly read in, the value is the filename." | |||
| 1707 | ((eq initialize t) | 1729 | ((eq initialize t) |
| 1708 | ;; Initialize the list from the tags table. | 1730 | ;; Initialize the list from the tags table. |
| 1709 | (save-excursion | 1731 | (save-excursion |
| 1710 | ;; Visit the tags table buffer to get its list of files. | 1732 | (let ((cbuf (current-buffer))) |
| 1711 | (visit-tags-table-buffer) | 1733 | ;; Visit the tags table buffer to get its list of files. |
| 1712 | ;; Copy the list so we can setcdr below, and expand the file | 1734 | (visit-tags-table-buffer) |
| 1713 | ;; names while we are at it, in this buffer's default directory. | 1735 | ;; Copy the list so we can setcdr below, and expand the file |
| 1714 | (setq next-file-list (mapcar 'expand-file-name (tags-table-files))) | 1736 | ;; names while we are at it, in this buffer's default directory. |
| 1715 | ;; Iterate over all the tags table files, collecting | 1737 | (setq next-file-list (mapcar 'expand-file-name (tags-table-files))) |
| 1716 | ;; a complete list of referenced file names. | 1738 | ;; Iterate over all the tags table files, collecting |
| 1717 | (while (visit-tags-table-buffer t) | 1739 | ;; a complete list of referenced file names. |
| 1718 | ;; Find the tail of the working list and chain on the new | 1740 | (while (visit-tags-table-buffer t cbuf) |
| 1719 | ;; sublist for this tags table. | 1741 | ;; Find the tail of the working list and chain on the new |
| 1720 | (let ((tail next-file-list)) | 1742 | ;; sublist for this tags table. |
| 1721 | (while (cdr tail) | 1743 | (let ((tail next-file-list)) |
| 1722 | (setq tail (cdr tail))) | 1744 | (while (cdr tail) |
| 1723 | ;; Use a copy so the next loop iteration will not modify the | 1745 | (setq tail (cdr tail))) |
| 1724 | ;; list later returned by (tags-table-files). | 1746 | ;; Use a copy so the next loop iteration will not modify the |
| 1725 | (if tail | 1747 | ;; list later returned by (tags-table-files). |
| 1726 | (setcdr tail (mapcar 'expand-file-name (tags-table-files))) | 1748 | (if tail |
| 1727 | (setq next-file-list (mapcar 'expand-file-name | 1749 | (setcdr tail (mapcar 'expand-file-name (tags-table-files))) |
| 1728 | (tags-table-files)))))))) | 1750 | (setq next-file-list (mapcar 'expand-file-name |
| 1751 | (tags-table-files))))))))) | ||
| 1729 | (t | 1752 | (t |
| 1730 | ;; Initialize the list by evalling the argument. | 1753 | ;; Initialize the list by evalling the argument. |
| 1731 | (setq next-file-list (eval initialize)))) | 1754 | (setq next-file-list (eval initialize)))) |
| @@ -1921,8 +1944,9 @@ directory specification." | |||
| 1921 | (princ (substitute-command-keys "':\n\n")) | 1944 | (princ (substitute-command-keys "':\n\n")) |
| 1922 | (save-excursion | 1945 | (save-excursion |
| 1923 | (let ((first-time t) | 1946 | (let ((first-time t) |
| 1924 | (gotany nil)) | 1947 | (gotany nil) |
| 1925 | (while (visit-tags-table-buffer (not first-time)) | 1948 | (cbuf (current-buffer))) |
| 1949 | (while (visit-tags-table-buffer (not first-time) cbuf) | ||
| 1926 | (setq first-time nil) | 1950 | (setq first-time nil) |
| 1927 | (if (funcall list-tags-function file) | 1951 | (if (funcall list-tags-function file) |
| 1928 | (setq gotany t))) | 1952 | (setq gotany t))) |
| @@ -1945,8 +1969,9 @@ directory specification." | |||
| 1945 | (tags-with-face 'highlight (princ regexp)) | 1969 | (tags-with-face 'highlight (princ regexp)) |
| 1946 | (princ (substitute-command-keys "':\n\n")) | 1970 | (princ (substitute-command-keys "':\n\n")) |
| 1947 | (save-excursion | 1971 | (save-excursion |
| 1948 | (let ((first-time t)) | 1972 | (let ((first-time t) |
| 1949 | (while (visit-tags-table-buffer (not first-time)) | 1973 | (cbuf (current-buffer))) |
| 1974 | (while (visit-tags-table-buffer (not first-time) cbuf) | ||
| 1950 | (setq first-time nil) | 1975 | (setq first-time nil) |
| 1951 | (funcall tags-apropos-function regexp)))) | 1976 | (funcall tags-apropos-function regexp)))) |
| 1952 | (etags-tags-apropos-additional regexp)) | 1977 | (etags-tags-apropos-additional regexp)) |
| @@ -2107,9 +2132,10 @@ for \\[find-tag] (which see)." | |||
| 2107 | (marks (make-hash-table :test 'equal)) | 2132 | (marks (make-hash-table :test 'equal)) |
| 2108 | (case-fold-search (if (memq tags-case-fold-search '(nil t)) | 2133 | (case-fold-search (if (memq tags-case-fold-search '(nil t)) |
| 2109 | tags-case-fold-search | 2134 | tags-case-fold-search |
| 2110 | case-fold-search))) | 2135 | case-fold-search)) |
| 2136 | (cbuf (current-buffer))) | ||
| 2111 | (save-excursion | 2137 | (save-excursion |
| 2112 | (while (visit-tags-table-buffer (not first-time)) | 2138 | (while (visit-tags-table-buffer (not first-time) cbuf) |
| 2113 | (setq first-time nil) | 2139 | (setq first-time nil) |
| 2114 | (dolist (order-fun (cond (regexp? find-tag-regexp-tag-order) | 2140 | (dolist (order-fun (cond (regexp? find-tag-regexp-tag-order) |
| 2115 | (t etags-xref-find-definitions-tag-order))) | 2141 | (t etags-xref-find-definitions-tag-order))) |