From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#13989: Make Info support footnotes Date: Wed, 20 Mar 2013 00:30:21 +0200 Organization: JURTA Message-ID: <87obefdnuq.fsf@mail.jurta.org> References: <20130318182438.9ed088809ca67b7e4326335c@gmail.com> <87k3p4fig2.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1363732836 5615 80.91.229.3 (19 Mar 2013 22:40:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Mar 2013 22:40:36 +0000 (UTC) Cc: 13989@debbugs.gnu.org To: Xue Fuqiao Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Mar 19 23:41:01 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UI5DG-0005gB-DI for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Mar 2013 23:40:58 +0100 Original-Received: from localhost ([::1]:59469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UI5Ct-0003Qv-7Y for geb-bug-gnu-emacs@m.gmane.org; Tue, 19 Mar 2013 18:40:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:44153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UI5Cm-0003Qf-1f for bug-gnu-emacs@gnu.org; Tue, 19 Mar 2013 18:40:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UI5Cg-0002fx-3S for bug-gnu-emacs@gnu.org; Tue, 19 Mar 2013 18:40:27 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60438) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UI5Cf-0002fh-Mp for bug-gnu-emacs@gnu.org; Tue, 19 Mar 2013 18:40:21 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UI5EI-0002oH-NI for bug-gnu-emacs@gnu.org; Tue, 19 Mar 2013 18:42:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Mar 2013 22:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13989 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13989-submit@debbugs.gnu.org id=B13989.136373288410758 (code B ref 13989); Tue, 19 Mar 2013 22:42:02 +0000 Original-Received: (at 13989) by debbugs.gnu.org; 19 Mar 2013 22:41:24 +0000 Original-Received: from localhost ([127.0.0.1]:36314 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UI5Df-0002nQ-DZ for submit@debbugs.gnu.org; Tue, 19 Mar 2013 18:41:24 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:52461 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UI5Da-0002nG-7r for 13989@debbugs.gnu.org; Tue, 19 Mar 2013 18:41:20 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id A63AC258B92960; Tue, 19 Mar 2013 15:39:34 -0700 (PDT) In-Reply-To: <87k3p4fig2.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 19 Mar 2013 00:35:57 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:72723 Archived-At: > And it's pretty straightforward to implement: But footnotes are still not navigable. Typing `TAB' should navigate to the next/previous footnote as it does for the cross-node references and URLs. Since adding a footnote regexp to `Info-next-reference' will create false positives such as e.g. `TAB' will find plain text "(1)" and "(2)" in the node (info "(emacs) Copying"), a better approach would be to support text-property links like used in the *Help* buffers where links have a special text property that `TAB' (`forward-button') searches for to navigate to the next link. These two approaches can co-exist in Info, so `TAB' will move point to the closest position found either by `re-search-forward' or `next-single-char-property-change'. Later these text properties could be added to links in virtual nodes because this approach is more efficient and reliable. === modified file 'lisp/info.el' --- lisp/info.el 2013-02-21 06:55:19 +0000 +++ lisp/info.el 2013-03-19 22:28:00 +0000 @@ -3057,6 +3078,38 @@ (defun Info-mouse-scroll-down (e) (select-window (posn-window (event-start e)))) (Info-scroll-down))) +(defun Info-next-reference-or-link (pat prop) + "Move point to the next pattern-based cross-reference or property-based link. +The next cross-reference is searched using the regexp PAT, and the next link +is searched using the text property PROP. Move point to the closest found position +of either a cross-reference found by `re-search-forward' or a link found by +`next-single-char-property-change'. Return the new position of point, or nil." + (let ((pcref (save-excursion (re-search-forward pat nil t))) + (plink (next-single-char-property-change (point) prop))) + (when (and (< plink (point-max)) (not (get-char-property plink prop))) + (setq plink (next-single-char-property-change plink prop))) + (if (< plink (point-max)) + (if (and pcref (<= pcref plink)) + (goto-char (or (match-beginning 1) (match-beginning 0))) + (goto-char plink)) + (if pcref (goto-char (or (match-beginning 1) (match-beginning 0))))))) + +(defun Info-prev-reference-or-link (pat prop) + "Move point to the previous pattern-based cross-reference or property-based link. +The previous cross-reference is searched using the regexp PAT, and the previous link +is searched using the text property PROP. Move point to the closest found position +of either a cross-reference found by `re-search-backward' or a link found by +`previous-single-char-property-change'. Return the new position of point, or nil." + (let ((pcref (save-excursion (re-search-backward pat nil t))) + (plink (previous-single-char-property-change (point) prop))) + (when (and (> plink (point-min)) (not (get-char-property plink prop))) + (setq plink (previous-single-char-property-change plink prop))) + (if (> plink (point-min)) + (if (and pcref (>= pcref plink)) + (goto-char (or (match-beginning 1) (match-beginning 0))) + (goto-char plink)) + (if pcref (goto-char (or (match-beginning 1) (match-beginning 0))))))) + (defun Info-next-reference (&optional recur count) "Move cursor to the next cross-reference or menu item in the node. If COUNT is non-nil (interactively with a prefix arg), jump over @@ -3071,14 +3124,13 @@ (defun Info-next-reference (&optional re (old-pt (point)) (case-fold-search t)) (or (eobp) (forward-char 1)) - (or (re-search-forward pat nil t) + (or (Info-next-reference-or-link pat 'link) (progn (goto-char (point-min)) - (or (re-search-forward pat nil t) + (or (Info-next-reference-or-link pat 'link) (progn (goto-char old-pt) (user-error "No cross references in this node"))))) - (goto-char (or (match-beginning 1) (match-beginning 0))) (if (looking-at "\\* Menu:") (if recur (user-error "No cross references in this node") @@ -3099,14 +3151,13 @@ (defun Info-prev-reference (&optional re (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://") (old-pt (point)) (case-fold-search t)) - (or (re-search-backward pat nil t) + (or (Info-prev-reference-or-link pat 'link) (progn (goto-char (point-max)) - (or (re-search-backward pat nil t) + (or (Info-prev-reference-or-link pat 'link) (progn (goto-char old-pt) (user-error "No cross references in this node"))))) - (goto-char (or (match-beginning 1) (match-beginning 0))) (if (looking-at "\\* Menu:") (if recur (user-error "No cross references in this node") @@ -3840,7 +3892,25 @@ (defun Info-try-follow-nearest-node (&op ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)")) (Info-goto-node "Top" fork)) ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)")) - (Info-goto-node node fork))) + (Info-goto-node node fork)) + ;; footnote + ((setq node (Info-get-token (point) "(" "\\(([0-9]+)\\)")) + (let ((old-point (point)) new-point) + (save-excursion + (goto-char (point-min)) + (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t) + (setq new-point (if (< old-point (point)) + ;; Go to footnote reference + (and (search-forward node nil t) + ;; Put point at beginning of link + (match-beginning 0)) + ;; Go to footnote definition + (search-backward node nil t))))) + (if new-point + (progn + (goto-char new-point) + (setq node t)) + (setq node nil))))) node)) (defun Info-mouse-follow-link (click) @@ -4896,6 +4966,21 @@ (defun Info-fontify-node () mouse-face highlight help-echo "mouse-2: go to this URL")))) + ;; Fontify footnotes + (goto-char (point-min)) + (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t)) + (let ((limit (point))) + (goto-char (point-min)) + (while (re-search-forward "\\(([0-9]+)\\)" nil t) + (add-text-properties (match-beginning 0) (match-end 0) + `(font-lock-face info-xref + link t + mouse-face highlight + help-echo + ,(if (< (point) limit) + "mouse-2: go to footnote definition" + "mouse-2: go to footnote reference")))))) + ;; Hide empty lines at the end of the node. (goto-char (point-max)) (skip-chars-backward "\n")