From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "H. Dieter Wilhelm" Newsgroups: gmane.emacs.bugs Subject: bug#60587: Patch for adding links to symbols' help documentation Date: Sat, 14 Jan 2023 00:33:19 +0100 Message-ID: <867cxqui0w.fsf@duenenhof-wilhelm.de> References: <86y1qgr1bf.fsf@duenenhof-wilhelm.de> <86tu13qydg.fsf@duenenhof-wilhelm.de> <83h6x2u74b.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11169"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cc: 60587@debbugs.gnu.org, Stefan Monnier To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 14 00:34:21 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 1pGTYz-0002h7-EN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Jan 2023 00:34:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGTYj-0000Xh-4l; Fri, 13 Jan 2023 18:34:05 -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 1pGTYg-0000X0-Vi for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2023 18:34:02 -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 1pGTYg-0002Zr-NP for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2023 18:34:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pGTYg-00005P-Ip for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2023 18:34:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "H. Dieter Wilhelm" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Jan 2023 23:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60587 X-GNU-PR-Package: emacs Original-Received: via spool by 60587-submit@debbugs.gnu.org id=B60587.167365281432738 (code B ref 60587); Fri, 13 Jan 2023 23:34:02 +0000 Original-Received: (at 60587) by debbugs.gnu.org; 13 Jan 2023 23:33:34 +0000 Original-Received: from localhost ([127.0.0.1]:52689 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGTYD-0008Vx-Lr for submit@debbugs.gnu.org; Fri, 13 Jan 2023 18:33:34 -0500 Original-Received: from mout.kundenserver.de ([212.227.17.24]:32943) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pGTYB-0008Vj-FS for 60587@debbugs.gnu.org; Fri, 13 Jan 2023 18:33:32 -0500 Original-Received: from ping ([109.250.147.186]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MKsax-1p1pTo1ttd-00LGWI; Sat, 14 Jan 2023 00:33:21 +0100 In-Reply-To: <83h6x2u74b.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 07 Jan 2023 09:38:28 +0200") X-Provags-ID: V03:K1:Lkr8Q5u5QNBHy/B6/eeUHwUnQ/ryhAEcbjJjBFLm0A8b3/GL91V 0tRi/+LdIo2wXpULCg2D34Z3/YZn31Y/CDbmHOU1aQPqUboqC+gs2L66HrI5GHRJ/xes15u 3lgtUJF01lIzS1ZzncR6BnJ6YS311/sTdv0wE/yoL0Z76bLBJZfTbiog4xffskCn+ZgGdOO PXJzsutWZ61+JEQLiqiKA== UI-OutboundReport: notjunk:1;M01:P0:GPR0p3Y5iNY=;f5VVTHTNhPNXcU8lPgkfaXH6LJL CiR+KF9/zxBl3PENl8e4xXNq86v0gCFfvcSfzwfqXjgLsGLfRv/BuUyXRbBXymku0FBw5dQap fDHoXg32S7EjZpQy0QYlj50NslyMOUXyXxGOrqQBBsiR/HDAvCELi+WhsLUcxN8nVjkEeqHAL xGM9qornYV/XAsPtYQZIfmndBuTbyedWLwpuuqiWsgRj0JAP97JpoVZtCt4Wn2+5KsmV2lg2e PlSTZ6PZyXlXOQJn+rRQRmyvDw2cClPhHcvVoYY9B+r0n1UXQH2rIDvsoM61cP7AYO8/bh/Ny /dk14ru5UM/DrqEpnX2SrP90evN9pjs1x795rEzNwtpT+PdyeVYPdqkcdr8QcJvKjp7KrcWPx A4tYB+1EowEHLaeQ4oLQCSA4GntgGqcpgMTcZr1d5nj6dbksGd+3BhBa843JGtJrME3tDmEdu 0P9Ck55vHWf6ru0Cgir8CD7ivKsQAVYyeWMDyUB/mgX/3640Aqc83VO0g+8lUsuRzhRjMgzVQ uPqW7NnQLFIi8luH5OccJ57I4O0LFis+KyFNWtuoZNj2VWRfqEKkSJJD1EIsJrzvRDK65kIry d6xXl8a4uxImrD+SE0HX3mkoPqBJ9fFklmDUZO5M2Jo1/NDckAofIu74FhcU8xmLfaJiBPHek oS+8au6aJZksWgjaVwz/aTMOOvJAnJFsFBYqIOMj4w== 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:253310 Archived-At: Eli Zaretskii writes: >> +(require 'button) >> +(require 'cl-lib) >> +(require 'help-mode) ;redundant? > > If this is added to an existing file, there should be a ^L and some > heading-style command before it. I had a look at the usage of ^L in info.el but I can't discern any rule or consistency. The number of lines between its page delimiters are over 900 and below 20. I assume you want me to use ^L to separate a different topic within info.el? >> + (while (re-search-forward Info-xref-symbol-regexp nil t) >> + (let* ((data (match-string 8)) >> + (sym (intern-soft data))) >> + (if sym >> + (cond >> + ((match-string 3) ; `variable' &c >> + (and (or (boundp sym) ; `variable' doesn't en= sure >> + ; it's actually bound >> + (get sym 'variable-documentation)) >> + (Info-xref-button 8 'Info-xref-variable = sym))) >> + ((match-string 4) ; `function' &c >> + (and (fboundp sym) ; similarly >> + (Info-xref-button 8 'Info-xref-function = sym))) >> + ((match-string 5) ; `face' >> + (and (facep sym) >> + (Info-xref-button 8 'Info-xref-face sym)= )) >> + ((match-string 6)) ; nothing for `symbol' >> + ((match-string 7) >> + (Info-xref-button 8 'Info-xref-function-def s= ym)) >> + ((cl-some (lambda (x) (funcall (nth 1 x) sym)) >> + describe-symbol-backends) >> + (Info-xref-button 8 'Info-xref-symbol sym))))= ))) > > Can this be rewritten so as to avoid the need for error-prone updates > of the sub-expression numbers every time Info-xref-symbol-regexp is > modified? What do you think about the following approach? (defcustom info-symbol-context '(( variable . "variable\\|option") ;; defining symbol as variable ( function . "function\\|command\\|call") ;; defining symbol as function ( face . "face") ;; defining symbol as face ( ignore . "symbol\\|program\\|property") ;; ignore symbols following this context type ( definition . "source \\(?:code \\)?\\(?:of\\|for\\)")) ;; function definitions in files "Help." :type 'list :version "30.1" :group 'info) ;; Assembling the complete regexp (defvar info-symbol-regexp (concat ;; context "\\(" ; ---- context start "\\<\\(" ; contex definition (string-remove-suffix "\\|" (mapconcat (lambda (x) (concat "\\(" (cdr x) "\\)\\|")) info-symbol-context "")) "\\)" ; --- definition end "[ \t\n]+" ; --- separators to quoted symbols "\\)?" ;; ---- end of context ;; quoted symbol "['`=E2=80=98]" ; start quotes ;; Note: symbol starting with word-syntax character: "\\(\\sw\\(\\sw\\|\\s_\\)+\\|`\\)" ; symbol "['=E2=80=99]" ; end quotes ) "Help.") ;; helper function (defun info-check-type( type) "Check if TYPE corresponds to the current search result. `match-string'." (let ((ictr info-symbol-regexp) (n 3) ;embedded within 2 groups ) (while (not (eq type (caar ictr))) (setq n (1+ n)) (setq ictr (cdr ictr))) (match-string n) )) ;;Here comes the function creating links ;;.... (while (re-search-forward info-symbol-regexp nil t) (let* ((data (match-string 8)) (sym (intern-soft data))) (if sym (cond ((info-check-type 'variable) (and (or (boundp sym) (get sym 'variable-documentation)) (info-button 8 'info-variable sym))) ((info-check-type 'function) (and (fboundp sym) (info-button 8 'info-function sym))) ((info-check-type 'face) (and (facep sym) (info-button 8 'info-face sym))) ((info-check-type 'ignore)) ((info-check-type 'definition) (info-button 8 'info-function-def sym)) ;;=20 ((cl-some (lambda (x) (funcall (nth 1 x) sym)) describe-symbol-backends) (info-button 8 'info-symbol sym))))))) --=20 Best wishes H. Dieter Wilhelm Zwingenberg, Germany