emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r112103: Info footnote fontification


From: Juri Linkov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112103: Info footnote fontification and navigation.
Date: Thu, 21 Mar 2013 01:04:40 +0200
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 112103
fixes bug: http://debbugs.gnu.org/13989
committer: Juri Linkov <address@hidden>
branch nick: trunk
timestamp: Thu 2013-03-21 01:04:40 +0200
message:
  Info footnote fontification and navigation.
  
  * lisp/info.el (Info-next-reference-or-link)
  (Info-prev-reference-or-link): New functions.
  (Info-next-reference, Info-prev-reference): Use them.
  (Info-try-follow-nearest-node): Handle footnote navigation.
  (Info-fontify-node): Fontify footnotes.
modified:
  lisp/ChangeLog
  lisp/info.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-03-20 18:13:00 +0000
+++ b/lisp/ChangeLog    2013-03-20 23:04:40 +0000
@@ -1,3 +1,11 @@
+2013-03-20  Juri Linkov  <address@hidden>
+
+       * info.el (Info-next-reference-or-link)
+       (Info-prev-reference-or-link): New functions.
+       (Info-next-reference, Info-prev-reference): Use them.
+       (Info-try-follow-nearest-node): Handle footnote navigation.
+       (Info-fontify-node): Fontify footnotes.  (Bug#13989)
+
 2013-03-20  Stefan Monnier  <address@hidden>
 
        * subr.el (posn-point, posn-string): Fix it here instead (bug#13979).

=== modified file 'lisp/info.el'
--- a/lisp/info.el      2013-02-21 06:55:19 +0000
+++ b/lisp/info.el      2013-03-20 23:04:40 +0000
@@ -3057,6 +3057,38 @@
        (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 +3103,13 @@
            (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 +3130,13 @@
       (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 +3870,25 @@
      ((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 +4944,21 @@
                                  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")


reply via email to

[Prev in Thread] Current Thread [Next in Thread]