From: Jean Louis <bugs@gnu.support>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: 60568@debbugs.gnu.org
Subject: bug#60568: [FR] 30.0.50; Help buffers and function bodies for generated functions
Date: Thu, 5 Jan 2023 20:00:50 +0300 [thread overview]
Message-ID: <Y7cCQnkU6ZyZSDZ0@protected.localdomain> (raw)
In-Reply-To: <87fscpifdw.fsf@localhost>
* Ihor Radchenko <yantar92@posteo.net> [2023-01-05 10:57]:
> Recently, we have stumbled upon a situation when showing function code
> is not only useful, but one of the few sane ways to examine it [3].
> Functions that are not directly written in the source but rather
> generated programmatically cannot currently be easily examined using
> built-in help functionality (using describe-function or other means).
> The help buffer only links to the (point-min) in the library defining
> the generated function - not very helpful. In contrast, helpful extracts
> function body from symbol function slot.
> Would it be possible to provide function body info via *Help* system in
> Emacs?
That would be helpful.
When there is some on the fly defined function I have used
`symbol-function' function to extract data and save the function in the file for
later examination.
;;; SAVE FUNCTION
(defun save-function ()
"Saves function at point"
(interactive)
(let ((function (function-called-at-point)))
(when (and (symbolp function)
(y-or-n-p (format "Save `%s'" (symbol-name function))))
(save-function-1 function))))
(defun save-function-1 (function)
(let* ((fun (symbol-function function))
(type (car fun))
(file (concat rcd-temp-file-directory
"function-" (symbol-name function) ".el")))
(cond ((eq type 'lambda) (setq fun (append (list 'defun function) (cdr fun))))
((eq type 'closure) (setq fun (append (list 'defun function) (nthcdr 2 fun)))))
(message (string-to-file-force (prin1-to-string fun) file))))
(defun save-function-delete ()
(interactive)
(save-function)
(beginning-of-line)
(mark-sexp)
(delete-active-region))
Then I would get this result, for example:
-rw-r--r-- 1 668 Jan 5 19:54 function-hyperscope-add-new-note-hyperdocument.el
with body being:
(defun hyperscope-add-new-note-hyperdocument nil (interactive) (let* ((parent (hyperscope-set-parent-or-select)) (markup (hyperscope-markup-select)) (related-person-by-parent (if parent (progn (hyperscope-related-person-id parent)))) (related-person (if (and related-person-by-parent (y-or-n-p (format "Is Hyperdocument related to `%s'? " (cf-people-name related-person-by-parent)))) (progn related-person-by-parent))) (prompt (format "New `%s' hyperdocument name: " type-name)) (name (rcd-ask prompt)) (hyperdocument (hyperscope-add-generic name "" markup id nil parent nil nil nil related-person))) (hyperscope-ring hyperdocument) (hyperscope-revert hyperdocument)))
Which I know is not very readable, but is still something useful.
Thus the help buffer shall try to find function in source, but if it
is not there, it shall at least show it's definition by using
`symbol-function'.
Problem is with byte-compiled functions:
(symbol-function 'rcd-iso-date) ➜ #[0 "\300\301!\207" [format-time-string "%Y-%m-%d"] 2]
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2023-01-05 17:00 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
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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7cCQnkU6ZyZSDZ0@protected.localdomain \
--to=bugs@gnu.support \
--cc=60568@debbugs.gnu.org \
--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 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.