From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings Newsgroups: gmane.emacs.bugs Subject: bug#60568: [FR] 30.0.50; Help buffers and function bodies for generated functions Date: Fri, 06 Jan 2023 22:52:32 +0000 Message-ID: <371ba1d0be96347bdf60@heytings.org> References: <87fscpifdw.fsf@localhost> <83wn61w7lc.fsf@gnu.org> <8dea9f3e0e7865d8f3c6@heytings.org> <83r0w9vzgy.fsf@gnu.org> <8dea9f3e0e8e6114ffc3@heytings.org> <83pmbtvwyr.fsf@gnu.org> <8dea9f3e0e160e17818f@heytings.org> <83mt6xvsct.fsf@gnu.org> <8dea9f3e0ea1de84c49a@heytings.org> <83cz7sw4q1.fsf@gnu.org> <371ba1d0beb0ed44a9a6@heytings.org> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28221"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 60568@debbugs.gnu.org, yantar92@posteo.net, Eli Zaretskii , mardani29@yahoo.es To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 06 23:53:20 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 1pDvaR-0007BM-W8 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 06 Jan 2023 23:53:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDvaB-0000uU-Si; Fri, 06 Jan 2023 17:53:03 -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 1pDvaA-0000uG-TZ for bug-gnu-emacs@gnu.org; Fri, 06 Jan 2023 17:53:03 -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 1pDvaA-00082b-AV for bug-gnu-emacs@gnu.org; Fri, 06 Jan 2023 17:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pDva9-0006PF-PL for bug-gnu-emacs@gnu.org; Fri, 06 Jan 2023 17:53:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gregory Heytings Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 06 Jan 2023 22:53:01 +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.167304555624594 (code B ref 60568); Fri, 06 Jan 2023 22:53:01 +0000 Original-Received: (at 60568) by debbugs.gnu.org; 6 Jan 2023 22:52:36 +0000 Original-Received: from localhost ([127.0.0.1]:56016 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDvZk-0006Ob-9h for submit@debbugs.gnu.org; Fri, 06 Jan 2023 17:52:36 -0500 Original-Received: from heytings.org ([95.142.160.155]:33956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDvZi-0006OT-D4 for 60568@debbugs.gnu.org; Fri, 06 Jan 2023 17:52:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20220101; t=1673045553; bh=zECz0m3z+tK2Z0EcaJYDP2pw7gWRHiOuO0Jusv7vgyo=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:From; b=f8XTdY5itkJeOIoBCW6uQobSGIEtDlgc/NK6yH2flyzaFvRFYebJqogluPBsR/1gi oklXtIiKIfc0KkqNJRiiAnFX8euTkzEvRzuTtcmscYti/axUYWT/OC0VKsvw53QSHn KlURKGW2fePGpquw62WRbW8JEa1hkRi0l3lK1jsYey52VRLCi7M6dXbuYbfZDo/bB6 iv0ZzJVy2k0unUxzMNbsR2RO+UkGzMwSlvkdLFrLOgE+3z63FtO0HQXaduyiu5eXCB 7B/KQ7AyNZkSjDtvFj+HEAp7C/jtWUhpiSxHLy+DWE5lCGdvshJ8HYqsTcADOFcbS1 WQCibVcp8870Q== In-Reply-To: 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:252755 Archived-At: >>>> 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. > TBH, I'm not sure this is useful anymore, if the 'definition-name' slot is supposed to be used for such functions (which I didn't know). WDYT? >> +(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? > Yes and yes. >> + (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. > You mean, (flatten-tree (advice--cd*r (symbol-function fun))), right? > > - 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. > Are such dynamically defined functions not always non-compiled, by definition? At least with the original recipe in this feature request, (symbol-file 'org-babel-execute:sh) returns "lisp/org/ob-shell.elc", so it has been created by a byte-compiled function. >> + ;; 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 :-) > Oh yes ;-) >> + ;; 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`. > Indeed! >> @@ -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. > Sure. > > 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. > Okay.