all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* xref in a narrowed buffer?
@ 2020-03-04 14:39 Robert Pluim
  2020-03-04 15:20 ` Dmitry Gutov
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Pluim @ 2020-03-04 14:39 UTC (permalink / raw)
  To: emacs-devel

Iʼm not sure this counts as a bug, so I thought Iʼd ask:

    visit src/fontset.c, move point until youʼre inside 'set_fontset_font'
    C-x n d ; narrow-to-defun
    C-s FONTSET_ADD <RET>
    M-. <RET> ; xref-find-definitions
    C-n <RET> ; xref-goto-xref

    => echo area shows: Rerun etags: `^#define FONTSET_ADD(' not found
    in /Users/rpluim/repos/emacs/src/fontset.c

Should 'xref-goto-ref' widen the buffer before attempting to jump to
the definition? Or should 'xref-find-definitions' not show definitions
that are outside the narrowed area?

Robert



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: xref in a narrowed buffer?
  2020-03-04 14:39 xref in a narrowed buffer? Robert Pluim
@ 2020-03-04 15:20 ` Dmitry Gutov
  2020-03-04 15:46   ` Stefan Monnier
  2020-03-04 16:08   ` Robert Pluim
  0 siblings, 2 replies; 7+ messages in thread
From: Dmitry Gutov @ 2020-03-04 15:20 UTC (permalink / raw)
  To: Robert Pluim, emacs-devel

On 04.03.2020 16:39, Robert Pluim wrote:
> Should 'xref-goto-ref' widen the buffer before attempting to jump to
> the definition? Or should 'xref-find-definitions' not show definitions
> that are outside the narrowed area?

The latter is pretty hard to do, so the former, I guess.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: xref in a narrowed buffer?
  2020-03-04 15:20 ` Dmitry Gutov
@ 2020-03-04 15:46   ` Stefan Monnier
  2020-03-04 16:04     ` Dmitry Gutov
  2020-03-04 16:08   ` Robert Pluim
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2020-03-04 15:46 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Robert Pluim, emacs-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/x-markdown; coding=UTF-8, Size: 493 bytes --]

>> Should 'xref-goto-ref' widen the buffer before attempting to jump to
>> the definition? Or should 'xref-find-definitions' not show definitions
>> that are outside the narrowed area?
>
> The latter is pretty hard to do, so the former, I guess.

It could also signal a clean error telling the user the destination is
outside of the narrowed region, so the user can decide whether to widen
or not (and is aware of the fact that the source of the problem is the
narrowing).


        Stefan




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: xref in a narrowed buffer?
  2020-03-04 15:46   ` Stefan Monnier
@ 2020-03-04 16:04     ` Dmitry Gutov
  2020-03-04 16:38       ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Gutov @ 2020-03-04 16:04 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Robert Pluim, emacs-devel

On 04.03.2020 17:46, Stefan Monnier wrote:
>>> Should 'xref-goto-ref' widen the buffer before attempting to jump to
>>> the definition? Or should 'xref-find-definitions' not show definitions
>>> that are outside the narrowed area?
>>
>> The latter is pretty hard to do, so the former, I guess.
> 
> It could also signal a clean error telling the user the destination is
> outside of the narrowed region, so the user can decide whether to widen
> or not (and is aware of the fact that the source of the problem is the
> narrowing).

True. It's also an option.

I don't use narrowing, and don't understand its intended behavior, so 
someone else should make the choice on what is the best approach here.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: xref in a narrowed buffer?
  2020-03-04 15:20 ` Dmitry Gutov
  2020-03-04 15:46   ` Stefan Monnier
@ 2020-03-04 16:08   ` Robert Pluim
  2020-03-04 18:18     ` Dmitry Gutov
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Pluim @ 2020-03-04 16:08 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

>>>>> On Wed, 4 Mar 2020 17:20:53 +0200, Dmitry Gutov <dgutov@yandex.ru> said:

    Dmitry> On 04.03.2020 16:39, Robert Pluim wrote:
    >> Should 'xref-goto-ref' widen the buffer before attempting to jump to
    >> the definition? Or should 'xref-find-definitions' not show definitions
    >> that are outside the narrowed area?

    Dmitry> The latter is pretty hard to do, so the former, I guess.

After wandering through the maze of twisty cl-defmethods and wondering
why it wasnʼt working, I read the actual message, and realised I was
using the etags backend. This works for me, perhaps add a (when
widen-automatically ..) ?

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index 897f105019..6995a70b5a 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -2131,6 +2131,7 @@ xref-location-marker
     (let ((buffer (find-file-noselect file)))
       (with-current-buffer buffer
         (save-excursion
+          (widen)
           (etags-goto-tag-location tag-info)
           (point-marker))))))
 



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: xref in a narrowed buffer?
  2020-03-04 16:04     ` Dmitry Gutov
@ 2020-03-04 16:38       ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2020-03-04 16:38 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: rpluim, monnier, emacs-devel

> From: Dmitry Gutov <dgutov@yandex.ru>
> Date: Wed, 4 Mar 2020 18:04:50 +0200
> Cc: Robert Pluim <rpluim@gmail.com>, emacs-devel@gnu.org
> 
> > It could also signal a clean error telling the user the destination is
> > outside of the narrowed region, so the user can decide whether to widen
> > or not (and is aware of the fact that the source of the problem is the
> > narrowing).
> 
> True. It's also an option.
> 
> I don't use narrowing, and don't understand its intended behavior, so 
> someone else should make the choice on what is the best approach here.

Signaling an error sounds TRT to me.  When you narrow a buffer, Emacs
should behave as if the parts outside the restriction didn't exist.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: xref in a narrowed buffer?
  2020-03-04 16:08   ` Robert Pluim
@ 2020-03-04 18:18     ` Dmitry Gutov
  0 siblings, 0 replies; 7+ messages in thread
From: Dmitry Gutov @ 2020-03-04 18:18 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-devel

On 04.03.2020 18:08, Robert Pluim wrote:
>>>>>> On Wed, 4 Mar 2020 17:20:53 +0200, Dmitry Gutov <dgutov@yandex.ru> said:
> 
>      Dmitry> On 04.03.2020 16:39, Robert Pluim wrote:
>      >> Should 'xref-goto-ref' widen the buffer before attempting to jump to
>      >> the definition? Or should 'xref-find-definitions' not show definitions
>      >> that are outside the narrowed area?
> 
>      Dmitry> The latter is pretty hard to do, so the former, I guess.
> 
> After wandering through the maze of twisty cl-defmethods and wondering
> why it wasnʼt working, I read the actual message, and realised I was
> using the etags backend. This works for me, perhaps add a (when
> widen-automatically ..) ?
> 
> diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
> index 897f105019..6995a70b5a 100644
> --- a/lisp/progmodes/etags.el
> +++ b/lisp/progmodes/etags.el
> @@ -2131,6 +2131,7 @@ xref-location-marker
>       (let ((buffer (find-file-noselect file)))
>         (with-current-buffer buffer
>           (save-excursion
> +          (widen)
>             (etags-goto-tag-location tag-info)
>             (point-marker))))))

This would also need a save-restriction.

But according to others, we should signal a meaningful error instead.

That might have to be done in another place (also in etags.el), before 
the "rerun etags" message is shown.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-04 18:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-04 14:39 xref in a narrowed buffer? Robert Pluim
2020-03-04 15:20 ` Dmitry Gutov
2020-03-04 15:46   ` Stefan Monnier
2020-03-04 16:04     ` Dmitry Gutov
2020-03-04 16:38       ` Eli Zaretskii
2020-03-04 16:08   ` Robert Pluim
2020-03-04 18:18     ` Dmitry Gutov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.