From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Gregory Heytings <gregory@heytings.org>
Cc: 60568@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>,
yantar92@posteo.net, mardani29@yahoo.es
Subject: bug#60568: [FR] 30.0.50; Help buffers and function bodies for generated functions
Date: Fri, 06 Jan 2023 12:27:30 -0500 [thread overview]
Message-ID: <jwvmt6vmwr5.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <371ba1d0beb0ed44a9a6@heytings.org> (Gregory Heytings's message of "Fri, 06 Jan 2023 09:11:02 +0000")
>>> Not always, I can imagine functions defined with fset for example.
I'd consider that an error.
`defalias` on the other hand is indeed a normal and common case.
>>> What about the attached patch? It seems to work well.
>> SGTM. With which cases did you test this?
>> Adding Stefan, in case he has any comments.
SGTM as well. I do have some comments, see below.
> +(defun help-function-def--find-probable-definition-place (fun)
Can we shorten the name using "guess" i.s.o "find-probable"?
Also, this should be in `find-func.el` rather than in `help-mode.el`, no?
> + (save-excursion
> + ;; Build a list of strings with the symbols (and strings) of FUN.
> + (let ((names
> + (mapcar (lambda (el)
> + (concat
> + "\\_<"
> + (regexp-quote (format "%s" el))
I think you want "%S" rather than "%s".
> + "\\_>"))
> + (flatten-tree (symbol-function fun))))
- We probably want to use `advice-cd*r` so as to flatten the actual
function definition rather than the combination of its definition with
the various pieces of advice that are currently applied.
- The above works for non-compiled functions but for byte-compiled
functions we need an ad-hoc version of `flatten-tree` which extracts
the constants from the constant vector of bytecode objects (also
recursively since bytecode objects tend to contain other bytecode
objects).
For native-compiled functions, we may be able to get some kind of
"constant vector" as well, but I don't think that's currently
accessible from ELisp. We should ask Andrea.
> + ;; Exclude symbols that are 3 characters or less.
> + (when (> (length el) 9)
If we filter them out when constructing `names`, we can use a comment
where the number matches the number used in the code :-)
> + ;; Determine the beginning position of that
> + ;; function.
> + (goto-char (point-min))
> + (when (catch 'found
> + (while (re-search-forward
> + (concat "\\_<"
> + (regexp-quote result)
> + "\\_>"))
> + (when (string= (lisp-current-defun-name)
> + result)
> + (throw 'found t)))
> + (throw 'found nil))
> + (beginning-of-defun)
> + (cons result (point)))))))))))))
Can't we use `find-function-noselect` here? Or maybe just return the
function name and let the caller then use `find-function-noselect`.
> @@ -281,7 +366,31 @@ help-function-def--button-function
> (unless (= (point) position)
> (push-mark nil t))
> (goto-char position))
> - (message "Unable to find location in file")))))
> + (let ((probable-definition-place
> + (help-function-def--find-probable-definition-place fun)))
> + (when probable-definition-place
> + (goto-char (cdr probable-definition-place)))
> + (let ((help-buffer-under-preparation t))
> + (help-setup-xref (list #'help-function-def--button-function
> + fun file)
> + (called-interactively-p 'interactive))
> + (with-help-window (help-buffer)
> + (insert (substitute-command-keys
> + (format "Function %s could not be found in `%s'.\n\n"
> + fun (file-name-nondirectory file))))
> + (setq help-mode--current-data (list :symbol fun
> + :file file))
> + (save-excursion
> + (re-search-backward
> + (substitute-command-keys "`\\([^`']+\\)'")
> + nil t)
> + (help-xref-button 1 'help-function-def fun file))
> + (when probable-definition-place
> + (insert (substitute-command-keys
> + (format "It was probably defined by `%s'.\n\n"
> + (car probable-definition-place)))))
> + (insert "Function definition:\n\n")
> + (insert (pp-to-string (symbol-function fun))))))))))
Please move this to a separate function.
Also, I'm not completely convinced what you do with the *Help* buffer
here is the UI we'll want, really. But I don't have a good idea for
what to replace it with (yet), so we can start with that and tweak
it later.
Stefan
next prev parent reply other threads:[~2023-01-06 17:27 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 7:56 bug#60568: [FR] 30.0.50; Help buffers and function bodies for generated functions Ihor Radchenko
2023-01-05 8:09 ` Eli Zaretskii
2023-01-05 8:20 ` Ihor Radchenko
2023-01-05 8:32 ` Eli Zaretskii
2023-01-05 17:04 ` Jean Louis
2023-01-05 17:03 ` Jean Louis
2023-01-05 9:40 ` Gregory Heytings
2023-01-05 9:52 ` Gregory Heytings
2023-01-05 10:45 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-05 10:52 ` Ihor Radchenko
2023-01-05 11:20 ` Eli Zaretskii
2023-01-05 12:33 ` Gregory Heytings
2023-01-05 14:16 ` Eli Zaretskii
2023-01-05 14:27 ` Gregory Heytings
2023-01-05 15:10 ` Eli Zaretskii
2023-01-05 15:13 ` Gregory Heytings
2023-01-05 16:49 ` Eli Zaretskii
2023-01-05 20:44 ` Gregory Heytings
2023-01-06 6:35 ` Eli Zaretskii
2023-01-06 9:11 ` Gregory Heytings
2023-01-06 17:27 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-01-06 22:52 ` Gregory Heytings
2023-01-07 0:36 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-07 6:55 ` Eli Zaretskii
2023-01-07 9:42 ` Gregory Heytings
2023-01-07 13:38 ` Ihor Radchenko
2023-01-07 14:00 ` Eli Zaretskii
2023-01-07 14:04 ` Gregory Heytings
2023-01-07 15:07 ` Ihor Radchenko
2023-01-07 15:14 ` Eli Zaretskii
2023-01-07 15:19 ` Ihor Radchenko
2023-01-07 15:23 ` Eli Zaretskii
2023-01-07 17:59 ` Eli Zaretskii
2023-01-07 13:14 ` Ihor Radchenko
2023-01-07 13:55 ` Eli Zaretskii
2023-01-05 17:00 ` Jean Louis
2023-01-06 8:39 ` Ihor Radchenko
2023-01-06 16:44 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-07 11:32 ` Ihor Radchenko
2023-01-07 15:44 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-12 10:40 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvmt6vmwr5.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=60568@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=gregory@heytings.org \
--cc=mardani29@yahoo.es \
--cc=monnier@iro.umontreal.ca \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).