Commit graph

344 commits

Author SHA1 Message Date
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
Stefan Monnier
825b4ec338 * lisp/progmodes/xref.el (xref--show-defs-buffer-at-bottom): Fix missing arg 2021-01-02 23:12:10 -05:00
Dmitry Gutov
6b10ce867f xref--show-pos-in-buf: Don't set other-window-scroll-buffer
* lisp/progmodes/xref.el (xref--show-pos-in-buf):
Don't set other-window-scroll-buffer (bug#45581).
2021-01-02 20:52:31 +02:00
Dmitry Gutov
a516e69863 xref-show-definitions-completing-read: Default to the first location
* lisp/progmodes/xref.el (xref-show-definitions-completing-read):
Default to the first location.
2021-01-01 15:18:41 +02:00
Paul Eggert
ba05d005e5 Update copyright year to 2021
Run "TZ=UTC0 admin/update-copyright".
2021-01-01 01:13:56 -08:00
Dmitry Gutov
13b59c690a Add 'project-relative' as value for 'xref-file-name-display'
* lisp/progmodes/xref.el (xref-file-name-display): Document new value.
(xref-location-group ((l xref-file-location))): Handle the new value.
(xref--project-root): Extract from the default method of
'xref-backend-references' so it can be used in above's new code.
Also fix an old bug in the "backward compat" branch.

* lisp/progmodes/xref.el (xref--project-root-memo): New variable.

* test/lisp/progmodes/xref-tests.el: Add test cases for the three
possible settings of 'xref-file-name-display'.

Co-authored-by: Tobias Rittweiler <trittweiler@gmail.com>
2020-12-30 13:48:55 +02:00
Dmitry Gutov
3e80653d29 xref-show-definitions-completing-read: Tune up completion
* lisp/minibuffer.el (completion-category-defaults)
Use 'substring' completion style for 'xref-location' category by
default.

* lisp/progmodes/xref.el (xref-show-definitions-completing-read):
Assign the 'xref-location' category to the completions. Pass
REQUIRE-MATCH=t.
2020-12-29 20:25:03 +02:00
Dmitry Gutov
8c38345629 Rename and document the built-in xref-show-definitions-function's
* lisp/progmodes/xref.el (xref-show-definitions-buffer): Rename
from 'xref--show-defs-buffer'.
(xref-show-definitions-buffer-at-bottom): Rename from
'xref--show-defs-buffer-at-bottom'.
2020-12-28 02:30:09 +02:00
Dmitry Gutov
759ec25769 Generic-ify xref-location-column
* lisp/progmodes/xref.el (xref-location-column):
Create a generic from xref-file-location-column, to use in the
common rendering code (bug#36967).
(xref--insert-xrefs): Update accordingly.

* 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):
Ditto.
2020-12-21 03:38:37 +02:00
Juri Linkov
c3ad28c290 De-duplicate lines in Xref buffers
* lisp/progmodes/xref.el (xref--insert-xrefs):
Render matches coming from the same line together (bug#36967).
(xref--item-at-point): Account for the above.
2020-12-21 03:22:23 +02:00
Dmitry Gutov
1047f80f1c * lisp/progmodes/xref.el: Bump the version. 2020-12-09 23:38:18 +02:00
Dmitry Gutov
ea8ff97536 Add missing defcustom keywords to new variables
* lisp/progmodes/xref.el (xref-search-program-alist)
(xref-search-program): Add :version and :package-version.
2020-12-09 22:56:48 +02:00
Daniel Martín
6e0080e755 Add commands xref-next-group and xref-prev-group
* lisp/progmodes/xref.el (xref-next-group): New command that navigates
to the first item of the next xref group (typically a file).
(xref-prev-group): New command that navigates
to the first item of the next xref group (typically a file).
(xref--xref-buffer-mode-map): Bound the new commands to 'N' and 'P',
respectively.
* doc/emacs/maintaining.texi (Xref Commands): Document the new
commands in the Emacs manual.
* etc/NEWS: Announce them (bug#45089).
2020-12-07 17:01:35 +01:00
Dmitry Gutov
c86dc8d488 Always show the summary
* lisp/progmodes/xref.el (xref--show-defs-minibuffer):
Always show the summary (at least for now).
2020-12-05 03:01:34 +02:00
Dmitry Gutov
940bb6e984 Fontify the group and the line number
* lisp/progmodes/xref.el (xref--show-defs-minibuffer):
Fontify the group and the line number.
2020-12-05 03:01:34 +02:00
Dmitry Gutov
2945fe74a9 Hide the common parent directory, if any
* lisp/progmodes/xref.el (xref--show-defs-minibuffer):
Hide the common parent directory, if any.
2020-12-05 03:01:34 +02:00
William Xu
469f0a6516 xref--show-defs-minibuffer: new "show definitions" UI
* lisp/progmodes/xref.el (xref--show-defs-minibuffer):
New function to use as xref-show-definitions-function
(https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg00824.html).
2020-12-05 03:00:38 +02:00
Dmitry Gutov
27af17b9ee Improve docstrings
* lisp/progmodes/xref.el (xref-search-program-alist)
(xref-search-program): Improve docstrings.
2020-12-04 23:23:03 +02:00
Dmitry Gutov
db26a84481 ; Fix line number sorting 2020-12-04 04:46:52 +02:00
Dmitry Gutov
f2a3d6e28d Support using ripgrep in project-find-regexp and friends
Performance results vary here.  Some projects and search terms
don't see much of a change, but for some (including Emacs sources
checkout and case-insensitive search) the switch to ripgrep shows
~2-3x speed improvement.  Another piece of anecdata here:
https://lists.gnu.org/archive/html/emacs-devel/2020-06/msg00802.html

* lisp/progmodes/xref.el (xref-search-program-alist)
(xref-search-program): New user options.
(xref-matches-in-files): Use them.
2020-12-04 03:47:49 +02:00
Juri Linkov
ad29bc74ca * lisp/progmodes/xref.el (xref-goto-xref): Prefix arg quits the *xref* buffer.
(bug#44611)
2020-11-14 22:36:13 +02:00
Stefan Kangas
dd16e46bb9 ; Prefer https to http in more URLs
These were all tested and confirmed working.
2020-10-24 20:23:27 +02:00
Dmitry Gutov
36b3abc672 ; Add the necessary argument (bug#42967) 2020-08-27 11:33:52 +03:00
Dmitry Gutov
1a167f5a7a ; Bump xref version 2020-08-27 00:56:16 +03:00