all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
@ 2021-07-04  3:40 Hongyi Zhao
  2021-07-04 17:24 ` Daniel Martín
  0 siblings, 1 reply; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-04  3:40 UTC (permalink / raw)
  To: help-gnu-emacs

Say, I've the following content snippet in the Apropos buffer:

!cons
  Macro: Destructive: Set CDR to the cons of CAR and CDR.
  Properties: edebug-form-spec

If I put the cursor on cons, NOT !cons, and then hit `M-.', Emacs
can't skip to the DEFUN of cons. But if I do the same operations in
scratch buffer, it will do the trick.

Any hints for this behavior shown by Emacs? And how to obtain the same
effect in other buffers as shown in scratch buffer?

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-04  3:40 `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer Hongyi Zhao
@ 2021-07-04 17:24 ` Daniel Martín
  2021-07-05  2:44   ` Hongyi Zhao
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Martín @ 2021-07-04 17:24 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> Say, I've the following content snippet in the Apropos buffer:
>
> !cons
>   Macro: Destructive: Set CDR to the cons of CAR and CDR.
>   Properties: edebug-form-spec
>
> If I put the cursor on cons, NOT !cons, and then hit `M-.', Emacs
> can't skip to the DEFUN of cons. But if I do the same operations in
> scratch buffer, it will do the trick.
>
> Any hints for this behavior shown by Emacs? And how to obtain the same
> effect in other buffers as shown in scratch buffer?
>
> Regards

It depends on the variable xref-backend-functions (which can be made
buffer-local).  In general (and in Apropos buffers in particular), that
special hook only queries the Etags backend (etags--xref-backend), but
in the scratch buffer and other elisp-mode buffers it also queries the
Elisp backend (elisp--xref-backend), which uses the Emacs load history
to go to the definition.

So to have what you want, you could either:

- Generate TAGS for Emacs sources ("make tags" from a checked out Emacs
  source code directory).  Then M-x visit-tags-table RET
  <Emacs_source_dir>/src/TAGS RET.  That would also work for apropos
  functions and commands that are implemented in C.

- Create a buffer-local binding for xref-backend-functions in Apropos
  buffers where you prepend elisp--xref-backend to the list.
  



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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-04 17:24 ` Daniel Martín
@ 2021-07-05  2:44   ` Hongyi Zhao
  2021-07-05 21:26     ` Daniel Martín
  0 siblings, 1 reply; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-05  2:44 UTC (permalink / raw)
  To: Daniel Martín; +Cc: help-gnu-emacs

On Mon, Jul 5, 2021 at 1:24 AM Daniel Martín <mardani29@yahoo.es> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > Say, I've the following content snippet in the Apropos buffer:
> >
> > !cons
> >   Macro: Destructive: Set CDR to the cons of CAR and CDR.
> >   Properties: edebug-form-spec
> >
> > If I put the cursor on cons, NOT !cons, and then hit `M-.', Emacs
> > can't skip to the DEFUN of cons. But if I do the same operations in
> > scratch buffer, it will do the trick.
> >
> > Any hints for this behavior shown by Emacs? And how to obtain the same
> > effect in other buffers as shown in scratch buffer?
> >
> > Regards
>
> It depends on the variable xref-backend-functions (which can be made
> buffer-local).  In general (and in Apropos buffers in particular), that
> special hook only queries the Etags backend (etags--xref-backend), but
> in the scratch buffer and other elisp-mode buffers it also queries the
> Elisp backend (elisp--xref-backend), which uses the Emacs load history
> to go to the definition.
>
> So to have what you want, you could either:

Thank you very much for your explanation.

>
> - Generate TAGS for Emacs sources ("make tags" from a checked out Emacs
>   source code directory).  Then M-x visit-tags-table RET
>   <Emacs_source_dir>/src/TAGS RET.  That would also work for apropos
>   functions and commands that are implemented in C.

This way seems cumbersome.

>
> - Create a buffer-local binding for xref-backend-functions in Apropos
>   buffers where you prepend elisp--xref-backend to the list.
>

I've read some relevant document [1], but still can't figure out how
to set this feature in my initialization file.

[1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-05  2:44   ` Hongyi Zhao
@ 2021-07-05 21:26     ` Daniel Martín
  2021-07-06  0:02       ` Hongyi Zhao
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Martín @ 2021-07-05 21:26 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>>
>> - Create a buffer-local binding for xref-backend-functions in Apropos
>>   buffers where you prepend elisp--xref-backend to the list.
>>
>
> I've read some relevant document [1], but still can't figure out how
> to set this feature in my initialization file.
>
> [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html
>

You could add something like

(add-hook 'apropos-mode-hook
	  (lambda ()
	    (add-hook 'xref-backend-functions
		      #'elisp--xref-backend nil t)))

apropos-mode-hook is the hook that is invoked when apropos-mode is
turned on.  Notice that I pass t as the fourth argument to add-hook;
that says to modify the buffer-local value of xref-backend-functions,
not the global value.  As the code is evaluated when apropos-mode is
turned on, the current buffer will be the Apropos buffer and the change
will only have an effect on that buffer.




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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-05 21:26     ` Daniel Martín
@ 2021-07-06  0:02       ` Hongyi Zhao
  2021-07-06  0:09         ` Hongyi Zhao
  0 siblings, 1 reply; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-06  0:02 UTC (permalink / raw)
  To: Daniel Martín; +Cc: help-gnu-emacs

On Tue, Jul 6, 2021 at 5:27 AM Daniel Martín <mardani29@yahoo.es> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> >>
> >> - Create a buffer-local binding for xref-backend-functions in Apropos
> >>   buffers where you prepend elisp--xref-backend to the list.
> >>
> >
> > I've read some relevant document [1], but still can't figure out how
> > to set this feature in my initialization file.
> >
> > [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html
> >
>
> You could add something like
>
> (add-hook 'apropos-mode-hook
>           (lambda ()
>             (add-hook 'xref-backend-functions
>                       #'elisp--xref-backend nil t)))
>

The built-in help document says:

```
(add-hook HOOK FUNCTION &optional DEPTH LOCAL)

[...]
The place where the function is added depends on the DEPTH
parameter.  DEPTH defaults to 0.  By convention, it should be
a number between -100 and 100 where 100 means that the function
should be at the very end of the list, whereas -100 means that
the function should always come first.
Since nothing is "always" true, don’t use 100 nor -100.
When two functions have the same depth, the new one gets added after the
old one if depth is strictly positive and before otherwise.

For backward compatibility reasons, a symbol other than nil is
interpreted as a DEPTH of 90.
```

Here, you set DEPTH to nil. I'm not sure if your usage is equivalent
to the following?

  (add-hook 'apropos-mode-hook
           (lambda ()
             (add-hook 'xref-backend-functions
                       #'elisp--xref-backend 0 t)))

> apropos-mode-hook is the hook that is invoked when apropos-mode is
> turned on.  Notice that I pass t as the fourth argument to add-hook;
> that says to modify the buffer-local value of xref-backend-functions,
> not the global value.  As the code is evaluated when apropos-mode is
> turned on, the current buffer will be the Apropos buffer and the change
> will only have an effect on that buffer.
>

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-06  0:02       ` Hongyi Zhao
@ 2021-07-06  0:09         ` Hongyi Zhao
  2021-07-06  0:19           ` Hongyi Zhao
  0 siblings, 1 reply; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-06  0:09 UTC (permalink / raw)
  To: Daniel Martín; +Cc: help-gnu-emacs

On Tue, Jul 6, 2021 at 8:02 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Tue, Jul 6, 2021 at 5:27 AM Daniel Martín <mardani29@yahoo.es> wrote:
> >
> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >
> > >>
> > >> - Create a buffer-local binding for xref-backend-functions in Apropos
> > >>   buffers where you prepend elisp--xref-backend to the list.
> > >>
> > >
> > > I've read some relevant document [1], but still can't figure out how
> > > to set this feature in my initialization file.
> > >
> > > [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html
> > >
> >
> > You could add something like
> >
> > (add-hook 'apropos-mode-hook
> >           (lambda ()
> >             (add-hook 'xref-backend-functions
> >                       #'elisp--xref-backend nil t)))
> >
>
> The built-in help document says:
>
> ```
> (add-hook HOOK FUNCTION &optional DEPTH LOCAL)
>
> [...]
> The place where the function is added depends on the DEPTH
> parameter.  DEPTH defaults to 0.  By convention, it should be
> a number between -100 and 100 where 100 means that the function
> should be at the very end of the list, whereas -100 means that
> the function should always come first.
> Since nothing is "always" true, don’t use 100 nor -100.
> When two functions have the same depth, the new one gets added after the
> old one if depth is strictly positive and before otherwise.
>
> For backward compatibility reasons, a symbol other than nil is
> interpreted as a DEPTH of 90.
> ```
>
> Here, you set DEPTH to nil. I'm not sure if your usage is equivalent
> to the following?
>
>   (add-hook 'apropos-mode-hook
>            (lambda ()
>              (add-hook 'xref-backend-functions
>                        #'elisp--xref-backend 0 t)))
>

Based on my tries, passing nil or 0 as the third argument is
equivalent. Thank you again.

HY
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-06  0:09         ` Hongyi Zhao
@ 2021-07-06  0:19           ` Hongyi Zhao
  2021-07-06  0:29             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-06  0:19 UTC (permalink / raw)
  To: Daniel Martín; +Cc: help-gnu-emacs

On Tue, Jul 6, 2021 at 8:09 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Tue, Jul 6, 2021 at 8:02 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> >
> > On Tue, Jul 6, 2021 at 5:27 AM Daniel Martín <mardani29@yahoo.es> wrote:
> > >
> > > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> > >
> > > >>
> > > >> - Create a buffer-local binding for xref-backend-functions in Apropos
> > > >>   buffers where you prepend elisp--xref-backend to the list.
> > > >>
> > > >
> > > > I've read some relevant document [1], but still can't figure out how
> > > > to set this feature in my initialization file.
> > > >
> > > > [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html
> > > >
> > >
> > > You could add something like
> > >
> > > (add-hook 'apropos-mode-hook
> > >           (lambda ()
> > >             (add-hook 'xref-backend-functions
> > >                       #'elisp--xref-backend nil t)))
> > >
> >
> > The built-in help document says:
> >
> > ```
> > (add-hook HOOK FUNCTION &optional DEPTH LOCAL)
> >
> > [...]
> > The place where the function is added depends on the DEPTH
> > parameter.  DEPTH defaults to 0.  By convention, it should be
> > a number between -100 and 100 where 100 means that the function
> > should be at the very end of the list, whereas -100 means that
> > the function should always come first.
> > Since nothing is "always" true, don’t use 100 nor -100.
> > When two functions have the same depth, the new one gets added after the
> > old one if depth is strictly positive and before otherwise.
> >
> > For backward compatibility reasons, a symbol other than nil is
> > interpreted as a DEPTH of 90.
> > ```
> >
> > Here, you set DEPTH to nil. I'm not sure if your usage is equivalent
> > to the following?
> >
> >   (add-hook 'apropos-mode-hook
> >            (lambda ()
> >              (add-hook 'xref-backend-functions
> >                        #'elisp--xref-backend 0 t)))
> >
>
> Based on my tries, passing nil or 0 as the third argument is
> equivalent. Thank you again.
>

For this case, according to my understanding, the 3rd argument used
here is just as a placeholder.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-06  0:19           ` Hongyi Zhao
@ 2021-07-06  0:29             ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-07-06  0:46               ` Hongyi Zhao
  0 siblings, 1 reply; 9+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-06  0:29 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao wrote:

>>> (add-hook 'apropos-mode-hook
>>>    (lambda ()
>>>       (add-hook 'xref-backend-functions
>>>          #'elisp--xref-backend 0 t)))
>>
>> Based on my tries, passing nil or 0 as the third argument
>> is equivalent. Thank you again.
>
> For this case, according to my understanding, the 3rd
> argument used here is just as a placeholder.

C-h f add-hook RET

  DEPTH defaults to 0.

That means, it is better to send nil than 0 if you want the
default value. If you pass 0 is sounds like that's the value
you have computed for your purposes. Well, if it IS, only then
you should pass it.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer.
  2021-07-06  0:29             ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-06  0:46               ` Hongyi Zhao
  0 siblings, 0 replies; 9+ messages in thread
From: Hongyi Zhao @ 2021-07-06  0:46 UTC (permalink / raw)
  To: Emanuel Berg, help-gnu-emacs

On Tue, Jul 6, 2021 at 8:29 AM Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> >>> (add-hook 'apropos-mode-hook
> >>>    (lambda ()
> >>>       (add-hook 'xref-backend-functions
> >>>          #'elisp--xref-backend 0 t)))
> >>
> >> Based on my tries, passing nil or 0 as the third argument
> >> is equivalent. Thank you again.
> >
> > For this case, according to my understanding, the 3rd
> > argument used here is just as a placeholder.
>
> C-h f add-hook RET
>
>   DEPTH defaults to 0.
>
> That means, it is better to send nil than 0 if you want the
> default value. If you pass 0 is sounds like that's the value
> you have computed for your purposes. Well, if it IS, only then
> you should pass it.

Wonderful explanation. Thanks again.

HY
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



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

end of thread, other threads:[~2021-07-06  0:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-04  3:40 `M-.' can't skip to the corresponding DEFUN from within the Apropos buffer Hongyi Zhao
2021-07-04 17:24 ` Daniel Martín
2021-07-05  2:44   ` Hongyi Zhao
2021-07-05 21:26     ` Daniel Martín
2021-07-06  0:02       ` Hongyi Zhao
2021-07-06  0:09         ` Hongyi Zhao
2021-07-06  0:19           ` Hongyi Zhao
2021-07-06  0:29             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-06  0:46               ` Hongyi Zhao

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.