Commit graph

267 commits

Author SHA1 Message Date
Dmitry Gutov
9ca737c419 xref-matches-in-files: Move sorting to Lisp
For better compatibility with different systems.
Performance is unaffected, except in very pathological cases
(~100000 matches), and even then the overhead of 'sort' is comparable.

* lisp/progmodes/xref.el (xref-search-program-alist):
Drop the piping through 'sort'.
(xref-matches-in-files): Sort here instead.
Do that to both searchers' output as well now.
2021-09-17 15:39:36 +03:00
Stefan Kangas
63f419f133 ; Minor stylistic fixes found by checkdoc 2021-09-16 19:37:07 +02:00
Dmitry Gutov
d314951043 Extend xref-file-name-display to elisp and etags definitions
And all other types of locations (with a looks-like-file-name check).

* lisp/progmodes/xref.el (xref--group-name-for-display): Extract
from xref-buffer-location's implementation of xref-location-group.
(xref-file-location): Define trivial reader for the 'file' slot.
(xref-location-group): Update docstring.
(xref--analyze): Use the new function here, to be able to format
group names coming from any location type.
2021-09-13 01:37:32 +03:00
Eli Zaretskii
f94b915e2f Doc string followup to last change.
* lisp/progmodes/xref.el (xref-find-apropos): Mention
'tags-apropos-additional-actions' in the doc string.
* lisp/progmodes/etags.el (tags-apropos-additional-actions):
Mention 'xref-find-apropos' in the doc string.
2021-09-10 15:02:41 +03:00
Eli Zaretskii
11b56fa0b4 Fix a recent documentation change
* lisp/progmodes/xref.el (xref-auto-jump-to-first-definition)
(xref-auto-jump-to-first-xref):
* etc/NEWS: Fix wording and typos.
2021-09-07 18:44:26 +03:00
Eli Zaretskii
b02c9bcceb Improve documentation of new Xref options
* lisp/progmodes/xref.el (xref-auto-jump-to-first-definition)
(xref-auto-jump-to-first-xref): More accurate description in the
doc strings.

* doc/emacs/maintaining.texi (Looking Up Identifiers)
(Identifier Search, List Identifiers, Project File Commands): Fix
the documentation of 'xref-auto-jump-to-first-definition' and
'xref-auto-jump-to-first-xref' to be more accurate.

* etc/NEWS: More accurate wording of the entry about
'xref-auto-jump-to-first-definition' and
'xref-auto-jump-to-first-xref'.
2021-09-07 16:03:27 +03:00
Dmitry Gutov
ba6df55475 Fixup dired-do-find-regexp-and-replace
* lisp/dired-aux.el (dired-do-find-regexp-and-replace):
Disregard the customized value of xref-auto-jump-to-first-xref
(it breaks the xref-query-replace-in-results invocation).

* lisp/progmodes/xref.el (xref-auto-jump-to-first-xref):
Mention the caveat for users or xref distributed through ELPA.
2021-09-06 17:08:07 +03:00
Dmitry Gutov
71f8b55f46 project--files-in-directory: Fix handling of ignores
* lisp/progmodes/project.el (project--files-in-directory):
Pass "." as the DIR argument to 'find' because otherwise the ignore
expression can match the project root directory name, which we don't
want to happen (bug#50240).  Fixup the resulting file names at the end
with concatenation.
Originally I thought it could lead to worse performance, but the
results show equal or slightly better timings.

* lisp/progmodes/xref.el (xref-matches-in-directory):
Apply a similar fix.
(xref--find-ignores-arguments): Use file-name-as-directory, so
that when passed "." replace-match still had the expected effect.

* test/lisp/progmodes/project-tests.el (project-ignores-bug-50240):
New test.

* test/lisp/progmodes/xref-tests.el
(xref-matches-in-directory-filters-with-ignores): New test.
2021-09-06 05:01:07 +03:00
Dmitry Gutov
d864389c34 * lisp/progmodes/xref.el: Bump the version again. 2021-09-05 22:25:15 +03:00
Juri Linkov
0972cbe42f * lisp/progmodes/xref.el: Fix defcustoms (bug#50067)
* lisp/progmodes/xref.el (xref-auto-jump-to-first-definition)
(xref-auto-jump-to-first-xref, xref-search-program): Fix defcustoms.
2021-09-05 11:36:30 +03:00
Dmitry Gutov
94530e7ea9 Belated fix
* lisp/progmodes/xref.el: (xref--show-xref-buffer):
Fix support for xref-auto-jump-to-first-xref.
2021-09-05 03:52:29 +03:00
Dmitry Gutov
c298337505 * lisp/progmodes/xref.el: Bump version. 2021-09-05 03:36:30 +03:00
Dmitry Gutov
1be8bfae6b Xref: automatic jumping to the first definition or reference
* lisp/progmodes/xref.el (xref-auto-jump-to-first-definition)
(xref-auto-jump-to-first-xref): New user options.
Discussed in bug#50067.
(xref--show-xrefs, xref--show-defs): Use them here.
(xref--auto-jump-first): New function, handles different values.
(xref-show-definitions-buffer)
(xref-show-definitions-buffer-at-bottom): Use it.
2021-09-05 03:35:43 +03:00
Dmitry Gutov
88795df552 Rename xref-select-and-{goto,show}-xref
* lisp/progmodes/xref.el (xref-select-and-show-xref):
Rename from xref-select-and-goto-xref (bug#35376).
Update all references.
2021-09-05 01:45:46 +03:00
Lars Ingebrigtsen
03dcceeeee Rename xref--mouse-2 and adjust documentation
* doc/emacs/maintaining.texi (Xref Commands): `mouse-1' is bound
to `xref-goto-xref', not `mouse-2' (bug#35376).
(Xref Commands): Mention what `mouse-2' does.

* lisp/progmodes/xref.el (xref--button-map): Adjust.
(xref-select-and-goto-xref): Rename from xref--mouse-2 (bug#35376).
2021-08-31 04:50:18 +02:00
Mattias Engdegård
d6ad208b2c Use overlay arrow to indicate current *xref* selection
* lisp/progmodes/xref.el (xref--set-arrow): New function.
(xref-show-location-at-point, xref-goto-xref)
(xref--next-error-function): Call it.
(xref--show-common-initialize): Remove arrow.
2021-08-21 12:41:54 +02:00
Mattias Engdegård
6993d45e51 Add "Find References" to context menu (bug#50067)
The new entry appears next to "Find Definition" and like it only
appears when the context menu was invoked on an identifier.

* lisp/progmodes/prog-mode.el (prog-context-menu): New menu entry.
* lisp/progmodes/xref.el (xref-find-references-at-mouse): New
function, analogous to `xref-find-definitions-at-mouse`.
2021-08-21 12:41:54 +02:00
Mattias Engdegård
b4830907ed Indicate progress while searching for references in xref
* lisp/progmodes/xref.el (xref-backend-references): Add messages to
show the user that something is happening instead of silently freezing
during the frequently long synchronous searches for references.
2021-08-21 12:41:54 +02:00
Mattias Engdegård
4d6e770031 Re-type the :location slot in xref-match-item to xref-location
* lisp/progmodes/xref.el (xref-match-item): Change type for
:location from `xref-file-location`, which was likely a mistake,
to `xref-location`. This allows `xref-make-match` to take
arguments of any subtype of `xref-location` (bug#50067).
2021-08-21 12:41:54 +02:00
Eli Zaretskii
f658b955cc Improve doc string of 'M-.'
* lisp/progmodes/xref.el (xref-find-definitions): Mention 'M-,' in
the doc string.
2021-08-21 11:17:09 +03:00
Mattias Engdegård
e1ed0c3af1 Fix xref {prev,next}-error target buffer match highlighting extent
* lisp/progmodes/xref.el (xref--next-error-function):
Bind `xref--current-item` during the call to `xref--show-location` so
that `xref-pulse-momentarily` finds the match extent.
2021-08-20 12:34:34 +02:00
Juri Linkov
9b31ad3609 * lisp/progmodes/xref.el (xref--collect-matches): Widen temporarily. 2021-08-18 20:02:39 +03:00
Dmitry Gutov
f65958a94d Provide a default for xref-find-apropos pattern
* lisp/progmodes/xref.el (xref-find-apropos):
Provide a default for the pattern (bug#49731).
2021-08-06 03:02:13 +03:00
Dmitry Gutov
232be9bf87 Change the xref-goto-xref error message
* lisp/progmodes/xref.el (xref-goto-xref):
Change the error message (bug#49846).
2021-08-06 02:49:42 +03:00
Dmitry Gutov
69398a4da0 Fix printing of multiple items in one group without line numbers
* lisp/progmodes/xref.el (xref--insert-xrefs):
Fix printing of multiple items in one group without line numbers
(mentioned in bug#49731).
2021-07-29 04:57:36 +03:00
Dmitry Gutov
6ec3cf1ccb (xref--insert-xrefs): Fix printing of line numbers
* lisp/progmodes/xref.el (xref--insert-xrefs):
Fix printing of line numbers when we have multiple files with
(e.g.) single match on the same line.
2021-07-06 01:56:18 +03:00
Dmitry Gutov
45bdc37c81 Support old BSD find and "root dir symlink" better
* lisp/progmodes/grep.el (grep-compute-defaults):
Add '-H' to grep-find-template (bug#48471).

* lisp/cedet/semantic/symref/grep.el (semantic-symref-perform-search):
Pass the root directory name without the trailing slash.

* lisp/progmodes/xref.el (xref-matches-in-directory): Ditto.

* test/lisp/progmodes/xref-tests.el (xref--xref-file-name-display-is-abs)
(xref--xref-file-name-display-is-relative-to-project-root):
Make tests more strict again.
2021-06-07 04:52:30 +03:00
Daniel Mendler
443d9efc95 (completing-read): Add group-function to the completion metadata
A completion table can specify a `group-function` in its metadata.
The group function takes two arguments, a completion candidate and a
transform argument.  The group function is used to group the
candidates after sorting and to enhance the completion UI with group
titles.

If the transform argument is nil, the function must return the title
of the group to which the completion candidate belongs.  The function
may also return nil if the candidate does not belong to a group.

If the transform argument is non-nil, the function must return the
transformed candidate.  For example, the transformation allows to
remove a redundant part of the candidate, which is then displayed in
the title.

The grouping functionality is guarded by the customizable variable
`completions-group` and turned off by default for the *Completions*
buffer.

The specific form of the `group-function` has been chosen in order to
allow allocation-free grouping.  This is important for completion UIs,
which continously update the displayed set of candidates (Icomplete,
Vertico, Ivy, etc.).  Only when the transform argument is non-nil the
candidate transformation is performed, which may involve a string
allocation as done in the function `xref--completing-read-group`.

The function `xref-show-definitions-completing-read` makes use of the
`group-function`, by moving the file name prefix to the title.  If
grouping is enabled, the *Completions* are displayed as
"linenum:summary" instead of "file:linenum:summary".  This way the
*Completions* buffer resembles the *Occur* buffer.

* doc/lispref/minibuf.texi: Add documentation.

* lisp/minibuffer.el (completion-metadata): Describe the
`group-function` in the docstring.
(completions-group): Add guard variable, off by default.
(completions-group-format): Add variable defining the format string
for the group titles.
(completions-group-title): Add face used by `completions-group-format`
for the group titles.
(completions-group-separator): Add face used by
`completions-group-format` for the group separator lines.
(minibuffer--group-by): New grouping function.
(minibuffer-completion-help): Use it.
(display-completion-list): Add optional GROUP-FUN argument.
(completion--insert-strings): Add optional GROUP-FUN argument.  Insert
group titles if `completions-format` is `one-column`.  Transform each
candidate with the GROUP-FUN.  Attach the untransformed candidate to
the property `completion--string`.

* lisp/simple.el (choose-completion): Retrieve the untransformed
completion candidate from the property `completion--string`.

* lisp/progmodes/xref.el:
(xref--completing-read-group): New grouping function.
(xref-show-definitions-completing-read): Use it.
2021-05-20 20:50:23 +03:00
Dmitry Gutov
d83db639d3 Visually truncate excessively long lines in Xref
* lisp/progmodes/xref.el (xref-truncation-width): New option.
(xref--apply-truncation): New function.
(xref--insert-xrefs): Use it (bug#46859).
2021-05-18 03:36:40 +03:00
Dmitry Gutov
a3c77dda95 * lisp/progmodes/xref.el: Bump version. 2021-04-29 05:02:13 +03:00
Eli Zaretskii
d753b39096 Obsolete the TAB binding in *xref* buffers
* doc/emacs/maintaining.texi (Xref Commands): Remove the
description of the TAB binding.  Enhance the description of the
RET binding.  (Bug#44611)

* etc/NEWS: Announce the obsolescence of TAB binding in XREF.

* lisp/progmodes/xref.el (xref-goto-xref): Improve doc string.
2021-04-24 12:54:44 +03:00
Eli Zaretskii
804f5acda4 Revert "Remove the binding for xref-quit-and-goto-xref"
This reverts commit 522c34f0e8.

Making changes to which there was an explicit disagreement
and a long discussion is unacceptable.  (Bug#44611)
2021-04-23 09:25:35 +03:00
Dmitry Gutov
9a15694a45 * lisp/progmodes/xref.el: Remove the "still experimental" note. 2021-04-23 00:19:26 +03:00
Dmitry Gutov
522c34f0e8 Remove the binding for xref-quit-and-goto-xref
* lisp/progmodes/xref.el (xref--xref-buffer-mode-map):
Remove the binding for xref-quit-and-goto-xref (bug#44611).

* doc/emacs/maintaining.texi (Xref Commands): Update.
2021-04-23 00:18:01 +03:00
Dmitry Gutov
eadf4cff7c Move part of the fix from project to xref
* lisp/progmodes/project.el (project--find-regexp-in-files):
Don't unquote file names here.

* lisp/progmodes/xref.el (xref-matches-in-files): Do it here.
And only if the first element in the list is quoted (bug#47799).
2021-04-22 17:40:30 +03:00
Dmitry Gutov
f955df1788 Improve quoting of directory names in project/xref
* lisp/progmodes/project.el (project--files-in-directory):
Quote LOCALDIR a bit earlier, to affect
xref--find-ignores-arguments as well (bug#47799).

* lisp/progmodes/xref.el (xref-matches-in-directory):
Quote the dir passed to xref--rgrep-command.
2021-04-16 03:52:44 +03:00
Juri Linkov
a789d8a3a0 * lisp/progmodes/xref.el: Change xref-file-name-display and xref-match face.
* lisp/progmodes/xref.el (xref-file-name-display): Change the default value
to 'project-relative' (bug#47012).
(xref-match)<face>: Inherit from 'match'.
2021-04-02 11:25:05 +03:00
Dmitry Gutov
344eea4113 xref.el: Keep Emacs 26 compatibility
* lisp/progmodes/xref.el (xref--read-identifier)
(xref-find-definitions, xref-find-definitions-other-window)
(xref-find-definitions-other-frame, xref-find-references):
Undo the latest change for Emacs 26 compatibility (bug#47286).
2021-03-24 12:39:08 +02:00
Gabriel do Nascimento Ribeiro
50512e36c7 Replace "(default %s)" with 'format-prompt'
* lisp/cmuscheme.el (scheme-load-file, scheme-compile-file):
* lisp/comint.el (comint-get-source):
* lisp/emulation/viper-cmd.el (viper-quote-region, viper-kill-buffer)
(viper-query-replace, viper-read-string-with-history):
* lisp/eshell/esh-mode.el (eshell-find-tag):
* lisp/gnus/gnus-sum.el (gnus-articles-to-read)
(gnus-summary-search-article-forward)
(gnus-summary-search-article-backward):
* lisp/international/mule-cmds.el (set-input-method, toggle-input-method)
(describe-input-method, set-language-environment)
(describe-language-environment):
* lisp/mh-e/mh-gnus.el (mh-mml-minibuffer-read-disposition):
* lisp/mh-e/mh-letter.el (mh-insert-letter):
* lisp/mh-e/mh-mime.el (mh-display-with-external-viewer)
(mh-mime-save-parts, mh-mh-forward-message)
(mh-mml-query-cryptographic-method, mh-minibuffer-read-type):
* lisp/mh-e/mh-seq.el (mh-read-seq, mh-read-range):
* lisp/mh-e/mh-utils.el (mh-prompt-for-folder):
* lisp/progmodes/etags.el (find-tag-tag):
(find-tag-noselect, find-tag, find-tag-other-window)
(find-tag-other-frame, find-tag-regexp):
* lisp/progmodes/idlwave.el (idlwave-find-module):
* lisp/progmodes/inf-lisp.el (lisp-load-file, lisp-compile-file):
* lisp/progmodes/tcl.el (tcl-load-file, tcl-restart-with-file):
* lisp/progmodes/xref.el (xref--read-identifier):
(xref-find-definitions, xref-find-definitions-other-window)
(xref-find-definitions-other-frame, xref-find-references):
* lisp/ses.el (ses-read-printer):
(ses-read-cell-printer, ses-read-column-printer)
(ses-read-default-printer, ses-define-local-printer):
* lisp/subr.el (read-number):
* lisp/term.el (term-get-source):
* src/minibuf.c (read-buffer): Remove prompt suffix and
use 'format-prompt'.
* lisp/minibuffer.el (format-prompt): Ignore DEFAULT empty strings
(bug#47286).
2021-03-24 10:31:31 +01:00
Juri Linkov
3ea0a334dc New commands xref-next-line-no-show and xref-prev-line-no-show (bug#44611)
* lisp/progmodes/xref.el (xref-next-line-no-show)
(xref-prev-line-no-show): New commands.
(xref-next-line, xref-prev-line): Use them.
2021-03-16 20:07:34 +02:00
Juri Linkov
04c43bb047 * lisp/progmodes/xref.el (xref-after-update-hook): New defcustom (bug#46992).
(xref--insert-xrefs): Use run-hooks on it.
2021-03-08 19:48:28 +02:00
Dmitry Gutov
8e103ebef1 Speed up xref rendering for matches on very long lines
* lisp/progmodes/xref.el (xref--insert-xrefs): Cut up the current
line into pieces here for multiple matches's summaries, so that
xref--insert-xrefs can do less work (bug#46859).
(xref--insert-xrefs): Do less work.
(xref--outdated-p):
Update accordingly to how the summary creation logic changed.
(xref--buf-pairs-iterator): Update to the new calling convention.
(xref-location-column): Effectively rename back to
xref-file-location-column since the generic version is now unused.

* test/lisp/progmodes/xref-tests.el
(xref-matches-in-directory-finds-two-matches-on-the-same-line)
(xref-matches-in-directory-finds-an-empty-line-regexp-match):
Adjust to the xref-location-column change.
(xref-matches-in-files-trims-summary-for-matches-on-same-line):
New test.

* test/lisp/progmodes/xref-resources/file1.txt:
Change contents slightly to test the new xref--outdated-p code.
2021-03-08 04:25:15 +02:00
Dmitry Gutov
e86b30d6fd (xref-revert-buffer): Also 'erase-buffer' when handling a user-error
* lisp/progmodes/xref.el (xref-revert-buffer):
Also 'erase-buffer' when handling a user-error (bug#46042).
2021-01-29 15:53:28 +02:00
João Távora
2a71831eb3 Allow project/xref packages to be used in Emacs 26.1
* lisp/progmodes/project.el: Change Package-Requires to Emacs 26.1
(bug#44671).

* lisp/progmodes/xref.el: Ditto.
2021-01-28 04:18:12 +01:00
Dmitry Gutov
cc98d0bf52 ; xref-revert-buffer: Drop the (goto-char) at the end 2021-01-23 02:58:53 +02:00
Dmitry Gutov
5821dee094 Erase the buffer only after fetching the new contents
* lisp/progmodes/xref.el (xref-revert-buffer):
Erase the buffer only after fetching the new contents (bug#46042).
2021-01-23 02:53:12 +02:00
Dmitry Gutov
4ca808ee7a Make sure the new window is not too tall
* lisp/progmodes/xref.el (xref-show-definitions-buffer-at-bottom):
Make sure the new window is not too tall (bug#45945).
2021-01-19 03:05:44 +02:00
Dmitry Gutov
17bd039539 New command xref-quit-and-pop-marker-stack
* lisp/progmodes/xref.el (xref-quit-and-pop-marker-stack):
New command.
(xref--xref-buffer-mode-map): Binding for it.
2021-01-11 00:45:21 +02:00
Dmitry Gutov
6e73e07a6f Make sure default-directory relates to the originating buffer
* lisp/progmodes/xref.el (xref--show-xref-buffer):
Pick up default-directory value from the caller
(https://lists.gnu.org/archive/html/emacs-devel/2021-01/msg00551.html).
(xref-show-definitions-buffer-at-bottom): Same.
2021-01-09 02:10:06 +02:00
Dmitry Gutov
665b4e7c4e Proof some searches and file listings against symlinks
* lisp/progmodes/project.el (project--files-in-directory):
Make sure the directory includes the trailing slash in case it's
a symlink, discussed in
https://lists.gnu.org/archive/html/emacs-devel/2021-01/msg00345.html.

* lisp/progmodes/xref.el (xref-matches-in-directory): Same.

* lisp/cedet/semantic/symref/grep.el (semantic-symref-perform-search):
Same.
2021-01-06 23:07:22 +02:00