diff options
| author | Juri Linkov | 2013-03-21 01:04:40 +0200 |
|---|---|---|
| committer | Juri Linkov | 2013-03-21 01:04:40 +0200 |
| commit | afff09d015b0e17c059e68fe4a8f1d31014a3700 (patch) | |
| tree | 3076a99c3f964070171488288237692a7f37540e | |
| parent | 9a1ff1644d34aba9de29c0afa9cdf6f798226efc (diff) | |
| download | emacs-afff09d015b0e17c059e68fe4a8f1d31014a3700.tar.gz emacs-afff09d015b0e17c059e68fe4a8f1d31014a3700.zip | |
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.
Fixes: debbugs:13989
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/info.el | 77 |
2 files changed, 78 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 908d10494ff..f0427753551 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-03-20 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * info.el (Info-next-reference-or-link) | ||
| 4 | (Info-prev-reference-or-link): New functions. | ||
| 5 | (Info-next-reference, Info-prev-reference): Use them. | ||
| 6 | (Info-try-follow-nearest-node): Handle footnote navigation. | ||
| 7 | (Info-fontify-node): Fontify footnotes. (Bug#13989) | ||
| 8 | |||
| 1 | 2013-03-20 Stefan Monnier <monnier@iro.umontreal.ca> | 9 | 2013-03-20 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 10 | ||
| 3 | * subr.el (posn-point, posn-string): Fix it here instead (bug#13979). | 11 | * subr.el (posn-point, posn-string): Fix it here instead (bug#13979). |
diff --git a/lisp/info.el b/lisp/info.el index 3792857d47a..3586a124c14 100644 --- a/lisp/info.el +++ b/lisp/info.el | |||
| @@ -3057,6 +3057,38 @@ See `Info-scroll-down'." | |||
| 3057 | (select-window (posn-window (event-start e)))) | 3057 | (select-window (posn-window (event-start e)))) |
| 3058 | (Info-scroll-down))) | 3058 | (Info-scroll-down))) |
| 3059 | 3059 | ||
| 3060 | (defun Info-next-reference-or-link (pat prop) | ||
| 3061 | "Move point to the next pattern-based cross-reference or property-based link. | ||
| 3062 | The next cross-reference is searched using the regexp PAT, and the next link | ||
| 3063 | is searched using the text property PROP. Move point to the closest found position | ||
| 3064 | of either a cross-reference found by `re-search-forward' or a link found by | ||
| 3065 | `next-single-char-property-change'. Return the new position of point, or nil." | ||
| 3066 | (let ((pcref (save-excursion (re-search-forward pat nil t))) | ||
| 3067 | (plink (next-single-char-property-change (point) prop))) | ||
| 3068 | (when (and (< plink (point-max)) (not (get-char-property plink prop))) | ||
| 3069 | (setq plink (next-single-char-property-change plink prop))) | ||
| 3070 | (if (< plink (point-max)) | ||
| 3071 | (if (and pcref (<= pcref plink)) | ||
| 3072 | (goto-char (or (match-beginning 1) (match-beginning 0))) | ||
| 3073 | (goto-char plink)) | ||
| 3074 | (if pcref (goto-char (or (match-beginning 1) (match-beginning 0))))))) | ||
| 3075 | |||
| 3076 | (defun Info-prev-reference-or-link (pat prop) | ||
| 3077 | "Move point to the previous pattern-based cross-reference or property-based link. | ||
| 3078 | The previous cross-reference is searched using the regexp PAT, and the previous link | ||
| 3079 | is searched using the text property PROP. Move point to the closest found position | ||
| 3080 | of either a cross-reference found by `re-search-backward' or a link found by | ||
| 3081 | `previous-single-char-property-change'. Return the new position of point, or nil." | ||
| 3082 | (let ((pcref (save-excursion (re-search-backward pat nil t))) | ||
| 3083 | (plink (previous-single-char-property-change (point) prop))) | ||
| 3084 | (when (and (> plink (point-min)) (not (get-char-property plink prop))) | ||
| 3085 | (setq plink (previous-single-char-property-change plink prop))) | ||
| 3086 | (if (> plink (point-min)) | ||
| 3087 | (if (and pcref (>= pcref plink)) | ||
| 3088 | (goto-char (or (match-beginning 1) (match-beginning 0))) | ||
| 3089 | (goto-char plink)) | ||
| 3090 | (if pcref (goto-char (or (match-beginning 1) (match-beginning 0))))))) | ||
| 3091 | |||
| 3060 | (defun Info-next-reference (&optional recur count) | 3092 | (defun Info-next-reference (&optional recur count) |
| 3061 | "Move cursor to the next cross-reference or menu item in the node. | 3093 | "Move cursor to the next cross-reference or menu item in the node. |
| 3062 | If COUNT is non-nil (interactively with a prefix arg), jump over | 3094 | If COUNT is non-nil (interactively with a prefix arg), jump over |
| @@ -3071,14 +3103,13 @@ COUNT cross-references." | |||
| 3071 | (old-pt (point)) | 3103 | (old-pt (point)) |
| 3072 | (case-fold-search t)) | 3104 | (case-fold-search t)) |
| 3073 | (or (eobp) (forward-char 1)) | 3105 | (or (eobp) (forward-char 1)) |
| 3074 | (or (re-search-forward pat nil t) | 3106 | (or (Info-next-reference-or-link pat 'link) |
| 3075 | (progn | 3107 | (progn |
| 3076 | (goto-char (point-min)) | 3108 | (goto-char (point-min)) |
| 3077 | (or (re-search-forward pat nil t) | 3109 | (or (Info-next-reference-or-link pat 'link) |
| 3078 | (progn | 3110 | (progn |
| 3079 | (goto-char old-pt) | 3111 | (goto-char old-pt) |
| 3080 | (user-error "No cross references in this node"))))) | 3112 | (user-error "No cross references in this node"))))) |
| 3081 | (goto-char (or (match-beginning 1) (match-beginning 0))) | ||
| 3082 | (if (looking-at "\\* Menu:") | 3113 | (if (looking-at "\\* Menu:") |
| 3083 | (if recur | 3114 | (if recur |
| 3084 | (user-error "No cross references in this node") | 3115 | (user-error "No cross references in this node") |
| @@ -3099,14 +3130,13 @@ COUNT cross-references." | |||
| 3099 | (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://") | 3130 | (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://") |
| 3100 | (old-pt (point)) | 3131 | (old-pt (point)) |
| 3101 | (case-fold-search t)) | 3132 | (case-fold-search t)) |
| 3102 | (or (re-search-backward pat nil t) | 3133 | (or (Info-prev-reference-or-link pat 'link) |
| 3103 | (progn | 3134 | (progn |
| 3104 | (goto-char (point-max)) | 3135 | (goto-char (point-max)) |
| 3105 | (or (re-search-backward pat nil t) | 3136 | (or (Info-prev-reference-or-link pat 'link) |
| 3106 | (progn | 3137 | (progn |
| 3107 | (goto-char old-pt) | 3138 | (goto-char old-pt) |
| 3108 | (user-error "No cross references in this node"))))) | 3139 | (user-error "No cross references in this node"))))) |
| 3109 | (goto-char (or (match-beginning 1) (match-beginning 0))) | ||
| 3110 | (if (looking-at "\\* Menu:") | 3140 | (if (looking-at "\\* Menu:") |
| 3111 | (if recur | 3141 | (if recur |
| 3112 | (user-error "No cross references in this node") | 3142 | (user-error "No cross references in this node") |
| @@ -3840,7 +3870,25 @@ If FORK is non-nil, it is passed to `Info-goto-node'." | |||
| 3840 | ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)")) | 3870 | ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)")) |
| 3841 | (Info-goto-node "Top" fork)) | 3871 | (Info-goto-node "Top" fork)) |
| 3842 | ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)")) | 3872 | ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)")) |
| 3843 | (Info-goto-node node fork))) | 3873 | (Info-goto-node node fork)) |
| 3874 | ;; footnote | ||
| 3875 | ((setq node (Info-get-token (point) "(" "\\(([0-9]+)\\)")) | ||
| 3876 | (let ((old-point (point)) new-point) | ||
| 3877 | (save-excursion | ||
| 3878 | (goto-char (point-min)) | ||
| 3879 | (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t) | ||
| 3880 | (setq new-point (if (< old-point (point)) | ||
| 3881 | ;; Go to footnote reference | ||
| 3882 | (and (search-forward node nil t) | ||
| 3883 | ;; Put point at beginning of link | ||
| 3884 | (match-beginning 0)) | ||
| 3885 | ;; Go to footnote definition | ||
| 3886 | (search-backward node nil t))))) | ||
| 3887 | (if new-point | ||
| 3888 | (progn | ||
| 3889 | (goto-char new-point) | ||
| 3890 | (setq node t)) | ||
| 3891 | (setq node nil))))) | ||
| 3844 | node)) | 3892 | node)) |
| 3845 | 3893 | ||
| 3846 | (defun Info-mouse-follow-link (click) | 3894 | (defun Info-mouse-follow-link (click) |
| @@ -4896,6 +4944,21 @@ first line or header line, and for breadcrumb links.") | |||
| 4896 | mouse-face highlight | 4944 | mouse-face highlight |
| 4897 | help-echo "mouse-2: go to this URL")))) | 4945 | help-echo "mouse-2: go to this URL")))) |
| 4898 | 4946 | ||
| 4947 | ;; Fontify footnotes | ||
| 4948 | (goto-char (point-min)) | ||
| 4949 | (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t)) | ||
| 4950 | (let ((limit (point))) | ||
| 4951 | (goto-char (point-min)) | ||
| 4952 | (while (re-search-forward "\\(([0-9]+)\\)" nil t) | ||
| 4953 | (add-text-properties (match-beginning 0) (match-end 0) | ||
| 4954 | `(font-lock-face info-xref | ||
| 4955 | link t | ||
| 4956 | mouse-face highlight | ||
| 4957 | help-echo | ||
| 4958 | ,(if (< (point) limit) | ||
| 4959 | "mouse-2: go to footnote definition" | ||
| 4960 | "mouse-2: go to footnote reference")))))) | ||
| 4961 | |||
| 4899 | ;; Hide empty lines at the end of the node. | 4962 | ;; Hide empty lines at the end of the node. |
| 4900 | (goto-char (point-max)) | 4963 | (goto-char (point-max)) |
| 4901 | (skip-chars-backward "\n") | 4964 | (skip-chars-backward "\n") |