all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How does `describe-function' know where the source code of the function is?
@ 2022-01-17  4:03 Marcin Borkowski
  2022-01-17  4:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Marcin Borkowski @ 2022-01-17  4:03 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hi all,

If I define a function with `defun', C-h f gives me a link to the source
code of the function.  I defined a macro defining a function (its
expansion contained a `defun'), and C-h f'ing that function did /not/
give me that link.  I tried saying M-: (symbol-plist 'my-function), but
I haven't seen any property that would point to the source code.  So, my
question is: how does `describe-function' know where the link should
point to (and if it should be rendered at all)?  I skimmed its source
code, but it seems pretty convoluted.  I found
`help-fns-function-description-header', but it seems that the actual
code finding the exact position of the function definition is buried
deep down the call chain, so I'm asking here in the hope that someone
could point me to the right place faster than me trying to edebug this
or something.

TIA,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: How does `describe-function' know where the source code of the function is?
  2022-01-17  4:03 How does `describe-function' know where the source code of the function is? Marcin Borkowski
@ 2022-01-17  4:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2022-01-17  4:27 ` Eduardo Ochs
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2022-01-17  4:14 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski wrote:

> If I define a function with `defun', C-h f gives me a link
> to the source code of the function. I defined a macro
> defining a function (its expansion contained a `defun'), and
> C-h f'ing that function did /not/ give me that link. I tried
> saying M-: (symbol-plist 'my-function), but I haven't seen
> any property that would point to the source code. So, my
> question is: how does `describe-function' know where the
> link should point to (and if it should be rendered at all)?

Isn't the help system fed data when the defun is evaluated?

After that it's too late to find out :)

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




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

* Re: How does `describe-function' know where the source code of the function is?
  2022-01-17  4:03 How does `describe-function' know where the source code of the function is? Marcin Borkowski
  2022-01-17  4:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2022-01-17  4:27 ` Eduardo Ochs
  2022-01-17 16:22 ` Michael Heerdegen
  2022-01-18  2:51 ` Stefan Monnier via Users list for the GNU Emacs text editor
  3 siblings, 0 replies; 7+ messages in thread
From: Eduardo Ochs @ 2022-01-17  4:27 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list

On Mon, 17 Jan 2022 at 01:04, Marcin Borkowski <mbork@mbork.pl> wrote:

> Hi all,
>
> If I define a function with `defun', C-h f gives me a link to the source
> code of the function.  I defined a macro defining a function (its
> expansion contained a `defun'), and C-h f'ing that function did /not/
> give me that link.  I tried saying M-: (symbol-plist 'my-function), but
> I haven't seen any property that would point to the source code.  So, my
> question is: how does `describe-function' know where the link should
> point to (and if it should be rendered at all)?  I skimmed its source
> code, but it seems pretty convoluted.  I found
> `help-fns-function-description-header', but it seems that the actual
> code finding the exact position of the function definition is buried
> deep down the call chain, so I'm asking here in the hope that someone
> could point me to the right place faster than me trying to edebug this
> or something.
>
>
Hi Marcin,

when we run `M-h M-f find-file' or this sexp in eev,

  (find-efunction-links 'find-file)

it shows a temporary buffer with lots of sexps about `find-file',
including some that are quite technical and that are mostly for people
who want to understand how the higher-level functions work. I ran that
now, and the contents of the temporary buffer were these:

  # (find-efunction-links 'find-file)
  # (eek "M-h M-f  find-file")
  # (find-eev-quick-intro "4.2. `find-ekey-links' and friends")

  # (find-efunctiondescr 'find-file)
  # (find-efunction 'find-file)
  # (find-efunctionpp 'find-file)
  # (find-efunctiond 'find-file)

  # (Info-goto-emacs-command-node 'find-file)
  # (find-enode "Command Index" "* find-file:")
  # (find-elnode "Index" "* find-file:")

  # (where-is 'find-file)
  # (symbol-file 'find-file 'defun)
  # (find-fline (symbol-file 'find-file 'defun))
  # (find-epp (assoc (symbol-file 'find-file 'defun) load-history))
  # (find-epp (assoc "/home/edrx/bigsrc/emacs28/lisp/files.elc"
load-history))
  # (find-eppp (mapcar 'car load-history))
  # (find-estring (mapconcat 'identity (mapcar 'car load-history) "\n"))
  # (find-estring (documentation 'find-file))
  # (find-estring (documentation 'find-file t))
  # (describe-function 'find-file)

I think that the sexps in the third block contain a lot of what you
want, and the eev-isms should be easy to ignore.

Btw, I made a video a few weeks ago about the functions of eev that
show lots of very technical sexps like the ones in the third block
above. The video is here:

  http://angg.twu.net/2021-ffll.html

Cheers & happy hacking, =)
  Eduardo Ochs
  http://angg.twu.net/#eev


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

* Re: How does `describe-function' know where the source code of the function is?
  2022-01-17  4:03 How does `describe-function' know where the source code of the function is? Marcin Borkowski
  2022-01-17  4:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2022-01-17  4:27 ` Eduardo Ochs
@ 2022-01-17 16:22 ` Michael Heerdegen
  2022-01-18  2:51 ` Stefan Monnier via Users list for the GNU Emacs text editor
  3 siblings, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2022-01-17 16:22 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski <mbork@mbork.pl> writes:

> [...] question is: how does `describe-function' know where the link
> should point to (and if it should be rendered at all)?

AFAIK thanks to the stuff in "find-func.el".

Michael.




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

* Re: How does `describe-function' know where the source code of the function is?
  2022-01-17  4:03 How does `describe-function' know where the source code of the function is? Marcin Borkowski
                   ` (2 preceding siblings ...)
  2022-01-17 16:22 ` Michael Heerdegen
@ 2022-01-18  2:51 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-01-18 17:41   ` Marcin Borkowski
  3 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-01-18  2:51 UTC (permalink / raw)
  To: help-gnu-emacs

> question is: how does `describe-function' know where the link should
> point to (and if it should be rendered at all)?  I skimmed its source

The name of the file is stored in `load-history`.  The function
definition itself is then found (or not) by a naive regexp search.


        Stefan




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

* Re: How does `describe-function' know where the source code of the function is?
  2022-01-18  2:51 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-01-18 17:41   ` Marcin Borkowski
  2022-01-18 18:46     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Marcin Borkowski @ 2022-01-18 17:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


On 2022-01-18, at 03:51, Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:

>> question is: how does `describe-function' know where the link should
>> point to (and if it should be rendered at all)?  I skimmed its source
>
> The name of the file is stored in `load-history`.  The function
> definition itself is then found (or not) by a naive regexp search.

Thanks!  This is actually kind of fascinating - on the one hand, it
seems so fragile, and on the other hand, it works 99.99% of the time...

Best,

-- 
Marcin Borkowski
http://mbork.pl



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

* Re: How does `describe-function' know where the source code of the function is?
  2022-01-18 17:41   ` Marcin Borkowski
@ 2022-01-18 18:46     ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2022-01-18 18:46 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: help-gnu-emacs

> Thanks!  This is actually kind of fascinating - on the one hand, it
> seems so fragile, and on the other hand, it works 99.99% of the time...

It's actually the result of a form of machine learning: when the system
fails to work, we get a bug-report which feeds back into improving the
system, so with enough users using the system that gets up millions of
"training data".

The backpropagation algorithm involves actual human brain cells, tho ;-)


        Stefan




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

end of thread, other threads:[~2022-01-18 18:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-17  4:03 How does `describe-function' know where the source code of the function is? Marcin Borkowski
2022-01-17  4:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-01-17  4:27 ` Eduardo Ochs
2022-01-17 16:22 ` Michael Heerdegen
2022-01-18  2:51 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-01-18 17:41   ` Marcin Borkowski
2022-01-18 18:46     ` Stefan Monnier

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.