From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.bugs Subject: bug#60568: [FR] 30.0.50; Help buffers and function bodies for generated functions Date: Thu, 5 Jan 2023 20:00:50 +0300 Message-ID: References: <87fscpifdw.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22471"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.9+54 (af2080d) (2022-11-21) Cc: 60568@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 05 18:08:38 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pDTjK-0005fr-0x for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 05 Jan 2023 18:08:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDThw-0007e7-ON; Thu, 05 Jan 2023 12:07:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pDTho-0007Vy-BB for bug-gnu-emacs@gnu.org; Thu, 05 Jan 2023 12:07:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pDThm-0006Vt-L5 for bug-gnu-emacs@gnu.org; Thu, 05 Jan 2023 12:07:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pDThm-0006sn-GN for bug-gnu-emacs@gnu.org; Thu, 05 Jan 2023 12:07:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jean Louis Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Jan 2023 17:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60568 X-GNU-PR-Package: emacs Original-Received: via spool by 60568-submit@debbugs.gnu.org id=B60568.167293838826388 (code B ref 60568); Thu, 05 Jan 2023 17:07:02 +0000 Original-Received: (at 60568) by debbugs.gnu.org; 5 Jan 2023 17:06:28 +0000 Original-Received: from localhost ([127.0.0.1]:52718 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDThE-0006rY-3d for submit@debbugs.gnu.org; Thu, 05 Jan 2023 12:06:28 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:46419) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDThC-0006rA-FL for 60568@debbugs.gnu.org; Thu, 05 Jan 2023 12:06:27 -0500 Original-Received: from localhost ([::ffff:102.85.153.82]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000055EA2.0000000063B70395.0000220A; Thu, 05 Jan 2023 10:06:28 -0700 Content-Disposition: inline In-Reply-To: <87fscpifdw.fsf@localhost> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:252613 Archived-At: * Ihor Radchenko [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/